cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 5, 3 & 1

ChDe_285186
New Contributor II

 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 

0 Likes
66 Replies
Anonymous
Not applicable

In your while loop, you just update the PWM and not writing anything to the LCD.

0 Likes
ChDe_285186
New Contributor II

 I get the same result if the LCD script is put inside the loop

   

Chris

0 Likes
ChDe_285186
New Contributor II

 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

0 Likes
Anonymous
Not applicable

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

0 Likes
Anonymous
Not applicable

You should try example project, there is one about writing a ADC value on the LCD and other one is about using the PWM.

0 Likes
Bob_Marlowe
Expert II

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

0 Likes
Bob_Marlowe
Expert II

(&§%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

0 Likes
ChDe_285186
New Contributor II

 Thanks for your comments HL.

   

Bob, sounds like a plan. I'll give it a whirl!

   

Thanks mate

   

Chris D.

0 Likes
ChDe_285186
New Contributor II

 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.

0 Likes
Bob_Marlowe
Expert II

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
 

0 Likes
Anonymous
Not applicable

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).

0 Likes
ChDe_285186
New Contributor II

 I suspect I will need to send the CompareValue data from inside the loop to a register and then have the LCD read the register every 500mS? with a routine outside the loop.

   

Chris

0 Likes
Bob_Marlowe
Expert II

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

0 Likes
Bob_Marlowe
Expert II

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

0 Likes
ChDe_285186
New Contributor II

 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.

0 Likes
ChDe_285186
New Contributor II

 Bob, are you suggesting converting the decimals to ascii and then use LCD_PRSTRING ?

0 Likes
Anonymous
Not applicable

you should be able to seach the Net how to use itoa(). google is your friend.

0 Likes
Bob_Marlowe
Expert II

"are you suggesting converting the decimals to ascii and then use LCD_PRSTRING ?"

   

Yes, exactly.

   

 

   

Bob

0 Likes
ETRO_SSN583
Esteemed Contributor

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.

0 Likes
ChDe_285186
New Contributor II

 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.

   

???

0 Likes
Anonymous
Not applicable

Did you erase the or fill the row/rows with space before drawing the new bargraph?

0 Likes
Anonymous
Not applicable

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.

0 Likes
ChDe_285186
New Contributor II

 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. 

0 Likes
ChDe_285186
New Contributor II

 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).

0 Likes
Anonymous
Not applicable

Leading zero blanking should be what you need. How about upload your latest project so we can check for changes needed.

0 Likes
Anonymous
Not applicable

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.

0 Likes
Bob_Marlowe
Expert II

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

0 Likes
ETRO_SSN583
Esteemed Contributor

If you use sprintf() the attached will help you with formatting strings.

   

 

   

Regards, Dana.

0 Likes
ChDe_285186
New Contributor II

 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.

   
    
     Compiling...    
    
     creating project.mk     
    
     !E F:\DOCUME~1\SOLARI~1\Cypress\PRS\PRS\PRS\main.c(215): illegal expression    
    
     !E F:\DOCUME~1\SOLARI~1\Cypress\PRS\PRS\PRS\main.c(215): `3d' is a preprocessing number but an invalid integer constant    
    
     !E F:\DOCUME~1\SOLARI~1\Cypress\PRS\PRS\PRS\main.c(215): syntax error; found `3' expecting `)'    
    
     !E F:\DOCUME~1\SOLARI~1\Cypress\PRS\PRS\PRS\main.c(215): syntax error; found `3' expecting `;'    
    
     !W F:\DOCUME~1\SOLARI~1\Cypress\PRS\PRS\PRS\main.c(215):[warning] expression with no effect elided    
    
     !E F:\DOCUME~1\SOLARI~1\Cypress\PRS\PRS\PRS\main.c(215): syntax error; found `)' expecting `;'    
    
     !E F:\DOCUME~1\SOLARI~1\Cypress\PRS\PRS\PRS\main.c(215): illegal statement termination    
    
     !E F:\DOCUME~1\SOLARI~1\Cypress\PRS\PRS\PRS\main.c(215): skipping `)'    
    
     make: *** [obj/main.o] Error 1    
    
     main.o - 8 error(s) 1 warning(s)  11:58:02    
    
          
    
     Regards    
    
     Chris D.    
    
          
   
   
        
0 Likes
Anonymous
Not applicable

 Your project is missing.

0 Likes
ChDe_285186
New Contributor II

HMMM !!   It would appear that I overlooked that small detail.

   

Try this

   

Regards

   

Chris D

0 Likes
Anonymous
Not applicable

@Dana ..

   

   

   

Secrets of “printf”

0 Likes
ChDe_285186
New Contributor II

 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.

0 Likes
Anonymous
Not applicable

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.

0 Likes
Anonymous
Not applicable

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 *, ...);

0 Likes
Anonymous
Not applicable

Sorry typo, the inststruction should be

   

sprinf(s,(CONST char*)"%3d",BG);

0 Likes
Anonymous
Not applicable

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)....

0 Likes
Anonymous
Not applicable

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

0 Likes
Bob_Marlowe
Expert II

I would use

   

csprintf(s,"%3d",BG);

   

 

   

Bob

0 Likes