Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to make a 1 minute counter using TMR1 in PIC16F628A?

Status
Not open for further replies.

emkay

Junior Member level 2
Joined
Feb 16, 2005
Messages
21
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,281
Activity points
1,494
dear all.

how to have a counter that will count for 1 minute...by using TMR1 in pic16f628a
i reer to use an interrupt

previously i use delay a minute from piclist code generator.

here the code fo 1 minute delay

Code:
; Delay = 60 seconds
; Clock frequency = 4 MHz

; Actual delay = 60 seconds = 60000000 cycles
; Error = 0 %

	cblock
	d1
	d2
	d3
	endc

Delay1minute
			;59999994 cycles
	movlw	0x23
	movwf	d1
	movlw	0xCB
	movwf	d2
	movlw	0x83
	movwf	d3
Delay1minute_0
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	$+2
	decfsz	d3, f
	goto	Delay1minute_0

			;2 cycles
	goto	$+1

			;4 cycles (including call)
	return

how do i modify thsi code so that it can be use for TMR1

thanks in advance
 

1 minute count

Locate the register of the TMR1, better yet use C language, will save lots of trouble.
 

Re: 1 minute count

Hi !

Using TMR1 and the PIC main oscillator at 4MHz is impossible to have 60s counting, because the maximum prescaler is 8 (clock division). At 4MHz and prescaler = 8, TMR1 will overflow every 524288 us or aproximattely every 0,5s, as follows:

65536 x 1/fosc/4 x 8 prescaler

65536 x 1us x 8 = 524288 us

If you use a 32768Hz in the TMR1 external oscillator, you can obtain 16 s counting (steps of 244.141 us)

You can configure TMR1 (with 32768 Hz xtal) to overflow every 15 s, make the interrupt and increment a variable. When such variable reaches 4, you have your 60 s timing (and clear the variable after this).

Another idea is using a low frequency clock feeding the TMR1 input, lets say 1000Hz. This way you get 60 s when TMR1 reachs 60000.
 

Re: 1 minute count

rkodaira said:
If you use a 32768Hz in the TMR1 external oscillator, you can obtain 16 s counting (steps of 244.141 us)

.
I have a question....
what will be the value of the prescaler (y)???
where we have 15s= y*(4/fosc)*256
if fosc = 32768Hz....this will give y=480!!!!
 

Re: 1 minute count

Salam,

If u want an accurate delay for any application do as rkodaira said, but if u intend to make a clock use 4MHz Xtal and /8 prescaler then u can subtract the error every while.

Hope that this this is what u r asking for and that i've helped u
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top