Scaling?
Mike15
Posts: 109
·I am using an ADC to read an accelerometer and I'm trying to scale the input.
P75······· CON $00C0 ' 0.75
P50······· CON $0080 ' 0.50
P25······· CON $0040 ' 0.25
SCLK······ CON 6
CS········ CON 7
SerData_in CON 8
adc······· VAR Word
sValue···· VAR Word
main:
GOSUB convert
GOSUB print
GOTO main
print:
DEBUG HOME
DEBUG "Raw value... ", DEC adc, " ", CR
DEBUG "Filtered.... ", DEC sValue, " "
sValue = adc
RETURN
convert:
LOW CS
SHIFTIN Serdata_in,SCLK,MSBPOST,[noparse][[/noparse]adc\12]
HIGH CS
sValue = (adc */ P25) + (sValue */ P75)
adc = adc */ (?)
sValue = sValue */ (?)
RETURN
I know this my ADC has 4096 counts each count = 1mV and my accelerometer out puts 27 mV per G and has an at rest reading of 2.5V or 2500 counts.
My question is how can I scale this so I get an at rest reading and +/- G's?
·
P75······· CON $00C0 ' 0.75
P50······· CON $0080 ' 0.50
P25······· CON $0040 ' 0.25
SCLK······ CON 6
CS········ CON 7
SerData_in CON 8
adc······· VAR Word
sValue···· VAR Word
main:
GOSUB convert
GOSUB print
GOTO main
print:
DEBUG HOME
DEBUG "Raw value... ", DEC adc, " ", CR
DEBUG "Filtered.... ", DEC sValue, " "
sValue = adc
RETURN
convert:
LOW CS
SHIFTIN Serdata_in,SCLK,MSBPOST,[noparse][[/noparse]adc\12]
HIGH CS
sValue = (adc */ P25) + (sValue */ P75)
adc = adc */ (?)
sValue = sValue */ (?)
RETURN
I know this my ADC has 4096 counts each count = 1mV and my accelerometer out puts 27 mV per G and has an at rest reading of 2.5V or 2500 counts.
My question is how can I scale this so I get an at rest reading and +/- G's?
·
Comments
· IF counts.BIT15 THEN
··· gForce = 0 - ((ABS(counts) - 2500) / 27)
· ELSE
··· gForce = (counts - 2500) / 27
· ENDIF
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Post Edited (Jon Williams (Parallax)) : 4/10/2006 11:22:01 PM GMT
+G [noparse][[/noparse]if counts > 2500] =·counts - 2500 / 27
-G [noparse][[/noparse]if counts < 2500] = 2500 - counts / -27
???
Post Edit -- D'Oh!
Post Edited (PJ Allen) : 4/11/2006 1:07:50 AM GMT
gForce = 0 - ((ABS(counts) - atrest) / 27)
Is it possable to average numbers?
But, remember, with acceleration, time is a big deal.· So, mind what you are averaging.
Post Edited (PJ Allen) : 4/11/2006 1:48:08 PM GMT