Happy new year to all!
I have a question about the Pin Change Interrupt Timing.
Proplem:
There is a PWM Singnal on PD7(PCINT23), blue signal on picture.
I would like to generate an interrupt each time on a high level on this pin.
Therefore I'm using the Pin change interrupt.
The Code I'm using for this is as follows:
#include <avr/io.h>
#include <stdlib.h>
#include <avr/interrupt.h>
ISR(PCINT2_vect)
{
PORTD |= (1 << PD5); //PD5 High Red Signal on picture
PORTD &= ~(1 << PD5); //PD5 Low
}
int main(void)
{
PCMSK2 |= (1<<PCINT23);
PCICR |= (1<<PCIE2);
sei();
DDRD &= ~(1 << PD7);
DDRD |= (1 << PD5);
while (1)
{}
}
The AVR is running with 16 MHz (Clock Cycle Time should be 62,5ns )
Interrupt execution time should be 4 clock cycles as datasheet.
But as you can see on the picture the interrupt execution is delayed (sometimes outside the PWM Signal)(red line).
I expexted that the Interrupt should be executed more close to the rising edge of the blue signal.
Do you see something wrong in the code or do you have an idea to solve this problem?
Thank you in advance!
Regards,
Eric