unsigned long Htime;
unsigned long Ltime;
unsigned long Ttime;
unsigned long f;
int N;
void setup() {
// put your setup code here, to run once:
cli();
TCNT2 = 0;
TCCR2A = 0;
TCCR2B = 0;
Serial.begin(9600);
pinMode(5,INPUT);
pinMode(3,OUTPUT);
pinMode(11,OUTPUT);
TCCR2A = (1 << COM0A1) | (1 << COM0B1) | (1 << WGM21) | (1 << WGM20);
TCCR2B = (1 << WGM22) | (1 << CS22) | (1 << CS21) | (1 << CS20);
TIMSK2 = (1 << OCIE2A);
}
void loop() {
// put your main code here, to run repeatedly:
Htime = pulseIn(5, HIGH);
Ltime = pulseIn(5, LOW);
Ttime = Htime + Ltime;
f = 1000000 / Ttime;
Serial.println(f);
N = (16000000 / 1024 / f ) - 1;
OCR2A = N;
OCR2B = N/2;
}
Hi this is what i have written. and i need output a square wave with timer, its frequency is measured from input signal in pin 5. After connecting the oscilloscope, i see the problem, there is phase shift between 2 signals. How could i synchronize this 2 signals?(rising edge to rising edge, falling edge to falling edge) Thank u so much for your help!