Shop OBEX P1 Docs P2 Docs Learn Events
TLC 1549 ADC w/ stamp — Parallax Forums

TLC 1549 ADC w/ stamp

ArchiverArchiver Posts: 46,084
edited 2002-06-02 07:43 in General Discussion
Hi all,

I'm trying to get a TCL1549 10bit ADC to send data to my bs2 with no
real success. I had it working with an 8bit ADC0831 (ala' basic
stamp lessons...) and it was working fine. I switched over to the
10bit one, changed my code to reflect a 10 bit ADC as well as the
pin assignments, but the data I'm getting back isn't right. (I am
getting data, it just makes no sense).

The binary value of adcBits gets changed each time through the
loop. If the sensor is outputing 0V the binary vaule cyles between
0 and 100, but sometimes 1000. Shouldn't I at least be getting
0000000000, 0000000100, etc. (?) If the output is 5V, the binary
reading is 1111111111, 1111111101, or 1111111011

In looking at the data sheet for the component I seems that the data
should be getting sent most significant bit post (I'm trying to use
mode 1).. but I'm by no means and must confess I don't understand
most of the datasheet. HELP! Code is below. Sorry for such a long
post.

'{$STAMP BS2}

'''''''''''''''''''''''''''''''''''''''''''''
' DECLARATIONS FOR DATA TRANSMISSION FROM ADC
'''''''''''''''''''''''''''''''''''''''''''''

'******VARIABLES******
adcbits var word

'*****CONSTANTS******
CS CON 11
CLK CON 12
DO CON 13


'''''''''''''''''''''''''''''''''''''''''''''
' OTHER DECLARATIONS
'''''''''''''''''''''''''''''''''''''''''''''

'******VARIABLES******
s1Reading var word
'used to keep track of the current sensor readings
'*****CONSTANTS******
adcResolution CON 1024 'the
resolution of the ADC in use.

'''''''''''''''''''''''''''''''''''''''''''''''''''
' ****** PROGRAM BODY ******
'''''''''''''''''''''''''''''''''''''''''''''''''''

debug cls
'Open the debug screen and clear it

''''''''''''''''''''''''''''''''''''''''''''
' START MAIN PROCEDURE THAT CALLS ALL OTHERS
''''''''''''''''''''''''''''''''''''''''''''
PAUSE 500
GOSUB MAIN

MAIN:

high 8
'setup pin1 on multiplex for sensor1
low 9
low 10
GOSUB getCurrentVoltage
s1Reading = (100 * adcbits)/adcResolution
'The percentage of the reading between 0 - 5V
GOSUB DISPLAY

goto MAIN

''''''''''''''''''''''''''''''''''''''''''''
' getcurrentVoltage takes in the current
' voltage reading via serial data, and inputs
' it into adcbits
''''''''''''''''''''''''''''''''''''''''''''
getCurrentVoltage:

high CS
'go high on the CS pin of the ADC0831
low CS
'go low on the CS pin.. ADC now primed for transmission
low CLK
pulsout CLK,210
shiftin DO,CLK,msbpost,[noparse][[/noparse]adcbits\10]
'current binary reading is put into adcbits

RETURN

''''''''''''''''''''''''''''''''''''''''''''''''''
' DISPLAY is used to ouptut the current readings
''''''''''''''''''''''''''''''''''''''''''''''''''
DISPLAY:

debug home
'go to first line of debug window
debug CR, "s1BINARY = ", bin adcBits
debug CR, "s1Int = ", dec3 s1Reading

pause 1000
debug cls
RETURN

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2002-06-02 07:08
    Hi,

    The data sheet you said, wants you to use msbpost. Try using lsbfirst and
    see what you get, the data sheet
    maybe written for another type of microcontroller with a slightly different
    meaning for msbpost and lsbfirst. The
    difference might be as to where the start reading data begins on the clock
    pulse. See if lsbfirst works and let
    us know the results. I do not have the data sheet for the TCL1549, but I will
    try to find one and see if I can
    see what you need to do for changes from the ADC0831. Most ADC chips I have
    experienced have similar code but
    with slightly different meanings as how to apply them, because of the type of
    microcontroller used to make the
    data sheets.

    Have Fun !!
    Dale Fleischmann

    sailing711 wrote:

    > Hi all,
    >
    > I'm trying to get a TCL1549 10bit ADC to send data to my bs2 with no
    > real success. I had it working with an 8bit ADC0831 (ala' basic
    > stamp lessons...) and it was working fine. I switched over to the
    > 10bit one, changed my code to reflect a 10 bit ADC as well as the
    > pin assignments, but the data I'm getting back isn't right. (I am
    > getting data, it just makes no sense).
    >
    > The binary value of adcBits gets changed each time through the
    > loop. If the sensor is outputing 0V the binary vaule cyles between
    > 0 and 100, but sometimes 1000. Shouldn't I at least be getting
    > 0000000000, 0000000100, etc. (?) If the output is 5V, the binary
    > reading is 1111111111, 1111111101, or 1111111011
    >
    > In looking at the data sheet for the component I seems that the data
    > should be getting sent most significant bit post (I'm trying to use
    > mode 1).. but I'm by no means and must confess I don't understand
    > most of the datasheet. HELP! Code is below. Sorry for such a long
    > post.
    >
    > '{$STAMP BS2}
    >
    > '''''''''''''''''''''''''''''''''''''''''''''
    > ' DECLARATIONS FOR DATA TRANSMISSION FROM ADC
    > '''''''''''''''''''''''''''''''''''''''''''''
    >
    > '******VARIABLES******
    > adcbits var word
    >
    > '*****CONSTANTS******
    > CS CON 11
    > CLK CON 12
    > DO CON 13
    >
    > '''''''''''''''''''''''''''''''''''''''''''''
    > ' OTHER DECLARATIONS
    > '''''''''''''''''''''''''''''''''''''''''''''
    >
    > '******VARIABLES******
    > s1Reading var word
    > 'used to keep track of the current sensor readings
    > '*****CONSTANTS******
    > adcResolution CON 1024 'the
    > resolution of the ADC in use.
    >
    > '''''''''''''''''''''''''''''''''''''''''''''''''''
    > ' ****** PROGRAM BODY ******
    > '''''''''''''''''''''''''''''''''''''''''''''''''''
    >
    > debug cls
    > 'Open the debug screen and clear it
    >
    > ''''''''''''''''''''''''''''''''''''''''''''
    > ' START MAIN PROCEDURE THAT CALLS ALL OTHERS
    > ''''''''''''''''''''''''''''''''''''''''''''
    > PAUSE 500
    > GOSUB MAIN
    >
    > MAIN:
    >
    > high 8
    > 'setup pin1 on multiplex for sensor1
    > low 9
    > low 10
    > GOSUB getCurrentVoltage
    > s1Reading = (100 * adcbits)/adcResolution
    > 'The percentage of the reading between 0 - 5V
    > GOSUB DISPLAY
    >
    > goto MAIN
    >
    > ''''''''''''''''''''''''''''''''''''''''''''
    > ' getcurrentVoltage takes in the current
    > ' voltage reading via serial data, and inputs
    > ' it into adcbits
    > ''''''''''''''''''''''''''''''''''''''''''''
    > getCurrentVoltage:
    >
    > high CS
    > 'go high on the CS pin of the ADC0831
    > low CS
    > 'go low on the CS pin.. ADC now primed for transmission
    > low CLK
    > pulsout CLK,210
    > shiftin DO,CLK,msbpost,[noparse][[/noparse]adcbits\10]
    > 'current binary reading is put into adcbits
    >
    > RETURN
    >
    > ''''''''''''''''''''''''''''''''''''''''''''''''''
    > ' DISPLAY is used to ouptut the current readings
    > ''''''''''''''''''''''''''''''''''''''''''''''''''
    > DISPLAY:
    >
    > debug home
    > 'go to first line of debug window
    > debug CR, "s1BINARY = ", bin adcBits
    > debug CR, "s1Int = ", dec3 s1Reading
    >
    > pause 1000
    > debug cls
    > RETURN
    >
    > To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    > from the same email address that you subscribed. Text in the Subject and Body
    of the message will be ignored.
    >
    >
    > Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
  • ArchiverArchiver Posts: 46,084
    edited 2002-06-02 07:43
    Hi Again,

    Found the data sheets for the TLC1549, and in your program you have one line
    the reads;

    adcResolution CON 1024 'the resolution of the ADC in
    use.

    in the data sheet this value should be 512 not 1024, this may also be your
    problem(s) you are experiencing.

    Also, do you have the -Vref tied to ground or some negative voltage, if it is a
    negative voltage change it to ground.
    The Basic Stamp does not like negative numbers and changes them to the two's
    compliment, example -3 would be changed
    to -3 * -3 = 9 or -3 squared, -2 would equal 4, etc. Try all of the suggestion
    I have made one at a time and see if
    anyone of them makes any difference, before going to the next on. If no change
    go back to the original code then try
    the next suggestion, you may end up making more then one change before things
    start to work correctly. With all the
    suggestions I have made there is 6 different combinations you need to try, see
    what each does before going to the next
    suggestion.

    Have Fun !!
    Dale Fleischmann

    Dale Fleischmann wrote:

    > Hi,
    >
    > The data sheet you said, wants you to use msbpost. Try using lsbfirst and
    see what you get, the data sheet
    > maybe written for another type of microcontroller with a slightly different
    meaning for msbpost and lsbfirst. The
    > difference might be as to where the start reading data begins on the clock
    pulse. See if lsbfirst works and let
    > us know the results. I do not have the data sheet for the TCL1549, but I will
    try to find one and see if I can
    > see what you need to do for changes from the ADC0831. Most ADC chips I have
    experienced have similar code but
    > with slightly different meanings as how to apply them, because of the type of
    microcontroller used to make the
    > data sheets.
    >
    > Have Fun !!
    > Dale Fleischmann
    >
    > sailing711 wrote:
    >
    > > Hi all,
    > >
    > > I'm trying to get a TCL1549 10bit ADC to send data to my bs2 with no
    > > real success. I had it working with an 8bit ADC0831 (ala' basic
    > > stamp lessons...) and it was working fine. I switched over to the
    > > 10bit one, changed my code to reflect a 10 bit ADC as well as the
    > > pin assignments, but the data I'm getting back isn't right. (I am
    > > getting data, it just makes no sense).
    > >
    > > The binary value of adcBits gets changed each time through the
    > > loop. If the sensor is outputing 0V the binary vaule cyles between
    > > 0 and 100, but sometimes 1000. Shouldn't I at least be getting
    > > 0000000000, 0000000100, etc. (?) If the output is 5V, the binary
    > > reading is 1111111111, 1111111101, or 1111111011
    > >
    > > In looking at the data sheet for the component I seems that the data
    > > should be getting sent most significant bit post (I'm trying to use
    > > mode 1).. but I'm by no means and must confess I don't understand
    > > most of the datasheet. HELP! Code is below. Sorry for such a long
    > > post.
    > >
    > > '{$STAMP BS2}
    > >
    > > '''''''''''''''''''''''''''''''''''''''''''''
    > > ' DECLARATIONS FOR DATA TRANSMISSION FROM ADC
    > > '''''''''''''''''''''''''''''''''''''''''''''
    > >
    > > '******VARIABLES******
    > > adcbits var word
    > >
    > > '*****CONSTANTS******
    > > CS CON 11
    > > CLK CON 12
    > > DO CON 13
    > >
    > > '''''''''''''''''''''''''''''''''''''''''''''
    > > ' OTHER DECLARATIONS
    > > '''''''''''''''''''''''''''''''''''''''''''''
    > >
    > > '******VARIABLES******
    > > s1Reading var word
    > > 'used to keep track of the current sensor readings
    > > '*****CONSTANTS******
    > > adcResolution CON 1024 'the
    > > resolution of the ADC in use.
    > >
    > > '''''''''''''''''''''''''''''''''''''''''''''''''''
    > > ' ****** PROGRAM BODY ******
    > > '''''''''''''''''''''''''''''''''''''''''''''''''''
    > >
    > > debug cls
    > > 'Open the debug screen and clear it
    > >
    > > ''''''''''''''''''''''''''''''''''''''''''''
    > > ' START MAIN PROCEDURE THAT CALLS ALL OTHERS
    > > ''''''''''''''''''''''''''''''''''''''''''''
    > > PAUSE 500
    > > GOSUB MAIN
    > >
    > > MAIN:
    > >
    > > high 8
    > > 'setup pin1 on multiplex for sensor1
    > > low 9
    > > low 10
    > > GOSUB getCurrentVoltage
    > > s1Reading = (100 * adcbits)/adcResolution
    > > 'The percentage of the reading between 0 - 5V
    > > GOSUB DISPLAY
    > >
    > > goto MAIN
    > >
    > > ''''''''''''''''''''''''''''''''''''''''''''
    > > ' getcurrentVoltage takes in the current
    > > ' voltage reading via serial data, and inputs
    > > ' it into adcbits
    > > ''''''''''''''''''''''''''''''''''''''''''''
    > > getCurrentVoltage:
    > >
    > > high CS
    > > 'go high on the CS pin of the ADC0831
    > > low CS
    > > 'go low on the CS pin.. ADC now primed for transmission
    > > low CLK
    > > pulsout CLK,210
    > > shiftin DO,CLK,msbpost,[noparse][[/noparse]adcbits\10]
    > > 'current binary reading is put into adcbits
    > >
    > > RETURN
    > >
    > > ''''''''''''''''''''''''''''''''''''''''''''''''''
    > > ' DISPLAY is used to ouptut the current readings
    > > ''''''''''''''''''''''''''''''''''''''''''''''''''
    > > DISPLAY:
    > >
    > > debug home
    > > 'go to first line of debug window
    > > debug CR, "s1BINARY = ", bin adcBits
    > > debug CR, "s1Int = ", dec3 s1Reading
    > >
    > > pause 1000
    > > debug cls
    > > RETURN
    > >
    > > To UNSUBSCRIBE, just send mail to:
    > > basicstamps-unsubscribe@yahoogroups.com
    > > from the same email address that you subscribed. Text in the Subject and
    Body of the message will be ignored.
    > >
    > >
    > > Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
    >
    > To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    > from the same email address that you subscribed. Text in the Subject and Body
    of the message will be ignored.
    >
    >
    > Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
Sign In or Register to comment.