PIC16F648A interrupts

I have a simple program that runs the (timer2) PWM reliably, scope measurements confirm timing of pulse width and the rate as well. I add a simple 256 location lookup table to change the PW on a cyclic basis. Still OK but not exactly verified with scope on a dynamic basis, tho verified that i get the proper PW at setting of CCPR1L.

Now, here is when i get into trouble; adding an interrupt.

Number one: exactly when is that interrupt hit, at end of the period, or at end of the pulse? (note if CCPR1L=0 there ain't no pulse, at one it is 200nSec and at 255 the low time is 200nSec)?

Number two: exactly what code and what order is required for reset before i kick it back on with BCF PIR1,TMR2IF and BSF INTCON,GIE?

The simulator is of no help (for me). I do know that i better have all instructions execute from reset until i kick on the interrupt (or i am really SOL).


Reply to
Robert Baer
Loading thread data ...

The timer interrupt comes from the timer; it has nothing to do with the PWM. It happens when the timer rolls over to 0, which is a function of the timer's period register (PR2).

I'm not sure what you man by that. Do you mean in your interrupt handler? All you have to do is clear TMR2IF. You should not manipulate GIE in your interrupt handler.

Reply to
John Temples

Am i confused! To set up the PWM and "tie" it to the output, I need to use timer 2 (and cannot use any other). PR2 sets the PWM period; no other way i know of. AFAIK that sets the timer 2 which then needs PIR1,TMR2IF and BSF INTCON,GIE to enable the interrupt.

Is there any detailed explanation of this stuff?

Reply to
Robert Baer

Hi Robert,

Am 19.11.2015 um 05:47 schrieb Robert Baer:

Exactly, only TMR2 is used here.

The TMR2 prescaler can be set up via register T2CON.

You need to set TMR2IE, PEIE and GIE to 1.

The processors datasheet has all the infos. Look at the block diagrams.

Cheers, Wolfgang

From-address is spam trap 
Use: wolfgang (dot) mahringer (at) sbg (dot) at
Reply to
Wolfgang Mahringer

TMR2IF means the interrupt has occurred. To enable the interrupt, you have to set TMR2IE, PEIE, and GIE.

Reply to
John Temples


Reply to
Robert Baer

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.