Shop OBEX P1 Docs P2 Docs Learn Events
LTC1298 Voltmeter Project — Parallax Forums

LTC1298 Voltmeter Project

Tom PTom P Posts: 97
edited 2007-05-16 18:15 in General Discussion
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

Comments

  • PJAllenPJAllen Banned Posts: 5,065
    edited 2007-05-15 00:19
    What's your "Full Scale" voltage?·

    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.
  • Tom PTom P Posts: 97
    edited 2007-05-15 01:10
    The maximum voltage would be 5 volts input.
    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
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2007-05-16 00:52
    Here's a good read -- http://www.emesystems.com/BS2math1.htm#cookbook

    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 (!!)
  • Tom PTom P Posts: 97
    edited 2007-05-16 11:47
    Aha -- I am beginnning to see the light but its a long tunnel!!
    Ok, final question here : where in the program (above) can I place the calculation?

    thanks
    Tom
  • Mike GreenMike Green Posts: 23,101
    edited 2007-05-16 14:21
    You put the calculation anywhere you want where the inputs to the calculation are known and you need the result. That statement may seem simplistic, but it's a simple idea. The calculation isn't just a formula that specifies the relationship among several variables. It's a set of steps for doing a calculation and it's applied at a particular time (when it is executed by the Stamp).
  • Tracy AllenTracy Allen Posts: 6,666
    edited 2007-05-16 18:15
    Tom, to be very specific about it, the most logical places to put that calculations would be either inside the convert subroutine, just before the RETURN, or, in the main routine, just after the GOSUB convert.

    AD = AD ** 14464 + AD ' convert counts to millivolts

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
Sign In or Register to comment.