Hello all,
I try to build a RPM meters that work simultaneous with 2 interrupts. the first interrupt by using IR sensor and the other one will be 5V pulse after a voltage divider that I made with 40K and 10K resistors.
the frequency that I want to measure is fast, about 5msec average time between 2 interrupts.
I'm sure the the IR sensor works well and I believe that the other interrupt is ok, I checked with DVM and make sure that the voltage is fine.
by unknown reason for me, the Serial Monitor after about 15 second since start is collapse, the Arduino should handle this speed.
It is important to my project to get the specific accurate time of each interrupt, this is the reason that I print it and use micros function, the numbers 1 and 2 are just to distinguish the interrupts, maybe there are syntex errors, this is because I write it from other computer without upload it to the Arduino.
the code is attach , I will be grateful if you can help me solve the problem.
thank you,
Idan
const byte pin2 = 2;
const byte pin3 = 3 ;
int time1 = 0;
void setup()
{
Serial.begin(9600);
attachInterrupt(digitalPinToInterrupt(pin2), isr1, RISING);
attachInterrupt(digitalPinToInterrupt(pin3), isr2, RISING);
}
void isr1()
{
detachInterrupt(digitalPinToInterrupt(pin2));//to avoid a new interrupt while the function is running
detachInterrupt(digitalPinToInterrupt(pin3));//to avoid a new interrupt while the function is running
time1 = micros();
Serial.println(time1);
Serial.println(" 1\n");
}
void isr2()
{
detachInterrupt(digitalPinToInterrupt(pin3));//to avoid a new interrupt while the function is running
detachInterrupt(digitalPinToInterrupt(pin2));//to avoid a new interrupt while the function is running
time1 = micros();
Serial.println(time1);
Serial.println(" 2\n");
}
void loop(){
attachInterrupt(digitalPinToInterrupt(pin2), isr1, RISING);
attachInterrupt(digitalPinToInterrupt(pin3), isr2, RISING);
}