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.

ADC SS3 not writing to the ss3 fifo after a ss3 fifo read

With the below code I have set the tiva tm4c123 launchpad SS3 to sample ADC1 continuously. What I really would like to do have the ADC1 sample continuously and read the latest sample. This is not possible as the SS3 fifo gets full and doesn't write anymore. With the function below, I am trying to read the fifo in a loop to get the highest value. before I enter the loop I am trying to read the fifo to let the fifo write the latest value into it but it doesn't seem to do it. For testing, I hook up PE2 to gnd, run the routine, then hook up PE2 to 3.3v and repeat. It seems that the loop has to run to clear the fifo out so it will write. So I am always a loop behind.

    // setup adc 1
  ADC1_ACTSS_R =  0x00000008; // enable sample sequencer 3
  ADC1_SSCTL3_R = 0x00000002; //  sample sequencer 3 ends on first sample
  ADC1_EMUX_R =   0x0000F000; //sample sequencer always samples
  ADC1_SSMUX3_R = 0x11111111; // set sample sequencer 3 to sample A1 in all of the mux fields
  ADC1_DCCTL3_R = 0x00000000; // says that VDDA is the adc voltage ref, no dither
  ADC1_PSSI_R = 0x08; // begin sampling on sample seq 3
  ADC1_PC_R = 0x07; // set adc to 1msps
  ADC0_SSPRI_R = 0x00000123; // ss3 is the highest priority

 void peak_detect_inc(float ad_lsb_voltage, int mux_channel) {  
   Serial.println(); // insert a line to seperate text
   set_multiplexer(mux_channel);
   //current_ad_read[mux_channel] = analogRead(A1);
   //float peak_voltage = analogRead(A1);
  //ADC1_OSTAT_R = 0x08;
  //ADC1_USTAT_R = 0x08;
 
  Serial.println();
  volatile int peak_voltage_ad = ADC1_SSFIFO3_R; // sample once at start of movement
  peak_voltage_ad = ADC1_SSFIFO3_R; // trying to read the fifo so it will accept the latest writes
   peak_voltage_ad = ADC1_SSFIFO3_R; // trying to read the fifo so it will accept the latest writes
    peak_voltage_ad = ADC1_SSFIFO3_R; // trying to read the fifo so it will accept the latest writes
     peak_voltage_ad = ADC1_SSFIFO3_R; // trying to read the fifo so it will accept the latest writes
   Serial.print("ADC1_SSFIFO3_R = ");
   Serial.println(peak_voltage_ad);
   ADC1_OSTAT_R = 0x08;
  ADC1_USTAT_R = 0x08;
  reg = ADC1_OSTAT_R; //fifo oveflow status
  Serial.print("ADC1_OSTAT_R = ");
  Serial.println(reg);
 
  reg = ADC1_USTAT_R; //fifo oveflow status
  Serial.print("ADC1_USTAT_R = ");
  Serial.println(reg);
 
  reg = ADC1_SSFSTAT3_R;
  Serial.print("ADC1_SSFSTAT3_R = ");
  Serial.println(reg);
   
 
   for(i=1; i < 50; i++) {   // loop to read the latest value
     //float temp = analogRead(A1);
     float temp = ADC1_SSFIFO3_R; //
     if (temp > peak_voltage_ad) { // if voltage increases store it
     peak_voltage_ad = temp;
     }
   }  
   float peak_voltage = peak_voltage_ad * ad_lsb_voltage;
   Serial.print ("  fixed_ad_read mux_channel ");
   Serial.print (mux_channel);
   Serial.print (" = ");
   Serial.println(peak_voltage, 6);

 }
 

this is the serial monitor output trying to read

//pe2 = 3.3v

ADC1_SSFIFO3_R = 0 // this should read 4084

ADC1_OSTAT_R = 8

ADC1_USTAT_R = 0

ADC1_SSFSTAT3_R = 4096

fixed_ad_read mux_channel 1 = 3.269202

//trying to read pe2= gnd

ADC1_SSFIFO3_R = 4084 // this should read 0

ADC1_OSTAT_R = 8

ADC1_USTAT_R = 0

ADC1_SSFSTAT3_R = 4096

fixed_ad_read mux_channel 1 = 3.260420

 

  • Hi,

    It is normal to have problems - mainly due to timings - while you set the ADC to run continuously, which means at 1Ms/s, the rest of your code - i.e. all serial.print takes enormous time to execute, comparing with 1 microsecond for ADC, so you may have different results. 

    Also, take into account the temperature is generally a very slow process, so sampling at around 1 second will be enough - it is wise to use a timer to trigger the ADC at slower rates. Doing so you will have enough time to serial.print.

    But there are other things you must consider: read the errata sheet http://www.ti.com/lit/er/spmz849b/spmz849b.pdf, and look for ADC#09 problem/workaround.

    Try to use driverlib functions….

    Petrei