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