Evening
I have set the interrupt time to 25ms and checked via a oscilloscope. the reading of the receiver pulse works well, and the interrupt works when a pulse is missing, but i still get stuck in the interrupt.
#define ledPin 13
#define RxThro 3
unsigned long Time1 = 0;
unsigned long Time2 = 0;
unsigned long pulse1 = 0;
volatile boolean failSafe = false;
int FST = 15000;
boolean toggle = false;
void setup()
{
Serial.begin(115200);
pinMode(13, OUTPUT);
pinMode(ledPin, OUTPUT);// initialize timer1
pinMode(RxThro, INPUT);
noInterrupts(); // disable all interrupts
TCCR1A = 0;
TCCR1B = 0;
TCNT1 = FST; // preload timer 65536-16MHz/256/2Hz
//TCCR1B |= (1 << CS12); //
TCCR1B |= (1 << CS11);
//TCCR1B |= (1 << CS10);
TIMSK1 |= (1 << TOIE1); // enable timer overflow interrupt
interrupts(); // enable all interrupts
}
void doCalcs()
{
if (failSafe == true)
{
pulse1 = 900;
}
else
{
TCNT1 = FST; //reset the failsafe timer
pulse1 = Time2 - Time1;
}
}
void getInputs()
{
while ((digitalRead(RxThro) == LOW)||(failSafe == true))
{
}
Time1 = micros();
while ((digitalRead(RxThro) == HIGH)||(failSafe == true))
{
}
Time2 = micros();
}
ISR(TIMER1_OVF_vect) // interrupt service routine that wraps a user defined function supplied by attachInterrupt
{
TCNT1 = FST; // preload timer with Fail Safe Time
failSafe = true;
toggle = !toggle;
digitalWrite(13, toggle);
}
void loop()
{
failSafe == false;
getInputs();
doCalcs();
Serial.println(pulse1);
}