SOLVED ADC stops working at small delays (MCP3464)

Hi everyone,

I have tried debugging for a couple days with no luck, so this question is a cry for help.

I am trying to configure an external ADC (MCP3464 datasheet). The ADC uses SPI communication and I am getting a response from it when I set the delay to 1000ms. If I lower this below 100ms, the ADC does not update and prints the last value stored in the ADC register.

Here is the relevant part of the code, although I have attached the whole file in case you would like to check command bytes etc.

void adcSimple(){

    unsigned char convStatus;
    uint16_t adcData;    
    // chip Select pin LOW to read/write to ADC
    digitalWrite(adcChipSelectPin,LOW); 
    convStatus = SPI.transfer(readConversionData);
    // extracts remaing bytes and append to adcData 16 bit integer (15bits plus sign)
    adcData = SPI.transfer(0);
    adcData <<= 8;
    adcData |= SPI.transfer(0);
    // chip select pin hgih to stop read/write to ADC
    digitalWrite(adcChipSelectPin, HIGH);
    
    // start next conversion
    writeData(&startConversionFastCmd, 1);
    
    Serial.println(adcData);
}


void setup(){
  Serial.begin(115200);
  while (! Serial); 
  spiInit();
  adcInit();
  // set ADC Multiplexer to channel 0 
  writeData(&muxRegisters[0][0], 2);
  delay(1000);
}

void loop(){
  adcSimple();
  delay(1000);
}

type or paste code here

The adcSimple() function reads the ADC register address and appends it to the 16 bit adcData variable.

writeData(&startConversionFastCmd, 1);

The line above then restarts the ADC conversion (not the whole device) which is required to update the ADC register. For some reason this does not update the ADC register when there is insufficient delay in the loop.

  // Check the data ready bit
  if ((convStatus & 0x04) == 0x04)
  {
     Serial.println("ADC not ready!!!");

  }

I have run a test on convStatus, and this shows the ADC is not ready when the delay is short (around 100ms). I just don't understand why it takes so long (1000ms is equivalent to light years when running on 6MHz clock!)

Any suggestions would be greatly appreciated. Maybe someone has had a similar problem before?
Thanks,
Will

I have no experience with such peripherals. In the datasheet it says 'Data Rate' is programmed and from TABLE 5-6 it can be seen the slowest data rate is 12.5Hz, which is 80 milliseconds. Is your sampling rate set?

'Light year' is measure of distance, not time. Just saying.

SOLVED!!! I lowered the oversampling rate (See table 5-6 of datasheet) and thus increased the data rate.

Flashko, you're a legend!

This is good. Wishing success with the project.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.