Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

How to Reset TMR2?

Status
Not open for further replies.

Suraj143

Active Member
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
 
Oh I see its very simple.Ok I'll turn that TMR2ON bit OFF & ON to make it reset.

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.
 
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.

OMG then I have to setup all PR2 & prescaler lines as well after clearing TMR2.:rolleyes:
 
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.
 
geko said:
The pre and postscaler ratios aren't changed neither is the value you've already loaded into PR2.
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.

OK I'll add clrf TMR2 after pressing the button in the coding.
 
Status
Not open for further replies.

Latest threads

Back
Top