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.

TMR1 With 12F675

Status
Not open for further replies.

Suraj143

Active Member
What I need is I need to use internal RC OSC (4Mhz) & use 32.768xtal to feed TMR1 input to make a RTC.

Can this be done ?I'm doubt where to put 32.768Xtal?
 
Just connect your crystal between pins 2 and 5 with two capacitors of 68-100pF from each pin to ground.

Mike.
 
This is what I need to do,

Internal Time must run no need to display.
I need to toggle a relay in some time intervals on each day.
I need to do a very low power design.

Whats the perfect way of doing?
 
Last edited:
Yes, you are correct, the crystal goes between pins 4 and 5.

From the data sheet,
5.5 Timer1 Oscillator
A crystal oscillator circuit is built-in between pins OSC1
(input) and OSC2 (amplifier output). It is enabled by
setting control bit T1OSCEN (T1CON<3>). The
oscillator is a low power oscillator rated up to 37 kHz. It
will continue to run during SLEEP. It is primarily
intended for a 32 kHz crystal. Table 9-2 shows the
capacitor selection for the Timer1 oscillator.
The Timer1 oscillator is shared with the system LP
oscillator. Thus, Timer1 can use this mode only when
the system clock is derived from the internal oscillator.
As with the system LP oscillator, the user must provide
a software time delay to ensure proper oscillator
start-up.
While enabled, TRISIO4 and TRISIO5 are set. GP4
and GP5 read ‘0’ and TRISIO4 and TRISIO5 are read
‘1’.

So, you can use the sleep instruction to reduce power between second interrupts. The 16F88 data sheet has example code to make a RTC with timer 1.
Code:
RTCinit		banksel	TMR1H
		movlw	0x80		; Preload TMR1 register pair
		movwf	TMR1H		; for 1 second overflow
		clrf	TMR1L
		movlw	b’00001111’	; Configure for external clock,
		movwf	T1CON		; Asynchronous operation, external oscillator
		clrf	secs		; Initialize timekeeping registers
		clrf	mins
		movlw	.12
		movwf	hours
		banksel	PIE1
		bsf	PIE1,TMR1IE	; Enable Timer1 interrupt
		return
RTCisr		banksel	TMR1H
		bsf	TMR1H,7		; Preload for 1 sec overflow
		bcf	PIR1,TMR1IF	; Clear interrupt flag
		incf	secs,F		; Increment seconds
		movf	secs, w
		sublw	.60
		btfss	STATUS,Z	; 60 seconds elapsed?
		return			; No, done
		clrf	seconds		; Clear seconds
		incf	mins,f		; Increment minutes
		movf	mins, w
		sublw	.60
		btfss	STATUS,Z	; 60 seconds elapsed?
		return			; No, done
		clrf	mins		; Clear minutes
		incf	hours,f		; Increment hours
		movf	hours, w
		sublw	.24
		btfss	STATUS,Z	; 24 hours elapsed?
		return			; No, done
		clrf	hours		; Clear hours
		return			;

Mike.
 
Status
Not open for further replies.

Latest threads

Back
Top