Shop OBEX P1 Docs P2 Docs Learn Events
ADC Help — Parallax Forums

ADC Help

Tom PTom P Posts: 97
edited 2009-04-14 15:11 in BASIC Stamp
Stampers:

I 'am experimenting with a BASIC STAMP 1 and a LTC1298 A/d converter.
The program seems to display reading but they are not voltages.
How can I display voltages from 0 to 5 volts on the Debug screen using the program below?????
thanks - tom
********************************************************************

' Voltmeter. bs1

SYMBOL CS = 0 ' Chip select; 0 = active.

SYMBOL CLK = 1 ' Clock to ADC; out on rising, in on falling edge.

SYMBOL DIO_n = 2 ' Pin _number_ of data input/output.

SYMBOL DIO_p = pin2 ' Variable_name_ of data input/output.

SYMBOL ADbits = b1 ' Counter variable for serial bit reception.

SYMBOL AD = w1 ' 12-bit ADC conversion result.

SYMBOL sglDif = 1 ' Single-ended, two-channel mode.

SYMBOL msbf = 1 ' Output 0s after data transfer is complete.

SYMBOL oddSign = bit0 ' Program writes channel # to this bit.

high CS ' Deactivate the ADC to begin.

Again: ' Main loop.

For oddSign = 0 to 1 ' Toggle between input channels.

gosub Convert ' Get data from ADC.

debug "ch ",#oddSign,":",#AD,cr ' Show the data on PC screen.

pause 500 ' Wait a half second.

next ' Change input channels.

goto Again ' Endless loop.

Convert:

low CLK ' Low clock--output on rising edge.

high DIO_n ' Switch DIO to output high (start bit).

low CS ' Activate the 1298.

pulsout CLK,5 ' Send start bit.

let DIO_p = sglDif ' First setup bit.

pulsout CLK,5 ' Send bit.

let DIO_p = oddSign ' Second setup bit.

pulsout CLK,5 ' Send bit.

let DIO_p = msbf ' Final setup bit.

pulsout CLK,5 ' Send bit.

input DIO_n ' Get ready for input from DIO.

let AD = 0 ' Clear old ADC result.

for ADbits = 1 to 13 ' Get null bit + 12 data bits.

let AD = AD*2+DIO_p ' Shift AD left, add new data bit.

pulsout CLK,5 ' Clock next data bit in.

next ' Get next data bit.

high CS ' Turn off the ADC

return ' Return to program.

Comments

  • Lee HarkerLee Harker Posts: 104
    edited 2009-04-14 15:11
    Tom,

    The data you receive from an ADC represents the value of the input voltage related to the reference. For a 12 bit ADC, the values can be from 0-4095. 0 of course is 0 volts and 4095 would be when the input is equal to the reference.

    If you have the reference tied to 5 volts, then the voltage being read is (ADC value/4095)*5. You will need to deal with the decimal values as your needs demand.

    Hope this helps.
Sign In or Register to comment.