S Suraj143 Active Member Nov 15, 2007 #1 Hi I have setup TMR2 in the beginning of the program.Now I need to reset TMR2 in the middle of the program by pressing a button. what i want to know is do I need to write all this lines including PR2 register,pre scaler etc.. or only bsf INTCON,PEIE is enough for reset the TMR2? Code: movlw .249 movwf PR2 bsf INTCON,PEIE bsf INTCON,GIE
Hi I have setup TMR2 in the beginning of the program.Now I need to reset TMR2 in the middle of the program by pressing a button. what i want to know is do I need to write all this lines including PR2 register,pre scaler etc.. or only bsf INTCON,PEIE is enough for reset the TMR2? Code: movlw .249 movwf PR2 bsf INTCON,PEIE bsf INTCON,GIE
P Pommie Well-Known Member Most Helpful Member Nov 15, 2007 #2 Just turn it off with bcf T2CON,TMR2ON. Mike.
S Suraj143 Active Member Nov 15, 2007 #3 Oh I see its very simple.Ok I'll turn that TMR2ON bit OFF & ON to make it reset. Thanks mike.
geko Active Member Nov 16, 2007 #4 Oh I see its very simple.Ok I'll turn that TMR2ON bit OFF & ON to make it reset. Click to expand... Turning the timer off and on won't reset it, it will just stop it with what ever value is in it. Since it's an 8 bit timer you can just use CLRF TMR2 without stopping it which will clear both the pre and post scalers at the same time.
Oh I see its very simple.Ok I'll turn that TMR2ON bit OFF & ON to make it reset. Click to expand... Turning the timer off and on won't reset it, it will just stop it with what ever value is in it. Since it's an 8 bit timer you can just use CLRF TMR2 without stopping it which will clear both the pre and post scalers at the same time.
S Suraj143 Active Member Nov 16, 2007 #5 geko said: Since it's an 8 bit timer you can just use CLRF TMR2 without stopping it which will clear both the pre and post scalers at the same time. Click to expand... OMG then I have to setup all PR2 & prescaler lines as well after clearing TMR2.
geko said: Since it's an 8 bit timer you can just use CLRF TMR2 without stopping it which will clear both the pre and post scalers at the same time. Click to expand... OMG then I have to setup all PR2 & prescaler lines as well after clearing TMR2.
geko Active Member Nov 16, 2007 #6 No, it's not that bad. The pre and postscaler ratios aren't changed neither is the value you've already loaded into PR2. The pre and post scalers are counters themselves. Writing to TMR2 (any value) sets these back to zero automatically. It's all in the datasheet by the way.
No, it's not that bad. The pre and postscaler ratios aren't changed neither is the value you've already loaded into PR2. The pre and post scalers are counters themselves. Writing to TMR2 (any value) sets these back to zero automatically. It's all in the datasheet by the way.
S Suraj143 Active Member Nov 16, 2007 #7 geko said: The pre and postscaler ratios aren't changed neither is the value you've already loaded into PR2. Click to expand... I haven't heard this before. The pre and post scalers are counters themselves. Writing to TMR2 (any value) sets these back to zero automatically. Click to expand... OK I'll add clrf TMR2 after pressing the button in the coding.
geko said: The pre and postscaler ratios aren't changed neither is the value you've already loaded into PR2. Click to expand... I haven't heard this before. The pre and post scalers are counters themselves. Writing to TMR2 (any value) sets these back to zero automatically. Click to expand... OK I'll add clrf TMR2 after pressing the button in the coding.