Recommendation for stopping PWM signal
Looking for a recommendation for generating a discrete number of pulses from PWM, for the example below i setup timer 1 to generate PWM and timer 2 with input capture interrupt to count the pulses, I did this with both rising and falling edge and both resulted with slight errors. I attempted to create a 3-pulse burst, but as can be seen it doesn't quite work. Any suggestions on how I can implement this better?
After 3 pulses on the interrupt, I stop PWM on channel 1.

Rising Edge mode Tim2 interrupt mode, 3 full pulses generated plus a 4th partial.


Rising Edge mode Tim2 interrupt mode, only 2 full pulses generated.


