Electronic – Using both PWM and Timer2 interrupt in PIC18F25k50

picpwmtimer

Background

I'm working on lead-acid battery charger and experimenting with battery desulfation.

I want to draw current vs time graph on graphic LCD and see:

  • how high current spikes I have
  • measure RMS of my current if possible

I expect something like this on ADC input:

enter image description here

Question

Can I use Timer2 interrupt when PWM is already using Timer2 in PIC18F25k50?

I want to use that interrupt to "synchronise" my ADC measurements with PWM and catch current spike.

Best Answer

  1. I can see no reason why not. It's quite common to want to synchronize with the PWM, and the interrupt from the timer is most commonly used.
  2. That's a little more tricky. You can use the Timer 2 interrupt to trigger a sample, but you want to do a block sample starting at the interrupt time, really, don't you? Unfortunately it doesn't look like that chip has DMA, so it would really be a case of using T2 to start the sampling, but drive the sampling from another timer / interrupt.