Sep 19, 2010 #1 H hhhsssmmm Member level 1 Joined May 14, 2009 Messages 37 Helped 0 Reputation 0 Reaction score 0 Trophy points 1,286 Activity points 1,732 hello guys i just want to know the math equations that will be needed to go into my C18 code to display the battery voltage from 0-12V on LCD. Of course the battery voltage is scaled from 0-5 volts and im using a 10bit adc on PIC18F2420 with VDD as the ref. MY head has worked out following to put in my C code for the necessary scaling factor conversion. 1 / [(R1+R2)/R2] .... lets say this inverse results of value X ADC voltage at PIC pin (0- 5V) = X * ADRES .... lets say this product results of value Y. Now Y is the actual voltage from 0 to 5V on the ADC pin. This of course represents the scaled 0 - 12V via the potential divider. Now what is the next step after this to get the value of Y to represent the value from 0 - 12V for the battery voltage so i can display on LCD?? what must i multiply or divide to get my desired result?.... im lost...plz help Thanks Haseeb
hello guys i just want to know the math equations that will be needed to go into my C18 code to display the battery voltage from 0-12V on LCD. Of course the battery voltage is scaled from 0-5 volts and im using a 10bit adc on PIC18F2420 with VDD as the ref. MY head has worked out following to put in my C code for the necessary scaling factor conversion. 1 / [(R1+R2)/R2] .... lets say this inverse results of value X ADC voltage at PIC pin (0- 5V) = X * ADRES .... lets say this product results of value Y. Now Y is the actual voltage from 0 to 5V on the ADC pin. This of course represents the scaled 0 - 12V via the potential divider. Now what is the next step after this to get the value of Y to represent the value from 0 - 12V for the battery voltage so i can display on LCD?? what must i multiply or divide to get my desired result?.... im lost...plz help Thanks Haseeb
Sep 20, 2010 #2 M millwood Advanced Member level 3 Joined Jul 2, 2009 Messages 733 Helped 80 Reputation 164 Reaction score 35 Trophy points 1,308 Activity points 5,088 you should scale the input voltage so that it can be adc'd by the mcu between 0 - 0x3ff, corresponding to 0v and 12v. so, you can map any reading of ADRESH:ADRESL to a voltage between 0 and 12v. all it is required now have been taught at elementary school.
you should scale the input voltage so that it can be adc'd by the mcu between 0 - 0x3ff, corresponding to 0v and 12v. so, you can map any reading of ADRESH:ADRESL to a voltage between 0 and 12v. all it is required now have been taught at elementary school.
Sep 20, 2010 #3 hugo Full Member level 6 Joined Dec 31, 1999 Messages 322 Helped 49 Reputation 98 Reaction score 23 Trophy points 1,298 Location canada Activity points 2,148 Hi, Let's say : R1+R2 = 10k ; Vo=Vin/3; R1=6.7k; R2=3.3k; you can now measure voltages up to 15V and you have to multiply your result with 3 ... ex. mikroc c language : Vin = Adc_Read(0); // Read from channel 0 (AN0) mV = (Vin * 5000) >> 10; // mv = Vin x 5000 / 1024 mV = 3*mV // multiply with k=3
Hi, Let's say : R1+R2 = 10k ; Vo=Vin/3; R1=6.7k; R2=3.3k; you can now measure voltages up to 15V and you have to multiply your result with 3 ... ex. mikroc c language : Vin = Adc_Read(0); // Read from channel 0 (AN0) mV = (Vin * 5000) >> 10; // mv = Vin x 5000 / 1024 mV = 3*mV // multiply with k=3