Shop OBEX P1 Docs P2 Docs Learn Events
STAMP 1 - A/D help — Parallax Forums

STAMP 1 - A/D help

Tom PTom P Posts: 97
edited 2009-04-23 10:53 in BASIC Stamp
<!--StartFragment -->Please Help!!!

Wonder if someone can help with a STAMP 1 problem?
I want to connect a LTC1298·- A/D converter to a STAMP 1,
and read voltage on the Debug screen in millivolts.
How can·I·change program to read millivolts.
Thanks in advance for your help.
Tom


**************************************************************************************************************************
' Voltmeter. bs1
' {$STAMP BS1}
' {$PBASIC 1.0}

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··

Comments

  • dandreaedandreae Posts: 1,375
    edited 2009-04-22 15:44
    Here is a link for an application note for the BS1 and the LTC 1298 that will help you with this project:· http://www.eetasia.com/ARTICLES/2002FEB/2002FEB20_AMD_MPR_EMS_AN.PDF?SOURCES=DOWNLOAD

    It goes over millivolts.

    Dave

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Dave Andreae

    Parallax Tech Support·
  • Tom PTom P Posts: 97
    edited 2009-04-22 19:12
    More Help Needed
    I have 1 volt on input to ADC, with 5.01 volt supply
    I am trying to display millivolts on screen and LCD.
    when I solve for AD -- orignal program I get 1261 counts
    When I solve for AZ -- Tracy Allen's equation I get 1536 mV --- AZ = AD** 14464 + AD --
    I can't seem to figure out why I am not getting 1000mv for 1 volt on input?
    any help appreciated
    Tom


    ***************************************************************************************
    ' Voltmeter. bs1
    ' {$STAMP BS1}
    ' {$PBASIC 1.0}

    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.
    SYMBOL AZ = W2


    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.
    AZ = AD** 14464 + AD
    'DEBUG "ch ",#oddSign,":",#AD,CR ' Show the data on PC screen.
    DEBUG "ch ",#oddSign,":",#AZ," mV",CR ' Show the data on PC screen.
    SEROUT 7,T2400,("ch ", #oddSign,":",#Az," mV",10,13) 'send via serial
    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.
  • FranklinFranklin Posts: 4,747
    edited 2009-04-22 23:05
    What do you get with 0v in?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • Tom PTom P Posts: 97
    edited 2009-04-23 10:53
    Stephen:

    Observations:
    With zero volts on the input of channel 0 -- I get 0 -output
    With 1 volt on input channel 0 ----·I get 1536

    tom
Sign In or Register to comment.