--0-1470314119-1081401860=:89293 Content-Type: text/plain; charset=us-ascii Content-Id: Content-Disposition: inline I am using MPLAB 6.50. I could be doing something stupid, but I am having trouble simulating a simple isr that is supposed to happen every 208 cycles. When using the stopwatch, I was getting 209. I simplified the problem in a test project, and the symptoms are the same, TMR0 is losing track of time. Adding a value to TMR0 inhibits counting for 2 cycles right? So I assume that adding 2 to TMR0 doesnt change the net outcome? I wrote a sample program to interupt naturally on TMR0 and the stopwatch says it interupts every 256 cycles -- good. Now if I add 2 to TMR0 during the interupt, it happens every 257 cycles! When I step through the code and watch TMR0, it doesnt increment until the 4th instruction after the add, whereas it should be the 3rd instruction. Has anyone else noticed this problem, or am I missing something? I have attached the test program if anyone cares to give it a try. Thanks, - Ben __________________________________ Do you Yahoo!? Yahoo! Small Business $15K Web Design Giveaway http://promotions.yahoo.com/design_giveaway/ -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details. --0-1470314119-1081401860=:89293 Content-Type: text/plain; name="test.asm" Content-Description: test.asm Content-Disposition: inline; filename="test.asm" LIST P=PIC12F629 RADIX dec INCLUDE "p12f629.inc" __CONFIG _INTRC_OSC_NOCLKOUT & _WDT_OFF CBLOCK 0x20 ; RAM starts at address 20h W_TEMP STATUS_TEMP ENDC org 0 goto init nop nop nop ;------------------- INTERUPT --------------------------- ;as per data sheet MOVWF W_TEMP ;copy W to temp register,could be in either bank SWAPF STATUS,W ;swap status to be saved into W BCF STATUS,RP0 ;change to bank 0 regardless of current bank MOVWF STATUS_TEMP ;save status to bank 0 register ;------------------- ISR --------------------------- isr: btfsc TMR0, 0 ;get rid of the jitters goto $+1 bcf INTCON, T0IF movlw 2 addwf TMR0, f movfw TMR0 movfw TMR0 movfw TMR0 movfw TMR0 ;tmr0 incs during this instruction movfw TMR0 ;tmr0 doesnt inc untill the pc is at this line movfw TMR0 movfw TMR0 ;------------------- END INTERUPT --------------------------- SWAPF STATUS_TEMP,W;swap STATUS_TEMP register into W, ;sets bank to original state MOVWF STATUS ;move W into STATUS register SWAPF W_TEMP,F ;swap W_TEMP SWAPF W_TEMP,W ;swap W_TEMP into W retfie ;------------------- INIT --------------------------- init: bcf STATUS, RP0 ;switch to bank 0 clrf TMR0 ;switch to bank 1 for option register bsf STATUS, RP0 bsf OPTION_REG, PSA ;set prescaler to WDT (1:1 for tmr0) bcf OPTION_REG, T0CS ;timer 0 is a timer ;switch back to bank 0 bcf STATUS, RP0 clrf TMR0 ;start counting 2 instr from now bsf INTCON, T0IE ;enable timer 0 interupts bsf INTCON, GIE ;enable interupts mainloop: nop ;jitter simulator nop nop goto mainloop end -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details. --0-1470314119-1081401860=:89293--