Other Parts Discussed in Thread: ADS1248
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);
}
}