Very good with everyone. My problem is how to synchronize a pwm with registers to an external interrupt using switch mode. I would like that every time the interrupt occurs in int0 the pwm is started according to the duty cycle. I am using arduino uno. and 60hz frequency
1-. I would like it to be as follows as shown in sync
2-.This is the result that shows me the pwm signal is out of sync.
#define f 60
unsigned int conv = 0;
unsigned int maximo = 0;
volatile boolean zero_cross=0;// indica cruce cero
int value = 0;
void setup() {
attachInterrupt(0, zero_cross_detect, RISING);
pinMode(9, OUTPUT);
pinMode(4, OUTPUT);
cli();
TCCR1A = 0B10000000;
TCCR1B = 0B00010001;
//maximo = (16e6/(2*f))-1; //
maximo = 65535; // 60 hz
// ICR1 = maximo;
ICR1 = maximo;
//OCR1A = maximo >> 1;
OCR1A = maximo >> 1;
TIMSK1 = 0B00100000;
sei();
}
void loop() {
digitalWrite(4, HIGH);
delay(10);
digitalWrite(4, LOW);
delay(10);
ISR (TIMER1_CAPT_vect)
{
conv = analogRead(A0);
conv = map(conv,0,1023,0,maximo);
// conv = (6000*65535)/8500;
OCR1A = conv;
//zero_cross=false;
}
void zero_cross_detect() {
zero_cross = true; //señal de cruce cero

