EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

PIC16F648A interrupts

Started by Robert Baer November 17, 2015
   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).

   Thanks.
On 2015-11-17, Robert Baer <robertbaer@localnet.com> wrote:
> I have a simple program that runs the (timer2) PWM reliably, scope > measurements confirm timing of pulse width and the rate as well.
> 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)?
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).
> 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?
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.
John Temples wrote:
> On 2015-11-17, Robert Baer<robertbaer@localnet.com> wrote: >> I have a simple program that runs the (timer2) PWM reliably, scope >> measurements confirm timing of pulse width and the rate as well. > >> 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)? > > 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). > >> 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? > > 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. > >
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?
Hi Robert,

Am 19.11.2015 um 05:47 schrieb Robert Baer:
> To set up the PWM and "tie" it to the output, I need to use timer 2 > (and cannot use any other).
Exactly, only TMR2 is used here.
> PR2 sets the PWM period; no other way i know of.
The TMR2 prescaler can be set up via register T2CON.
> AFAIK that sets the > timer 2 which then needs PIR1,TMR2IF and BSF INTCON,GIE to enable the > interrupt.
You need to set TMR2IE, PEIE and GIE to 1.
> > Is there any detailed explanation of this stuff?
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
On 2015-11-19, Robert Baer <robertbaer@localnet.com> wrote:
> John Temples wrote: >> On 2015-11-17, Robert Baer<robertbaer@localnet.com> wrote: >>> I have a simple program that runs the (timer2) PWM reliably, scope >>> measurements confirm timing of pulse width and the rate as well. >> >>> 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)? >> >> 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). >> >>> 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? >> >> 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. >> >> > 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.
TMR2IF means the interrupt has occurred. To enable the interrupt, you have to set TMR2IE, PEIE, and GIE.
Wolfgang Mahringer wrote:
> Hi Robert, > > Am 19.11.2015 um 05:47 schrieb Robert Baer: >> To set up the PWM and "tie" it to the output, I need to use timer 2 >> (and cannot use any other). > > Exactly, only TMR2 is used here. > >> PR2 sets the PWM period; no other way i know of. > > The TMR2 prescaler can be set up via register T2CON. > >> AFAIK that sets the >> timer 2 which then needs PIR1,TMR2IF and BSF INTCON,GIE to enable the >> interrupt. > > You need to set TMR2IE, PEIE and GIE to 1. >> >> Is there any detailed explanation of this stuff? > > The processors datasheet has all the infos. > Look at the block diagrams. > > Cheers, > Wolfgang >
thanks.

The 2024 Embedded Online Conference