Little math help
TC
Posts: 1,019
I am working on a little project that reads the voltage from a ADC0831 I have a working program, but I am looking to save RAM. I would like to use just one variable if i can
here is the math program that works
· FOR index = 1 TO 255
··· HIGH CS_main
··· LOW CS_main
··· LOW CLK
··· PULSOUT CLK, 210
··· SHIFTIN ADCData,CLK,MSBPOST,[noparse][[/noparse]adc\8]
··· ADC_AVG = ADC_AVG + adc
· NEXT
··· ADC_AVG = ADC_AVG / 255
··· v = 15 * ADC_AVG / 255
··· r·= 15 * ADC_AVG //255
··· v2 = 10 * r / 255
· SEROUT VFD, Baud, [noparse][[/noparse]$1F, $24, 0, 0, 0, 0,"Primary· = ", DEC2 v, ".", DEC1 v2,"V" ]
to give a little info on what I am doing. I am measuring a car battery. I am taking the average output from the ADC0831 then converting it to " 00.0 " format. then sending it to a VFD display. I am not a math wiz, but I know there are some amazing people that can fix what I am looking for.
Thanks
TC
Post Edited (TC) : 7/13/2006 2:07:57 AM GMT
here is the math program that works
· FOR index = 1 TO 255
··· HIGH CS_main
··· LOW CS_main
··· LOW CLK
··· PULSOUT CLK, 210
··· SHIFTIN ADCData,CLK,MSBPOST,[noparse][[/noparse]adc\8]
··· ADC_AVG = ADC_AVG + adc
· NEXT
··· ADC_AVG = ADC_AVG / 255
··· v = 15 * ADC_AVG / 255
··· r·= 15 * ADC_AVG //255
··· v2 = 10 * r / 255
· SEROUT VFD, Baud, [noparse][[/noparse]$1F, $24, 0, 0, 0, 0,"Primary· = ", DEC2 v, ".", DEC1 v2,"V" ]
to give a little info on what I am doing. I am measuring a car battery. I am taking the average output from the ADC0831 then converting it to " 00.0 " format. then sending it to a VFD display. I am not a math wiz, but I know there are some amazing people that can fix what I am looking for.
Thanks
TC
Post Edited (TC) : 7/13/2006 2:07:57 AM GMT
Comments
FOR index = 0 TO 255
' ... as above
NEXT
ADC_AVG = 150 ** ADC_AVG
Note use of the ** operator. This last operation converts ADC_AVG, the whole accumulation, directly to a number 0 to 150. Then display it like this...
SEROUT VFD, Baud, [noparse][[/noparse]$1F, $24, 0, 0, 0, 0,"Primary = ", DEC ADC_AVG/10, ".", DEC1 ADC_AVG,"V" ]
There is no need for the intermediate calculations and variables.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
TC
I tryed your Math Change and there is a 1 tenth of a volt difference from the one I have. The good part is i don't care. the only thing I would like to know is why in laymans terms.
TC
Never mind I did not change the index from 1 to 0. fixed it right up
TC
You killed two birds with one stone for me. I was trying to find a way to calibrate what the output is and now I can. lets say
ADC_AVG = 236 = 13.8 Volts (i think, not at home computer)
but with my Fluke Volt meter, i am getting 14.0 volts, all I have to do is add 2 to the 150
ADC_AVG = 152 ** ADC_AVG
and now the voltage reading is right. see what I an looking for is to read the voltage at a certan part (IE. Battery, Amplifier, ect.) and the ADC0831 can not be at the part, and I was getting voltage drops because of the wire runs. well now I can account for them in the car with out a computer.
READ VOLT_CAL, CAL
ADC_AVG = CAL ** ADC_AVG
I have A programing page that allows me to change things on the fly now I have one more
Thanks
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com