LTC1298 Voltmeter Project
I am a hardware person needing help with a A/D voltmeter project.
I tried the sample software for interfacing the STAMP 2 and an LTC1298 shown below.
The software example displays the counts from 0 to 4098, rather than voltage or millivolts.
I suck at math -- what do I need to add to the program to display millivolts in the debug window?
HELP -- HELP
*************************************************************************************8
'LTC1298 & STAMP2
CS con 0 ' Chip select; 0 = active
CLK con 1 ' Clock to ADC; out on rising, in on falling edge.
DIO_n con 2 ' Data I/O pin _number_.
config var nib ' Configuration bits for ADC.
AD var word ' Variable to hold 12-bit AD result.
startB var config.bit0 ' Start bit for comm with ADC.
sglDif var config.bit1 ' Single-ended or differential mode.
oddSign var config.bit2 ' Channel selection.
msbf var config.bit3 ' Output 0s after data xfer complete.
high CS ' Deactivate ADC to begin.
high DIO_n ' Set data pin for first start bit.
again: ' Main loop.
for oddSign = 0 to 1 ' Toggle between input channels.
gosub convert ' Get data from ADC.
debug "channel ",DEC oddSign, ": ",DEC AD,cr ' Display data.
pause 500 ' Wait a half second.
next ' Change channels.
goto again ' Endless loop.
convert:
config = config | %1011 ' Set all bits except oddSign.
low CS ' Activate the ADC.
shiftout DIO_n,CLK,lsbfirst,[noparse][[/noparse]config\4] ' Send config bits.
shiftin DIO_n,CLK,msbpost,[noparse][[/noparse]AD\12] ' Get data bits.
high CS ' Deactivate the ADC.
return
I tried the sample software for interfacing the STAMP 2 and an LTC1298 shown below.
The software example displays the counts from 0 to 4098, rather than voltage or millivolts.
I suck at math -- what do I need to add to the program to display millivolts in the debug window?
HELP -- HELP
*************************************************************************************8
'LTC1298 & STAMP2
CS con 0 ' Chip select; 0 = active
CLK con 1 ' Clock to ADC; out on rising, in on falling edge.
DIO_n con 2 ' Data I/O pin _number_.
config var nib ' Configuration bits for ADC.
AD var word ' Variable to hold 12-bit AD result.
startB var config.bit0 ' Start bit for comm with ADC.
sglDif var config.bit1 ' Single-ended or differential mode.
oddSign var config.bit2 ' Channel selection.
msbf var config.bit3 ' Output 0s after data xfer complete.
high CS ' Deactivate ADC to begin.
high DIO_n ' Set data pin for first start bit.
again: ' Main loop.
for oddSign = 0 to 1 ' Toggle between input channels.
gosub convert ' Get data from ADC.
debug "channel ",DEC oddSign, ": ",DEC AD,cr ' Display data.
pause 500 ' Wait a half second.
next ' Change channels.
goto again ' Endless loop.
convert:
config = config | %1011 ' Set all bits except oddSign.
low CS ' Activate the ADC.
shiftout DIO_n,CLK,lsbfirst,[noparse][[/noparse]config\4] ' Send config bits.
shiftin DIO_n,CLK,msbpost,[noparse][[/noparse]AD\12] ' Get data bits.
high CS ' Deactivate the ADC.
return
Comments
If it's 2V, say, then you're dealing with 2V / 4098 = 0.49mV / step (count.)· So, if it bounces back "1235", then it's 1235 X 0.49 mV = 605 mV.
So how do I convert the calculation you listed into actual code
Where do I embed the calculations you listed into the actual BS2 program that I listed, so it would display millivolts via debug
I am using a BASIC STAMP II with the LTC1298
thanks
Look for the subject: Cookbook example, how to compute Y=X*1.2207
Here, I'm sure you're asking, "What's the relevance of that, PJ?"·
5V / 4096 = 1.2207 mV (!!)
Ok, final question here : where in the program (above) can I place the calculation?
thanks
Tom
AD = AD ** 14464 + AD ' convert counts to millivolts
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com