Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

HELP~~ Converting Digital value to Analog value

Status
Not open for further replies.

vailant

Newbie level 5
Joined
Jan 6, 2010
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Singapore
Activity points
1,368
Hi all..
currently im using C8051F226 using silab in C language.. and my display is using a display module uOLED-96-G1..

i've set up the ADC and it work fine.. and now when i input a voltage of 0 to 3v, i'll get the int ADCvalue as 0 to 255... and im able to display the number on the uOLED. ADCvalue = ADC0H..

What i want to do now is to convert the ADC value back to the analog value...e.g.
if my int ADCvalue is 255.. i want to get 3.0
if my int ADCvalue is 127 or 128.. i want to get 1.5
if my int ADVvalue is 0.. i want to get 0.0... etc..
i've already printed the decimal point('.') on my display.. so now i need to get 2 seperate interger
when my ADCvalue is 255... i want '3' & '0'
when my ADCvalue is 127 or 128... i want '1' & '5' etc...


the problem is that my display wont be able to do printf function.. meaning i cant use the %f, %d, etc...


can any1 please help me with some calculation coding?? does it got to do with the bits resolution?
 

Hi,
Try something like:
Variable = (ADCvalue * 30) >> 8
d1 = Variable div 10
d2 = Variable mod 10
Then d1 stores the tens value as integer, d2 stores units value as integer.
Now just print d1 and d2.
Hope it helped.
Tahmid.
 

Variable = (ADCvalue * 30) >> 8
erm.. lets say the ADCvalue is 255.. so 255*30=7650.. wat does the ">>8" means?
 

Hi vailant,
">>8" means bitshift right eight times, in other words, divide by 255.
So 255*30=7650
7650>>8 = 30
30/10 = 3
30%10 = 0
So, d1 = 3, d2 = 0
Print this on LCD, with the "." printed between d1 and d2.
Another example, if result = 128,
128*30=3840
3840>>8=15
15/10= 1
15%10 = 5
so, d1 = 1, d2 = 5
Print this with "." in between, so 1.5
Hope it helped.
Tahmid.
 

Hi Tahmid,
Yes! it works! thank you so much.. i only hope that i could check your reply earlier. because i actually try to figure it out myself and i came out with a longer n stupid coding..

opvalue_d1 = (opvalue_d1 / 255) * 3;
d1 = opvalue_h1+'0';
opvalue_d2 = (opvalue_d2 * 100 / 255) *3;
d2 = opvalue_d2 / 10;
d2 = d2 % 10 + '0';

haha.. stupid me..
Thank you so much Tahmid. =)

Added after 18 minutes:

anyway.. can anyone tell me in simple terms wat is bits resolution?? and how its link to this conversion??
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top