ADS1118 - SPI - K Type Confusion
Greg LaPolla
Posts: 323
in Propeller 1
I tried to breadboard this and the readings seamed strange, so I had a pcb made and I am getting the same issue.
ADS1118 Datasheet
When reading the ADS1118 in Temp mode (Internal reading) I get the proper readings.
However when reading the ADS1118 in ADC mode with a K type thermocouple, It returns 0. If I grab ahold of the thermocouple the value will increase slowly in my hand I can get it to go up to about 12 or 13. If I put a flame on it I can get it to up to around 125 or so. I have read over the data sheet several times. I am wondering if the result I am getting is the difference between the internal temp and the temp reading of the external k type thermocouple. I can post the code if needed, but since I get the proper reading from the internal temp sensor I am not suspecting my code.
On a second note, I cant seem to capture the SPI comms on a propscope, is it just to fast for the propscope ? It cant even catch the cs line going up and down.
ADS1118 Datasheet
When reading the ADS1118 in Temp mode (Internal reading) I get the proper readings.
However when reading the ADS1118 in ADC mode with a K type thermocouple, It returns 0. If I grab ahold of the thermocouple the value will increase slowly in my hand I can get it to go up to about 12 or 13. If I put a flame on it I can get it to up to around 125 or so. I have read over the data sheet several times. I am wondering if the result I am getting is the difference between the internal temp and the temp reading of the external k type thermocouple. I can post the code if needed, but since I get the proper reading from the internal temp sensor I am not suspecting my code.
On a second note, I cant seem to capture the SPI comms on a propscope, is it just to fast for the propscope ? It cant even catch the cs line going up and down.
Comments
I also have a spin version of the code.
FWIW, I have used this chip before and had no trouble. Looking at your code it all seems fine, so like you I’m really scratching my head. (My design used 10 meg bias resistors, but the design you are using is basically straight out of the App Note you linked, so I doubt this is a factor).
Do you have the thermocouple connected between adc0 and adc1, differential? That is what the mux:=%000 calls out.
Single conversion: Once the mode bit is set to single conversion, start a conversion by setting bit 15 of the config register high. Then wait, either for the ready line to go back high, or for the full conversion time, which should be slightly longer than clkfreq/(samplesPerSecond). Then read the conversion register. The ADC then drops back to its sleep mode until you initiate another conversion.
The thermocouple is connected to AIN0 and AIN1. I have tried with all options and I get the same result. Both of my thermocouples are kinda old like 10 + years and the insolation is fiberglass. I have ordered a new thermocouple type J from amazon that should be here today. If I don't get a better reading with that then I am at a complete loss.
Reading the internal temp sensor gets 421 reading the external gets 0.
The adc channels return the voltage, not temperature directly. The temperature channel is there for your program to use as a cold junction reference, but that has to be combined in firmware with the thermocouple voltage. the calculation procedure is outlined in section 10 of the data sheet. The calculation also has to know the type of thermocouple you are using. Type K and type J have different responses. An advantage of the ADS1118 is that it allows you to use any type of thermocouple.
I might be able to help more if you post your program in Spin. I'm far from fluent in C, and I'm puzzled by the code you posted above. The config is set for reading the adc, but the returned value is shifted right by two as if it is reading the temperature channel. A 14-bit value of 421 returned from the temperature channel corresponds to about 13 °C. (421 * 0.03125 °C per bit.). Is that reasonable? In your first post, you reported a value of 125 when the K thermocouple was in a flame. Your PGA setting %101 is fine for the full scale of 256mV, 7.8125 µV per bit. But 125*7.8125/40 = ~24 °C. (The factor 40µV/°C is the typical output of the K thermocouple)
The join is not where the magic happens. The naming "couple" is misleading. It's the wire itself that is doing the work. Or more specifically, along the temperature gradient of the wire.
You can connect a known source of voltage to the ADC inputs to test the circuit and the firmware. Basic troubleshooting.
The configuration word itself looks okay. One thing though, That statement should only be applied to the temperature measurement. The ADC readings on the other hand use all 16 bits.
There is a possible bug in spi.spin, especially as it relates to single shot mode. Here is the Shiftout method, and you can see that it returns before it executes the instruction that is supposed to deselect the chip. So, the pin sticks low. That puzzled me when I first ran the code, but it started to work and show the proper decoding when I rewrote it with result := instead of the RETURN.
I'm attaching a photo of my "kSUMS" board that uses two ADS1115 chips. It can take 3 thermocouples in differential mode or 6 in single ended mode. The SIP resistor pack on the board sets the common mode voltage so that the couples have best emi resistance. There is a separate reference temperature sensor in contact with the terminal block.
I was hopeful when the ADS1118 came out that it would be a drop-in replacement for the ADS1115, nice to have a built-in reference sensor. But for some reason, they went with SPI for the ADS1118, whereas everything else in that family is i2c. Go figure.
Thanks for the info on the bug. I actually got Beau's SPI spin and I found your ADS115 code in the forum and I started from scratch and I actually got the one shot to work. After that I started suspecting the code I was using had an issue.
I will make the changes you showed there and see if I can get it to work. Doesn't RETURN cause an exit ?
@DigitalBob
Check out JLPCB. 2 bucks for 5 boards but 17 bucks to ship. Pretty fast turn around.
This is the board I have used. PWF used to make a
Propeller based accessory control board for a FRC
team.
The DR0 - DR3 wires are not required, but it may
require two 3.3v supplies (mine did).
Bill M.
One shot is working perfectly using 2 channels.
I can even see the communication in the Propscope. I have attached the new working code.
Using the math from your ads1115 code when you output to pst term you divide by 1000. When I do this I always get 0. I don't think thats normal.
Is there something wrong in my code posted in previous post.
In my object for the ADS1115, I convert from the raw count into microvolts, as you have also... That serves the same purpose as the floating point operation that you have commented out That is, 8 - 3/16 = 7 + 13/16 = 7.8125, which is the scale factor of 7.8125 microvolts per bit, on the highest programmable gain setting. To go from that to the thermocouple temperature, turn the crank on the microvolts and the reference temperature.
You might find it expedient to extract the routines that you need from the spin object and put them as dedicated methods in your project. You only need to deal with one mode, and with 16 bit words, and with setting up the pins. There is not much to it when it is stripped down.
https://gitlab.com/propeller1/
Spin object has been derived from Beau's SPI Spin object and Tracy's ADS1115 object. It still has a little weirdness with timing when reading thermocouple and cold junction alternately. Feedback is welcome on that.
C driver was based on an Arduino driver I found. Seems to work pretty good. Feedback welcome on that as well.
@"Tracy Allen" The divide by 1000 was in the demo program. It always is 0.
Still trying to figure out how to get actual millivolts from the thermocouple reading. Thermocouple always reads 0 at room temp and cold junction reading is around 21C. Applying heat to thermocouple will cause it to increase from 0.
There is no mystery to the actual millivolts from the thermocouple being zero at room temperature. That is, zero when the thermocouple temperature equals the reference temperature, whatever it may be. Thermocouples always produce a voltage as a function of differential temperature.
Your next steps involve a calculation, or more likely a lookup table that has the K voltage vs temperature referred to an ice point temperature of zero °C.
1) lookup the voltage a type k thermocouple would produce at your measured reference temperature (wrt to an ice bath).
2) add that to your measured thermocouple differential voltage.
3) use that to lookdown your actual thermocouple temperature.
I'll attach my object for type K couples that takes the above steps and include DAT for type K in 10 degree intervals from -200 °C to +1370 °C. The code uses linear interpolation within those intervals.