My code, which is using software PWM generated by Timer1, freq is 41kHz, CPU using external 14.7MHz clock. Only Timer1 using interrupt, nowhere disable global interrupt.
I set the PWM pulse width with a fixed value (here are 62%duty).
If my mainloop code is simple, the PWM generated stable (max positive pulse and min positive pulse is 80ns different, max negative pulse and min negative pulse is 83ns different). But if mainloop code is longer (with some SPI read, ADC read, all polling), the PWM generated is not stable (max positive and min positive is 333ns different, max negative and min negative is 500ns different).
My question is, why the interrupt time (timer1 interrupts, which used to generate PWM wave) is affected by none interrupt code (mainloop code)?
If you have any idea, please share. Thank you.