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.

pic 16f684 clock question

Status
Not open for further replies.

jkmadsci

New Member
I am trying to make a 16f684 clock program. I plan on using batteries.
If i use the int rc osc 31k hz clock, will it drift according to temperature and voltage. I read the datasheet and it said the external rc clock would drift. I didnt see any info regarding internal rc drift?

I suppose if the 31k osc drifts around too much ill have to use the 125k osc.
 
I'm not familiar with that particular pic but, assuming it's the same as most other pics, to do a clock type program. Run the processor at 4MHz using the internal oscillator and use a 32.768kHz (8000h) Crystal as the external clock for timer 1. You can then use the special events trigger of ccp1 to generate a 1Hz interrupt.

If you use a RC oscillator to generate interrupts then you will have a very inaccurate clock.

To setup Timer1 and CCP1, do:


Code:
		movlw	B'00001111';             enable timer1 
		movwf	T1CON;                     with external clock

		movlw	low(8000h-1);            Lets interupt every second
		movwf	CCPR1L;                    using the special event trigger on timer 1
		movlw	high(8000h-1)
		movwf	CCPR1H
		movlw	B'00001011';              enable special event trigger on CCP1
		movwf	CCP1CON;	

		bsf	STATUS,RP0
		bsf	PIE1,CCP1IE;            enable CCP1 interrupt
		bcf	STATUS,RP0

		movlw	0C0h
		movwf	INTCON;                    enable Peripheral interrupts

And your interrupt would look something like:


Code:
interrupt	movwf	int_work
		swapf	STATUS,W
		movwf	int_status;                  status is nibble swaped
		bcf	STATUS,RP0

		bcf	PIR1,CCP1IF;             reset special event trigger interupt
		incf	Seconds;                   increment seconds as a second has passed
		
		swapf	int_status,W
		movwf	STATUS
		swapf	int_work,F;                swap to file
		swapf	int_work,W;               swap to work
		retfie

HTH

Mike.
 
jkmadsci said:
I am trying to make a 16f684 clock program. I plan on using batteries.
If i use the int rc osc 31k hz clock, will it drift according to temperature and voltage. I read the datasheet and it said the external rc clock would drift. I didnt see any info regarding internal rc drift?

I suppose if the 31k osc drifts around too much ill have to use the 125k osc.

The internal oscillator is ONLY RC, it's far too inaccurate to use as a clock.

If you want clock type accuracy, use an external 32KHz watch cyrstal as Pommie suggests.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top