Shop OBEX P1 Docs P2 Docs Learn Events
Need help with LTC1298 ADC code — Parallax Forums

Need help with LTC1298 ADC code

MarkSMarkS Posts: 342
edited 2008-01-27 17:14 in Propeller 1
I'm making a temperature controller based on the LM34 temperature sensor and the LTC1298 ADC. My understanding, after reading the data sheet, is that I set to CS pin low and then have the clock pin alternating between high and low while outputting the initialization bits to the ADC and while reading the conversion bits from the ADC. To stop the conversion, set the CS pin to high. It sounds simple enough, but I'm not getting anything from the ADC. I must be doing something wrong. I've uploaded my code. It's very rough and incomplete, but I'm more concerned with getting a reading from the ADC than pretty code.

What am I doing wrong here? I'm at a total loss.

[noparse][[/noparse]edit] Data Sheet [noparse][[/noparse]/edit]

Post Edited (MarkS) : 1/26/2008 7:36:45 AM GMT

Comments

  • OzStampOzStamp Posts: 377
    edited 2008-01-26 07:34
    Hi Mark

    Check the PUB with the dira statements in it..

    dira ~~ is output ( you've got "DIN" defined as an output) you could well have it labelled correct but check it ..

    Also your first PUB is a forever running PUB ( it has a repeat ...?)


    Also check your indentations ...

    cheers

    ron Mel oz
  • MarkSMarkS Posts: 342
    edited 2008-01-26 07:37
    OzStamp said...
    Hi Mark

    Check the PUB with the dira statements in it..

    dira ~~ is output ( you've got "DIN" defined as an output) you could well have it labelled correct but check it ..

    Also your first PUB is a forever running PUB ( it has a repeat ...?)


    Also check your indentations ...

    cheers

    ron Mel oz

    DIN is an output in relation to the Prop. It's an input on the ADC.

    The Start function just reads the ADC, converts the result, displays it on two 7-segment LEDs and repeats. This code doesn't even begin to look like what the finished code will. This is just a test.

    When finished, this will test two different temperature sensors and two humidity sensors, will activate several relays and will have an LCD display.
  • deSilvadeSilva Posts: 2,967
    edited 2008-01-26 11:10
    Mark,
    your program looks gerenally good.. I shall check the timing with the scope in the afternoon. They shoud look like in the manual smile.gif You will save infinite time by using a scope - do pay the $500 ..$1000 if you plan to do more device interfacing.

    I think the culprit is this line:
    outa[noparse][[/noparse]DIN] := t >> 3
    


    It spoils it all! You never get the bits back you have shifted out. Just invert the initial sequence assigned to "t".

    And leave out all those funny 10µs waits.. They make no sense. You are lucky they won't do any harm, but leaving them out will make the program much more readable.

    ----
    Edit: Though for this kind of problems ViewPort is well suited...

    Post Edited (deSilva) : 1/26/2008 2:20:27 PM GMT
  • MarkSMarkS Posts: 342
    edited 2008-01-26 17:18
    deSilva said...

    Edit: Though for this kind of problems ViewPort is well suited...

    That's what I was thinking, but when I run ViewPort, it clears out the program. [noparse]:([/noparse]
  • deSilvadeSilva Posts: 2,967
    edited 2008-01-26 18:04
    But does it work now?
  • MarkSMarkS Posts: 342
    edited 2008-01-26 19:21
    deSilva said...
    But does it work now?

    Nothing's changed? confused.gif

    I changed it to this, but still nothing happens:

    repeat 4
    outa[noparse][[/noparse]CLK] := 0
    outa[noparse][[/noparse]DIN] := t
    t := t << 1
    outa[noparse][[/noparse]CLK] := 1

    Post Edited (MarkS) : 1/26/2008 7:35:52 PM GMT
  • SawmillerSawmiller Posts: 276
    edited 2008-01-27 01:23
    could compare it with the 1298 object in the exchange.....
    dan

    also do you have it wired up exactly as in the data sheet...? i seem to remember leaving off the capacitor for the Vref one time and it was erratic. could be wrong thou, memorys not what it used to be.tongue.gif

    Post Edited (Sawmiller) : 1/27/2008 1:29:43 AM GMT
  • deSilvadeSilva Posts: 2,967
    edited 2008-01-27 05:31
    Have you also reverted the bitstring assigned to "t"?
  • MarkSMarkS Posts: 342
    edited 2008-01-27 06:12
    deSilva said...
    Have you also reverted the bitstring assigned to "t"?

    Huh? I'm sorry, it has been a long time since I did any kind of serious programming and bit manipulation always got me stuck. I could never remember when to use >>, <<, |, ^, etc. The references I had for this purpose are long gone. What, exactly, do you mean and how do I do it?
    Sawmiller said...
    could compare it with the 1298 object in the exchange.....

    I didn't know that there was one in the exchange. I'll have to look for it.
    Sawmiller said...

    also do you have it wired up exactly as in the data sheet...? i seem to remember leaving off the capacitor for the Vref one time and it was erratic. could be wrong thou, memorys not what it used to be. tongue.gif

    I have it wired up exactly as it shows in the data sheet, save for that capacitor. However, adding that capacitor does nothing to fix the problem. The problem is that I'm getting zero (literally) from the ADC. The display shows '70', which is what it would if the ADC outputted 0.

    Post Edited (MarkS) : 1/27/2008 6:17:17 AM GMT
  • MarkSMarkS Posts: 342
    edited 2008-01-27 06:56
    OK, I found the 1298 Object (thank for the tip!) and it worked. I had to make several changes to the circuit though. The biggest issue was using two 1K resistors on the ADC's output as a voltage divider. This had the effect of cutting the voltage to a point that registered as a low to the Prop. Also, the 10K pot was set to 4 volts instead of the .7 that I thought I had set it to.

    The code I have to parse the output for display is more of a kludge than anything, so I can't be sure what the ADC is outputting, but the display does increase with a change in temperature. When I check my body temp by mouth, it barely registers 90°F, so I suspect that the display code is at fault here.

    Is there a better way to do this:
    tensPlace := temp / 10
    onesPlace := temp - (tensPlace * 10)

    This is obviously inaccurate, but I needed something quickly off the top of my head and I wasn't and still am not sure how the Prop treats a floating point value, which the conversion algorithm gives. Does the Prop round or truncate the result?
  • SawmillerSawmiller Posts: 276
    edited 2008-01-27 11:11
    i have used
    the simple numbers object before, maybe you can use it , or use it for a example
    i'm really lazy, hate to recode if i can use the existing code

    or maybe use the modulus in your division statement so you catch the remainder ?
    i'm playing with the ds1721 , which is a ic2 chip that ouputs the temp in degrees c. ,posted a few days ago. they were .70 canadian on ebay .


    dan
  • deSilvadeSilva Posts: 2,967
    edited 2008-01-27 12:03
    MarkS said...
    deSilva said...
    Have you also reverted the bitstring assigned to "t"?

    Huh? I'm sorry, it has been a long time since I did any kind of serious programming and bit manipulation always got me stuck. I could never remember when to use >>, <<, |, ^, etc. The references I had for this purpose are long gone. What, exactly, do you mean and how do I do it?
    It's diffucult to help under those circumstances. It's best for you to use proven objects only.

    The background here is, that you set three bits for the configuration of your chip. You - or someone else - has assigned those bits to the variable "t". You - or someone else - has now noticed that they must be shifted out MSB first, so you - or someone else - had the funny idea to first shift it to the right, and then get it back out of Nirvana again.

    This was the content of my posting dated yesterday. Sorry you missed the point...

    Edit: I might add that it took me 10 minutes to look through your code to find that issue, and 20 further minutes to understand the datasheet in search of further issues. This half hour however was not wasted. I am compiling some protocols used with ADC communication... It is fantastic.. Each kind has it's own so it seems...

    Post Edited (deSilva) : 1/27/2008 1:07:07 PM GMT
  • MarkSMarkS Posts: 342
    edited 2008-01-27 17:14
    That code you saw came straight out of the BS2 Object's ShiftOut code, which I might add, also didn't work.
Sign In or Register to comment.