PDA

View Full Version : Need help with LTC1298 ADC code



MarkS
01-26-2008, 02:59 PM
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.

Data Sheet (http://www.linear.com/pc/downloadDocument.do?navId=H0,C1,C1155,C1001,C1158, P1445,D2760)

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

OzStamp
01-26-2008, 03:34 PM
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

MarkS
01-26-2008, 03:37 PM
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.

deSilva
01-26-2008, 07:10 PM
Mark,
your program looks gerenally good.. I shall check the timing with the scope in the afternoon. They shoud look like in the manual http://forums.parallax.com/images/smilies/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[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 10s 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

MarkS
01-27-2008, 01:18 AM
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. :(

deSilva
01-27-2008, 02:04 AM
But does it work now?

MarkS
01-27-2008, 03:21 AM
deSilva said...
But does it work now?


Nothing's changed? http://forums.parallax.com/images/smilies/confused.gif

I changed it to this, but still nothing happens:

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

Post Edited (MarkS) : 1/26/2008 7:35:52 PM GMT

Sawmiller
01-27-2008, 09:23 AM
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.http://forums.parallax.com/images/smilies/tongue.gif

Post Edited (Sawmiller) : 1/27/2008 1:29:43 AM GMT

deSilva
01-27-2008, 01:31 PM
Have you also reverted the bitstring assigned to "t"?

MarkS
01-27-2008, 02:12 PM
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. http://forums.parallax.com/images/smilies/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

MarkS
01-27-2008, 02:56 PM
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 90F, 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?

Sawmiller
01-27-2008, 07:11 PM
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

deSilva
01-27-2008, 08:03 PM
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

MarkS
01-28-2008, 01:14 AM
That code you saw came straight out of the BS2 Object's ShiftOut code, which I might add, also didn't work.