My question is: how can I use an ISR and store the data I get from my analog inputs into an array for easier data analysis.
More specifically, I want to collect my data using an ISR function (internal timer interrupt), then store the collected data into an array. This way I can analyze the data more easily.
I have posted the code below. I have posted code showing how I implemented my ISR without storing the data into an array. I was wondering I anyone could help me out with this (how to store that data into an array). Thank you.
const int A0_pin = PC0;
const int A1_pin = PC1;
const uint16_t t1_load = 0;
const uint16_t t1_comp = 3173;
float count = 0;
float num = 0;
void setup() {
//Set A0 and A1 pins as inputs
DDRC &= ~(1 << A0_pin);
DDRC &= ~(1 << A1_pin);
//Reset Timer1 Control Reg A
TCCR1A = 0;
//Set CTC mode
TCCR1B &= ~(1 << WGM13);
TCCR1B |= (1 << WGM12);
//Set to prescaler of 256
TCCR1B |= (1 << CS12);
TCCR1B &= ~(1 << CS11);
TCCR1B &= ~(1 << CS10);
//Reset Timer1 and set compare value
TCNT1 = t1_load;
OCR1A = t1_comp;
//Enable Timer1 compare interrupt
TIMSK1 = (1 << OCIE1A);
//Enable global interrupt
sei();
Serial.begin(9600);
Serial.println("CLEARDATA"); //clears up any data left from previous projects
Serial.println("LABEL,TIME,TIMER,AVG,GAUGE0, GUAGE1"); //always write LABEL, so excel knows the next things will be the names of the columns
Serial.println("RESETTIMER"); //resets timer to 0
}
void loop() {
}
ISR(TIMER1_COMPA_vect) {
TCNT1 = t1_load;
float Gauge0 = analogRead(A0_pin);
float Gauge1 = analogRead(A1_pin); //44
//conversion of read data, to voltage range (0-100 percentVolts)
float gauge0 = Gauge0 * (100.0 / 1023.0);
float gauge1 = Gauge1 * (100.0 / 1023.0);
float add = gauge0 + gauge1;
float AVG = ((gauge0 + gauge1) / 2);
Serial.print("DATA,TIME,TIMER,");
Serial.print(add);
Serial.print(",");
Serial.print(gauge0);
Serial.print(",");
Serial.println(gauge1);
}
In the code, I want to store the gauge1
and the gauge0
values into an array essentially.
Serial.print()
in the interrupt routine is introducing a significant performance penalty, especially since you've set the communication speed to only 9600 baud.