- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have loaded the PWM PRS example and added an LCD to display the CompareValue as a percentage as well as show the CompareValue as a bar graph. The 0 bargraph appears to be all partially on without the hexbyte displayed.
Archive attached
Any suggestions?
Chris
- Labels:
-
PSoC 1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In your while loop, you just update the PWM and not writing anything to the LCD.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I get the same result if the LCD script is put inside the loop
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
OK, the solution is to put the LCD code between the loops. Although I would have thought that the LCD would have been updated inside the loop after the input register was read.
Is there a command to write decimal numbers to the LCD?
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If you don't put it inside the loop it would never shown.
Here is my approach for this project. Do one thing a time
1. Print a message such as hello world to the LCD
2. Use a delay loop to print a message with a counter which increase every 1 second..
3. Add the counter to count the number of keypress and shown on the LCD
4. Add another button so can do up and down counts and shown on the LCD
5. Change the step size of every increment or decement and print it on the LCD
6. Add printing of the bar
7. Add setting of the PWM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You should try example project, there is one about writing a ADC value on the LCD and other one is about using the PWM.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Converting ints to decimal strings use atoi()
Decimals and float conversion best with sprintf().
C-manual I like most is here: publications.gbdirect.co.uk/c_book/, look under Libraries, formatted I/O
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
(&§%E$)! NOT atoi() but itoa()!
As a matter of fact it seems as if I cannot tell the right hand side from the left hand side, but mixing itoa and atoi is new for me!
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for your comments HL.
Bob, sounds like a plan. I'll give it a whirl!
Thanks mate
Chris D.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
More on the LCD. I still cannot display decimal numbers on the LCD. The only way is to print a hex byte with either two or four characters and this converts decimal numbers to hex bytes and displays the hex byte.
Secondly is there any way to speed up the LCD processing. With LCD outputs included in a while loop the updated data from PTR0DR takes forever to process even though CPU clock is set to sysclock/1 on a 24MHz system. If I take out the LCD code then the update from PRT0DR is blindingly fast. I am using the 3210 eval kit.
Chris D.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The LCD is a rather slow device with delay loops (needed!) in the range of some ms. So it will be difficult to speed that up.
I do not understand what you mean with "update PRT0DR", can you please post your complete project, so that we all can have a look at all of your settings? To do so, use
Designer->File->Archive Project
and attach the resulting file (do NOT use chrome, that still may not work).
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The charater LCD you are using is very slow, you cannot expect it as fast as you computer monitor. It is much much slower.
The reponse time of the LCD display (optical) is in the range of 100-300ms. So basically it is no use t undate it more than 10 times a second (unless you want to create grey scale this way).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Your LCD only needs to get initialized only once, same with the bargraph. Best would be to put all the hardware (and software) initialization stuff into a separate routine that is called from main() in the very beginning. Also, when needed, enable interrupts there.
Constructs in C-language as
Variable = Variable +1; is better written as Variable++;
and
Variable = Variable + n; written as Variable += n;
This will allow the compiler to generate denser code..
Under Help->Documentation->Compiler and Programming Documents->C Language Compiler User Guide You will find an explanation on how to use the itoa() macro which will convert integers to ascii.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Som additional thoughts:
Working with a pseudo random number generator is usually done in the following order:
Start the hardware, write the polynom.
Seed the PRS.
Retrieve several numbers from generator where usually the number is smaller than the period of the PRS.
A PRS does not give you a random number, it delivers a random progession of numbers. When you are looking at getting something random you ought to google for "true random number" or ask Mrs. W. Pedia for it.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Moving the initilisation outside the loop has given a great improvement in response time.
No one has a solution to the problem of writing a decimal number to the LCD. Conversions from hex to decimal and viceverca are straight forward BUT there is NO command (on the LCD that comes with the 3210 eval kit) to print a DECIMAL to the LCD, only commands to print HEX BYTES to the LCD.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Bob, are you suggesting converting the decimals to ascii and then use LCD_PRSTRING ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
you should be able to seach the Net how to use itoa(). google is your friend.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
"are you suggesting converting the decimals to ascii and then use LCD_PRSTRING ?"
Yes, exactly.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
One other thing I found in using LCD was repeated writes of the same data
in a loop produced fast flashing artifacts on the LCD due to the onboard
controller receiving asynch writes. So I create a display buffer, and every time I
went to write I looked at the buffer, if it already had the data I wanted to write,
I executed no operations. If buffer was not same then I wrote data and updated
buffer. That removed all "funky" display artifacts.
Regards, Dana.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
OK. itoa seems to work. ---BUT--- the LCD displays oddly. for instance I have the code converting the bargraph bar number (CompareValue) as a percentage of the total bits (255 for the PRS8). Now I preload CompareValue with 127(50%) and the display is correct (50). If I then run the bar graph to255 (100%) it displays correctly. If I now decrease the bargraph back to 127 (50%) the display reads 500. If I further decrease the value to an equivalent 5% the LCD displays 500. It seems to maintain the max character length regardless of actual number of characters generated.
???
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Did you erase the or fill the row/rows with space before drawing the new bargraph?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If the old value on the LCD is 100, and you write 5 as the first character, it would display 500 as the two"00" is still in the LCD RAM. you can either
1. always write 3 digits ie 000, 001...099, 100
2. or filll the 3 charters with "space" first and then write the number
3. or write the number then write the reset of the digits (upto the 3rd one) with space.
4. There are ways to do leading zero blanking as well, but it would be a later exercise if you wish to do it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am using itoa to generate the ascii string which is printed on the second row of the by LCD_Prstring. I do not any control over the number of characters it generates.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I think I need to figure out how to right justify the ascii result to get it printed correctly. it appears to be left justified. That would explain why the value 5 (500) looks the same as the value 50(500).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Leading zero blanking should be what you need. How about upload your latest project so we can check for changes needed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
What you can do for now is to erase the row and reprint. That is the quickest way to get a fix. If you want to do it more cleverly. You can try to right justfy or with leading zero blanking.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
C-language is a machine-oriented language which results in the need for programming a lot of needed things yourself.
An easy solution is to assume that one unsigned char will not need more than 3 characters to get displayed.
So you may
LCD_Position(Line,Column);
LCD_PrCString(" "); // Three spaces
LCD_Position(Line,Column);
LCD_PrString(itoa(MyByte));
When you want to get the output right justified you'll have to check with strlen() what the size of the resulting itoa() conversion was and pad the result with spaces to the left.
Another choice is to use sprintf() which generates formatted I/O. Here is a C-reference, look under Libraries->Formatted I/O
publications.gbdirect.co.uk/c_book/
and this thread www.cypress.com/ for use with a PSoC1
Happy coding
Bob
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am stumped by the syntax of this function.
I have archived the project and attached it.
sprintf function is at line 215 and i have tried all manner of formats , all produce compile errors beginning with illegal expression.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Your project is missing.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@Dana ..
Secrets of “printf”
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dana,
I used that reference along with the reference from Bob as well as google. Odd thing is that there are a couple of differing protocols, some have the argument then the required format - some the other way around but neither seems towork.
What I don't understand is the 'Illegal expression" as the first error in the compiler?
Regards
Chris D.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
1. you did not give the size of your two arrays.
for example, if you want to size of string is 9 it should be
char pct[10],*ip;//the array has 9 charaterschar pnt[10],*s;
2. you don't need to include the springf prototype, just remove it from your file.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Don't know what is wrong, but no allowing me to add the 3 point
3. The 2nd argument the compiler is looking for a pointer to a const char, and your 2 and 3 arguements are wrong as well
So you can change it to sprinf(s,(CONST char*)"3d",BG);
the prototype is sprintf(char *, CONST char *, ...);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sorry typo, the inststruction should be
sprinf(s,(CONST char*)"%3d",BG);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
However, there are few issues with your program
1. your function does not have key debounce, the value may jump more than 1 for every key press.
2. you use
// Check if the Down key is pressed
{}
if (PRT0DR & 0x02 ) else
if (CompareValue> 0 )....
you can use
if(!(PRT0DR & 0x02))
{
if compareValue >0)....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
What is happening!!!!
Here again
2. you use
if (PTR0DR &02)
{}
else
...
you can use
if(!(PTR0DR& 02))
...
3. I will use unsgined char for the variable CompareValue, as it should always be +ve and
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I would use
csprintf(s,"%3d",BG);
Bob