Need help with LTC1298 ADC code
MarkS
Posts: 342
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
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
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.
your program looks gerenally good.. I shall check the timing with the scope in the afternoon. They shoud look like in the manual 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:
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
That's what I was thinking, but when I run ViewPort, it clears out the program. [noparse]:([/noparse]
Nothing's changed?
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
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.
Post Edited (Sawmiller) : 1/27/2008 1:29:43 AM GMT
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?
I didn't know that there was one in the exchange. I'll have to look for it.
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
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?
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
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