Prefekt 0 Posted February 22, 2003 Report Share Posted February 22, 2003 Hello, I programming a LCD Interface an a ADC Input. Now I would display the voltage from ADC to my LCD Display!. But I have two values, one in the low byte another in the high byte. How I can convert the binary value to a decimal value? Also I think, I must compute: U = Uinput * 5 / 1,024, because the pic can messure 5V with 10Bit (1024), so the PIC can messure 2,8828 mV Steps 5V/1024, right? Has anybody implimented a voltage messure and display on a LCD? Thanks Volker Quote Link to post Share on other sites

Guest Luca Posted March 3, 2003 Report Share Posted March 3, 2003 You must use this conversion formula : (High_value*255+Low_value)*5/1024 Quote Link to post Share on other sites

Steve_DeGroof 0 Posted March 6, 2003 Report Share Posted March 6, 2003 U = Uinput * 5 / 1,024 You could multiply by 44, then divide by 9 to get a value that's roughly 0-5000 mV. Quote Link to post Share on other sites

16F876 0 Posted April 4, 2005 Report Share Posted April 4, 2005 U = Uinput * 5 / 1,024 You could multiply by 44, then divide by 9 to get a value that's roughly 0-5000 mV. <{POST_SNAPBACK}> My solution is so complicated that I would have gone with Steve's solution, but here goes: I get the ADC value in int multi. I multiply the value by 4.882 ( comes from 5000/1024, therefor 1023(+1) will be 5000) as follows: void Voltage (void) { multi=multi+1; // add one temp=multi*4; temp0=(multi*8)/10; temp1=(multi*8)/100; temp2=(multi*2)/1000; multi=temp+temp0+temp1+temp2; } Then I do the BCD extraction: void bcdext (void) { thou=multi/1000; multi=multi%1000; hund =(multi/100); multi=multi%100; tens=(multi/10); ones=(multi%10); thou=thou+48; //the 48 gets added to get the LCD value hund=hund+48; tens=tens+48; ones=ones+48; } Then I do rounding of the value so a ADC value of 1023 will show 5000 while a value of zero will still show 0. void roundd (void) {if (ones>(4+48)) //ie ones +48(to get LCD value)>4 {tens=tens+1; /*if the LCD value for 9 increases by one it becomes the value for character ':' */ if (tens>(9+48)) {tens=(0+48); hund=hund+1; if (hund>(9+48)) {hund=(0+48); thou=thou+1;}}}} This gives an adc value of 1023 a value of 5000. Quote Link to post Share on other sites

Dave 0 Posted April 5, 2005 Report Share Posted April 5, 2005 Guys, Try my adaption of the Bresenham Line algorithm - I kept thinking that we have x and y, and a slope so came up with this (I just found up the Bresengam line alogrithm and adapted it ). Its pretty accurate, 511 gives 2499. The down side is that it takes alot of iterrations to find the value. Just pass the adc value (0 to 1023) and the converted value is returned. int BresenhamLine( int adcval ) { if( adcval == 0 ) return 0; int xnum = 2500; int y, x = 0; for (y = 0; y < 5000; y++) { xnum += 1023; if (xnum >= 5000) { xnum -= 5000; if( x == adcval ) break; x++; } } return y; } Let me know what you think. Regards Dave Quote Link to post Share on other sites

## Recommended Posts

## Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.

Note:Your post will require moderator approval before it will be visible.