hex to dec query

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

Hi,

   

Ive been looking at interfacing an lm35 to the PSOC 3, ive looked at the sample ADC single ended mode, Ive modified the output to convert the output from the adc to temperature as such: temp =(float)output*100/1023;

   

I am using the ADC in 10 bit mode, I want a float output.

   

Problem is, that the output is the temperature but still in hex, so the room temperature is currently 25c but it comes up as 19H which is correct but not ideal.

   

Ive looked at a few topics from here:

   

This one: http://www.cypress.com/forum/known-problems-and-solutions/problem-whit-psoc1-adcinc-and-lm35

   

and this one: www.cypress.com/forum/psoc-1-device-programming/decode-hex-dec

   

Ive tried implementing what Bob has suggested from the second topic, but the compiler doesnt like that there is no ANSI function prototype for this fuction: csprintf

   

Ive included the stdio.h library file too, anything (probably obvious) I am missing?

   

thanks

   

Kind regards

0 Likes
1 Solution
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Converting a hex to ASCII string is done with

   

sprintf(Buffer,FormatString,HexNumber). Probably the preceding "c" in the post you refer to was a simple typo.

   

 

   

Bob

View solution in original post

0 Likes
8 Replies
lock attach
Attachments are accessible only for community members.
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

Use printf to fix this issue. I am sending you the manual. Don't forget stdio.h to use it.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Converting a hex to ASCII string is done with

   

sprintf(Buffer,FormatString,HexNumber). Probably the preceding "c" in the post you refer to was a simple typo.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

Whoops... That's exactly what was wrong, the C was a typo indeed.

   

Thanks Bob,

   

Im sending it to a 16X2 LCD and the 9 for the Buffer is too many decimal places, Ive reduced the size of Buffer to 5 and its plenty,

   

However  I notcied that when written to the LCD there is like two pipe symbols occupying a segment at the end of the temperature readout. It shows this whether the length of buffer is 5 or 9. 

   

Im using  LCD_PrintString(Buffer); to dusplay the result called 'Buffer' on the LCD

   

Any ideas?

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

When you upload your workspace bundle I'll have a look at.To do so, use
Creator->File->Create Workspace Bundle (minimal)
and attach the resulting file.

   

 

   

Bob

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

Hi,

   

Ive uploaded the minimal bundle if you want to have a look.

   

Thanks

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Your LCD update frequency is quite too high. You get 10ksps and every time a sample is ready you print it. I would suggest you to insert a CyDelay(250) into your main-loop. Good wil be to clear the display (using spaces) before writing a new value.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

Hi Bob,

   

I inserted the delay, the transition on the LCD is much better.

   

Ive also added a LCDprint string("                         ");

   

after printing the temperature although i still see the double pipe after the temperature.

   

thank you

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Increase your Buffer[5] to [20]

   

 

   

Bob