Dave
Always wear safety glasses while programming.
Thanks for the heads up Mack,
I guess I was a bit confused by this in your ADC scaling tutorial:
Why would that read 205, instead of 204?Code:Convert this to an 10 bit PIC® resolution. 10 bits ADC = 0 to 1023, 1024 steps. At 5.0 volts one volt of input will will read 205. (204.6 actually)
Thanks Mack, for helping a newbie trying to understand.
Chris
Thanks for catching that and I apologize for the confusion.
I changed the article to
Hope that clears things up a bit..10 bits ADC = 0 to 1023, 1024 steps.
At 5.0 volts one volt of input will will read 204. (204.8 actually)
But we will use 205 for accuracy.
204 * 5 = 1020
205 * 5 = 1025
Dave
Always wear safety glasses while programming.
Hey Mack,
I sketched this code in notepad after reading some other posts...
Does it look like I'm on the right track?
Thanks again for your assistance,Code:ADVal VAR WORD Quanta CON 489 'VREF/1024 = 5/1024 = .00488 = 489 VoltageDivider CON 70 ADCVolts VAR BYTE LCDVolts VAR WORD ADCIN 0,ADVal ADCVolts=(ADVal/1000)*Quanta LCDVolts=ADCVolts*VoltageDivider LCDout $fe, 1 LCDout $fe, 2, "CURRENT READINGS ARE" Lcdout $fe, $C0, "A/D VDC = ",DEC1 ADCVolts/100,".",DEC2 ADCVolts//100 Lcdout $fe, $94, "--------------------" Lcdout $fe, $D4, "ACTUAL VDC = ",DEC3 LCDVolts/100,".",DEC2 LCDVolts//100
Chris
Really close!!
But I think I would try it like this.
Code:ADVal VAR WORD Quanta CON 342 ' 350 / 1023 * 1000 LCDVolts VAR WORD Z VAR WORD 'DUMMY VAR Z1 VAR WORD 'DUMMY VAR ADCIN 0,ADVal Z = ADVal * 342 Z1 = DIV32 1000 LCDVolts = Z1
Dave
Always wear safety glasses while programming.
Need help ...with this math. Please !
I use voltage divider ; R1=1000 ohms; R2= 50 to 3500 ohms.
I read the voltage :
I try to calculate the resistor(s) R2, assuming that I do not know values.Code:ADCON0 = %10000001 Pauseus 50 ' Wait for channel to setup ADCON0.1 = 1 ' Start conversion While ADCON0.1=1:Wend ' Wait for conversion advalue.HighByte=ADRESH ' Read variable from ADC and save advalue.LowByte=ADRESL
Formula is (?) :
R2= 1000 * advalue/(1024-advalue)
I wrote this code :
I want to display on Nokia 3310 :Code:dummy =1000 * advalue resistor = div32 10 resistor = (resistor / (1024-advalue)) * 100
But I can not to display the last digit (from right) of values of resistors ...I have "50" instead "54" ; "140" instead "147" ; "1030" instead "1036" ...Code:'~~~~~~~~~~~~~~~~~ setting cursor for display the advalue LcdReg = %10000000 + 5 ' cursor X call PrintCtrlLcd LcdReg = %01000011 ' cursor Y call PrintCtrlLcd '~~~~~~~~~~~~~~~~~ now display results Char = (advalue dig 3) call PrintChar Char = (advalue dig 2) call PrintChar Char = (advalue dig 1) call PrintChar Char = (advalue dig 0) call PrintChar ............. Char = resistor dig 4 call PrintChar Char = resistor dig 3 call PrintChar Char = resistor dig 2 call PrintChar Char = resistor dig 1 call PrintChar
Please, point me to the right direction ! Thanks in advance !
Hi,
The result from the ADC ranges from 0 to 1023, not 1024. Try using 1023 in the formula and see if that makes it better.
With that said the whole thing is a bit convoluted....Why do you multiply by 1000 only to divide the result by 10 directly after?
What's the voltage at the top of the resistor divider and what's VRef?
If both are 5V then the highest voltage on the ADC input would be 5/(1000+3500)*3500=3.888V giving an ADC reading of 3.888/(5/1024)=796.
If you multiply 796 by 100 (multiply by 1000, divide by 10) the result will still overflow a WORD.
/Henrik.
Bookmarks