Guys, I need some urgent helps here. I am getting an unexpected result when reading ADS1248.
I have wired up ADS1248 to read a 3-wire RTD, as shown in Figure 3, Page 4 of this document: http://www.ti.com/lit/an/sbaa180/sbaa180.pdf
I have hard coded the register to read AN0(+) and AN1(-), I use VREFP1 and VREFN1 as rerference input. I use internal clock (CLK pin grounded), I connect RESET pin to VCC. I separated DRDY and DOUT pins.
My problem is I do not get the desired reading. I am getting randomly fluctuate values from zero to full scale. Furthermore, I do not seem to get 1 mA output to the channels, as I configured, it reads zero.
My simplied code is as shown below. I have verified that the SPI command routine works well (one of the evident is my readback values is the same as my write values, as shown within the code). So please assume SPI works well.
Further info, *sometimes* I am getting (on the oscilloscope ) a capacitor-discharing pattern at the end of the 24- reading pulses. This seems to be telling me that the ADC has not finished outputing data yet?
Can someone look at the following code and possibly tells me what is going wrong? Thanks in advance.
void reset(void){ int i; char c[10], c1[10]; /* to reset SPI */ ads1248_write_low(RTD_CS_); for (i=0; i<5; i++){} ads1248_write_high(RTD_CS_); for (i=0; i<100; i++){} /* then issue RESET command to reset chip */ ads1248_cmd(RTD_CMD_RESET, 0, 0, NULL); /* stop continue data reading */ ads1248_cmd(RTD_CMD_SDATAC, 0, 0, NULL); ads1248_write_high(RTD_START); /* set IDAC to 1mA for 3-wire PT-100 */ c[RTD_REG_IDAC0] = IMAG(6); /* connect AIN0 to IDAC1 and AIN1 to IDAC2 */ c[RTD_REG_IDAC1] = RTD_MUX_CH0; c[RTD_REG_GPIOCFG] = c[RTD_REG_GPIODIR] = c[RTD_REG_GPIODAT] = 0; c[RTD_REG_MUX0] = RTD_MUX_CH0; c[RTD_REG_VBIAS] = 0; /* use internal oscillator, internal reference, onboard reference, normal operation*/ c[RTD_REG_MUX1] = VREFCON_ON | REFSELT(1) | MUX_CAL(0); /* PGA=128, Sample rate = 5SPS */ c[RTD_REG_SYS0] = RTD_PGA(5) | RTD_DR(1); for (i=0; i<15; i++) { /* skip calibration register */ if (i>RTD_REG_SYS0 && i<RTD_REG_IDAC0) continue; c1[i] = ~c[i]; while(c[i] != c1[i]) { ads1248_cmd(RTD_CMD_WREG, i, 1, &c[i]); /* read back for verification */ ads1248_cmd(RTD_CMD_RREG, i, 1, &c1[i]); if (i==RTD_REG_IDAC0) c1[i] &= 0x0f; /* debug */ if (c[i] != c1[i]) printf("c1[%d]=%02x\r\n", (int)i, (int)c1[i]); } }}void calibrate(int type){ ads1248_cmd(type, 0, 0, NULL);}main(){ unsigned long ul; reset(); calibrate(RTD_CMD_SELFOCAL); while(1) { /* check if conversion done */ if (DRDY_PIN & RTD_DRDY_) continue; /* issue a READ command and read back to ul */ ads1248_cmd(RTD_CMD_RDATA, 0, 2, (unsigned char *)&ul); /* issue a SYNC command to restart conversion*/ ads1248_cmd(RTD_CMD_SYNC, 0, 0, NULL); /* print out ul */ printf(reading=%ul\n", ul); }}
Hi K H,
If the IDAC is not giving you the programmed current 1mA output, it may be worthwhile to check if the internal reference is turning on by measuring the voltage at VREFOUT.. The VREFCOM pin needs to be connected to GND (or may be connected to AVSS). What voltage are you applying to the Analog supplies (AVDD/AVSS)?
Are you using the ADS1248EVM evaluation board or is this your own board? If you can post a schematic, showing the supply connections and the VREFCOM connection this will help.
I will look through your code to see if I can find any issues.
Best Regards,
Luis
Lius,
Thanks for the reply. I have measured the VREFOUT as +2.5V, with VREFCOM connected to AVSS (which is shorted to DGND).
Anyway, my routine now miraclely works. What I did was, I switched the registers writing order from register 15 to 0.. i.e.
Instead of:
for (i=0; i<15; i++)...
I do this:
for (i=15; i>=0; i--)...
Can someone explain why is that so? This does not seem to be a documented feature... or I overlooked it?
Hello K H,
Your previous description mentioned that you were not able to obtain 1mA out of the device and the results were fluctuating between zero and full-scale; which may be related to the internal reference not being turn on. On the post above, you have mentioned that you have measured 2.5V from the VREFOUT pin, however, the internal reference of the device is 2.048V.
Can you please post a schematic? The VREFOUT pin requires a bypass capacitor between 1uF to 47uF. The internal reference should measure 2.048V.
Can you post an oscilloscope plots of the SPI connections while reading the conversion results, and while writing the registers? (SCLK, CS, DIN, DOUT, DRDY)
Hello Luis,
Here is the re-make version:
Regarding the internal reference voltage of 2.5V, I am puzzled too. FYI, the system is designed for 3-wire RTD, which uses IDAC, and according to the document http://www.ti.com/lit/an/sbaa180/sbaa180.pdf, page 3:
"The internal reference must be turned on for the IDAC to function, even though an external reference channel is used."
Hence, I have turned on the internal reference (VREFCON=01) and selected REF1 input pair (REFSELT=01). I am not sure, in this case, whether it uses internal or external reference voltage. I am just blindly following the instruction given.
UPDATE: I have added a capacitor of 2.2uF accross VREFOUT and VREFCOM as per your suggestion. It now reads 2.048V, with that I am getting a much more sensible and stable output, although I am still left with the question of why it works by reversing the registers writing order.
Thanks for the help, much appreciated.