the output of the electric generator fed to the op amp output of the square pulse is 50 Hz and 50% duty cycle. on the other hand the arduino I have set is set to generate 100 Hz CTC mode. I want to synchronize the two between arduino and the output of the op amp so that the division of 4 quadrants of high accuracy pulse output from arduino. I think to trigger an arduino timer on pin 2 which is attached from the op amp output as external interrupt, each time> if positive high pulse input then start timer if low input pulse, stop and reset timer.
#define ext_interrupt 2
void setup() {
pinMode(ext_interrupt, INPUT);
pinMode(3, OUTPUT);
pinMode(4, INPUT);
cli();
TCCR1A = 0;
TCCR1B = 0;
TCNT1 = 0;
OCR1A = 2499; //set pin dutty on time
OCR1B = 1249; //set pin dutty off time
TCCR1A |= (1<<COM1A1) | (1<<COM1B1);
TCCR1B |= (1<<CS10) |(1<<CS11) | (1<<WGM12);
TIMSK1 |= (1<<OCIE1A) | (1<<OCIE1B);
sei();
}
ISR(TIMER1_COMPA_vect){ //controll OCR1A
if (digitalRead(ext_interrupt, HIGH)){
//how to start timer programaticaly ??
digitalWrite(3,HIGH);
digitalWrite(4,LOW);
}
}
ISR(TIMER1_COMPB_vect){ //controll OCR1B
if (digitalRead(ext_interrupt, HIGH)){
digitalWrite(3,LOW);
digitalWrite(4,HIGH);
//how to reset timer ??
//then reset all parameter back to 0 ??
}
}
void blink() {
state = !state;
}
void loop() {
// put your main code here, to run repeatedly:
}
how can i do this? pls help