I'm having trouble getting a TMR2 interrupt.The code below outputs a 240Hz / 50% PWM from Portb.3 The intention is to use the TMR2 IRQ as a signal to read external pots (via a 4051 and TLC549) that are adjusted to modify the frequency / duty cycle. A match is occuring between TMR2 and PR2 as the PWM maintains itself. I've used Timer0 as an alternate source and the ISR does get entered as expected The concept is fairly similar to Olin's HAL project, in that during the ISR a new value may be loaded into CCPR1L. However, as Olin's writing style is quite different to mine I may have missed something with the IRQ set-up. Microchip seem not to have any examples of TMR2 IRQ code (they poll TMR2IF), so I'm looking for help TIA =================================================== list p=16F628 #include led equ 0x07 __config _intrc_osc_noclkout & _wdt_off & _pwrte_on & _lvp_off & _boden_off org 0x00 goto entry org 0x04 goto irq entry clrf porta movlw 0x07 movwf cmcon clrf status ;set rp0, rp1 = 0 = Bank0 bsf status,rp0 ;tris registers in bank1 bcf status,rp1 movlw b'00000000' ;oooo oooo , Porta all o/p movwf trisa movlw b'00100000' ;ooio oooo all o/p except Serial Data movwf trisb movlw 0x86 ;TMR0 pre-scaler= 128 =30Hz IRQ movwf option_reg bcf status,rp0 bcf status,rp1 clrf porta ;4051 A = B = C = 0 clrf ashad ;clear shadow movlw b'01010000' ;TLC549 Clock high, CS high movwf portb clrf fsr clrf ccp1con ;CCP Module off, set up PWM clrf tmr2 movlw b'11111100' ;TMR2 - PR2 match value movwf pr2 movlw b'01111111' ;duty cycle MSBs movwf ccpr1l clrf intcon bsf status,rp0 clrf pie1 bcf status,rp0 clrf pir1 movlw b'00011100' ;DC LSBs <5:4>, 11xx = PWM mode movwf ccp1con bcf t2con,t2ckps0 ;PS 00 1: 1 ; 01 1:4 selected bsf t2con,t2ckps1 ; 1x 1:16 nop bsf t2con,tmr2on ;Timer2 enabled bsf intcon,peie ;enable peripheral IRQs bsf pie1,tmr2ie ;enable TMR2 IRQs bcf pir1,tmr2if ;reset TMR2 IRQ flag ; bsf intcon,t0ie bsf intcon,gie ;enable IRQs loop goto loop ;============================= ; ISR ;============================= irq bcf pir1,tmr2if ;reset IRQ source flags bcf intcon,t0if bsf portb,led ;ISR activity indicator nop bcf portb,led retfie ;temporary return movwf wtemp swapf status,w movwf stemp call readadc ;get pot value movf dbuff,w movwf ccpr1l ;into PWM DC register swapf stemp,w movwf status swapf wtemp,f swapf wtemp,w retfie -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu