sorry for that
this is the code I'm using now:
#include <avr/io.h>
#include <avr/interrupt.h>
void setup() {
// put your setup code here, to run once:
noInterrupts();
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
TCCR2A = _BV(COM2A1) | _BV(COM2B1) | _BV(WGM20);
TCCR2B = _BV(CS22);
OCR2A = 0;
OCR2B = 0;
TCNT2 = 0;
interrupts();
attachInterrupt(digitalPinToInterrupt(2), t1_ISR, RISING); //enable interrupt service routines on pins 2 and 3
attachInterrupt(digitalPinToInterrupt(3), t2_ISR, RISING);
}
volatile unsigned int t1;
volatile unsigned int t2;
volatile unsigned int oldt1 = 0;
volatile unsigned int oldt2 = 0;
void loop() {
// put your main code here, to run repeatedly:
while((t1 != oldt1) && (t2 != oldt2)){
if(t1<t2){
OCR2A = t2-t1; //duty cycle 50%
OCR2B = 0;
}
else if(t2<t1){
OCR2B = t1-t2;
OCR2A = 0;
}
}
oldt1 = t1;
oldt2 = t2;
}
void t1_ISR(){
t1 = TCNT2;
}
void t2_ISR(){
t2 = TCNT2;
}