Yes, but you still need to keep the reloading code in the interrupt routine otherwise the timer will "freewheel" again.I get a 100Hz output frequency on PORTD.7.
In your code, as the very first thing in the ISR, you are currently overwriting the TMR1 register with the value of a variable called timer.So, once the code gets to "copying" the TMR1 registers and adding the reload value to it you have overwritten it with something else.Code:' PWM calculation and update interrupt (Timer 1) pwmint: ' Timer 1 update TMR1L=timer.lowbyte '<---This is overwriting the TMR1 registers! TMR1H=timer.highbyte
I've just tested the following code here:And it works fine. Pushing the buttons connected to PortB.0 and PortA.4 increases/decreases the reload value for the timer and the interrupt frequency.Code:DEFINE LOADER_USED 1 DEFINE OSC 20 INCLUDE "DT_INTS-18.bas" INCLUDE "ReEnterPBP-18.bas" INCLUDE "IncPID.pbp" TMRCopy VAR WORD TimerReloadValue VAR WORD TimerReloadValue = 63000 ASM INT_LIST macro ; IntSource, Label, Type, ResetFlag? INT_Handler TMR1_INT, _TimezUp, PBP, yes endm INT_CREATE ; Creates the interrupt processor ENDASM @ INT_ENABLE TMR1_INT ; enable Timer 1 interrupts TRISB.0 = 1 ' +button TRISA.4 = 1 ' -button TRISB.3 = 0 ' Output to measure interrupt frequency CMCON = 7 ADCON1 = %00001111 ' No analog inputs. T1CON.0 = 1 ' Start TMR1 Main: If PortB.0 = 0 then TimerReloadValue = TimerReloadValue + 1 LCDOUT $FE,1,#TimerReloadValue ENDIF If PortA.4 = 0 then TimerReloadValue = TimerReloadValue - 1 LCDOUT $FE,1,#TimerReloadValue ENDIF Pause 20 Goto Main ' ---------- Interrupt handler ------------ TimezUp: T1CON.0 = 0 ' Stop TMR1 TMRCopy.HighByte = TMR1H ' Copy value of TMR1 registers TMRCopy.LowByte = TMR1L TMRCopy = TMRCopy + TimerReloadValue ' Add reload value (compensates for overhead) TMR1H = TMRCOPY.HighByte ' And back to TMR1 TMR1L = TMRCopy.LowByte T1CON.0 = 1 ' Restart Timer Toggle PortB.3 @ INT_RETURN
But, again, a change of 1 at the "top" will not result in the same change in interrupt frequency as a change of 1 at the "botton".




Bookmarks