hi
i am trying to sample from to channel of the analog input of the arduino to sensor and i need the time of measuring of the sample.
from some reason that i dont understand the time the i get from the milliys function is 101 for both channel
i will be glad if someone can help me fixing it please?
this is my code:
#include <math.h>
#define Piezo1 A0
#define Piezo2 A1
unsigned long start_time=0;
unsigned long stop_time_CH1=0;
unsigned long stop_time_CH0=0;
float Piezo_arr[2];
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
pinMode(Piezo1,INPUT);
pinMode(Piezo2,INPUT);
analogReference(DEFAULT);
// TIMER 1 for interrupt frequency 520.0039000292502 Hz:
cli(); // stop interrupts
TCCR1A = 0; // set entire TCCR1A register to 0
TCCR1B = 0; // same for TCCR1B
TCNT1 = 0; // initialize counter value to 0
// set compare match register for 520.0039000292502 Hz increments
OCR1A = 30768; // = 16000000 / (1 * 520.0039000292502) - 1 (must be <65536)
// turn on CTC mode
TCCR1B |= (1 << WGM12);
// Set CS12, CS11 and CS10 bits for 1 prescaler
TCCR1B |= (0 << CS12) | (0 << CS11) | (1 << CS10);
// enable timer compare interrupt
TIMSK1 |= (1 << OCIE1A);
sei(); // allow interrupts
start_time=millis();
}
ISR(TIMER1_COMPA_vect){
Piezo_arr[1]=((3.3/1023.0)*((float)analogRead(Piezo1)))-1.65;
stop_time_CH0=(millis()-start_time);
Piezo_arr[2]=((3.3/1023.0)*((float)analogRead(Piezo2)))-1.65;
stop_time_CH1=(millis()-start_time);
Serial.print(stop_time_CH0);
Serial.print(',');
Serial.print(Piezo_arr[1]);
Serial.print(',');
Serial.print(stop_time_CH1);
Serial.print(',');
Serial.print(Piezo_arr[2]);
Serial.println();
}
void loop() {
}