This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

ADC1241 - Timing Issues

Other Parts Discussed in Thread: ADS1241

Hi I am using the ADC1241.  I am using it to read 2 thermocouples.  I have 1 main loop in my program.  It does a bunch of stuff and then reads thermocouple 1 and then thermocouple 2.  The problem is it is the outputs are swapped:  it is giving me the TC2 data reading as TC1 temperature and vice versa.  If I comment out the reading of one or the other, then it gives me the correct TC temperature for that specific TC#.

Basically, if I put TC1 in icewater and TC2 in room temperature, the program will tell me

TC1=78°F and TC2=34°F.

Can you help me find what I am doing wrong?

My program flow is this:

int main ()

{

loop_start:

do a bunch of stuff;

read_TC1();          //read thermocouple 1 value

read_TC2();          //read thermocouple 2 value

goto loop_start;

}

//////////Function Descriptions below:

void read_TC1()

{

if (ADC_waiting==0)

{

ADC_channel(4,5);     //change MUX to channel 4 and 5

}

else if ((ADC_waiting==1)&&(ADC_chan=0x45))

{

ADC_check_drdy();   //check the DRDY bit

if (ADC_drdy==0)     //data is ready

{

ADC_val=ADC_read();

}

}

}

void ADC_channel(uint8_t Pchan, uint8_t Nchan)

{

uint8_t MUX_chan;

MUX_chan=((Pchan<<4)&(0xF0))|((Nchan)&(0x0F));    //combine the two channels into 1 byte

If (ADC_waiting==0)

{

spi_init_ADC();
DELAY_US(100);
//Update MUX register
spi_ss(1);
spi_write(0x51); //WREG - write to MUX register
spi_write(0x00); //only write to 1 register (no additional registers, see pg. 19 for WREG command)
spi_write(MUX_chan); //MSbits select positive channel, LSbits select negative channel
spi_ss(31);

DELAY_US(100);

ADC_waiting=1;                    //now we ARE waiting on a conversion to complete because one just started
ADC_chan=MUX_chan;

//--------------------------------------
//DSYNC, see pg. 14 of ADS1241 datasheet
//--------------------------------------
spi_ss(1);
spi_write(0xFC); //DSYNC command - see pg. 18 and 14
spi_ss(31);
//--------------------------------------

//dummy write
//See pg. 14 of datasheet (DSYNC OPERATION section)
//after DSYNC command, it stays in reset until next SCLK pulse
//So I believe this dummy read will get it out of reset
spi_ss(1);
spi_write(0x00); //NOP command (NOP) - see pg. 18
spi_ss(31);
spi_init(); //go back to regular SPI

}

}

  • Signalflow,


    The first thing that I would try is to throw away the first read add an extra read/check DRDY for each thermocouple read cycle.

    The concern is that if you change the mux value and the DRDY comes immediately, you'd still be reading data that is mostly from the first mux value. If you throw that data away, and you read the next data, the second data will be an ADC conversion of the new mux value. As an example, if you changed the mux directly in the middle of the data period you would get a data reading in between what would be read for the first and second channels. In this particular ADC, the digital filter/read cycle does not restart with a change in the mux setting.

    In short, try a dummy read, let the DRDY go high again, and then get the next data after the DRDY returns low.


    Joseph Wu