PDA

View Full Version : Accurate clock using 12C508



srob
- 19th September 2007, 09:16
I need to build a circuit that accurately toggles two outputs (1 high, 1 low) every minute. My initial idea was to use the 1Hz output from a DS1307 RTC, and counting to 60.

However, I thought a neater idea was to run the 12C508 from either a 32.768KHz or 4.9152MHz Crystal, and use the program counter to determine the timing.

Is this feasable, and if so can I do it in PBP, or how do I do it in assembly?

ronsimpson
- 19th September 2007, 13:56
There are hounds of ways to build this.
Use 12F510 or any of the little 10Fxxx parts.
Use the 32768 watch crystal.
In assembly, build the code to toggle the a out put pin. (10 instructions or less) Then build a kill time loop that takes (32768 * 60 – 10) instructions.
OR
In PBP use the pause instruction.
OR
Set up timer0 and prescaller to role over every 4 seconds. (Fosc/4)/128/256) Every 15 of those toggle the output. You software is looking for timer role over and counts to 15.
OR
?

Jerson
- 19th September 2007, 15:15
There are hounds of ways to build this.
Use 12F510 or any of the little 10Fxxx parts.
Use the 32768 watch crystal.
In assembly, build the code to toggle the a out put pin. (10 instructions or less) Then build a kill time loop that takes (32768 * 60 – 10) instructions.
OR
In PBP use the pause instruction.
OR
Set up timer0 and prescaller to role over every 4 seconds. (Fosc/4)/128/256) Every 15 of those toggle the output. You software is looking for timer role over and counts to 15.
OR
?
search the www for ideas from Roman Black
http://www.romanblack.com/one_sec.htm

srob
- 28th September 2007, 09:19
In the end I used the TMR0 timer and wrote the program in assembly (my first attempt at assembly on a PIC!). Using a 32K768Hz crystal, I set the prescalers to 1/256 to give 32Hz, and then counted to 1 second sixty times!

OPTION_REG=%00000111

TRISIO=0

cnt var byte $0F system

ASM

CLRF GPIO
CLRF STATUS
CLRF cnt ;clear registers
CLRF TMR0
LOOP BTFSS TMR0,5 ;count to 1 second
GOTO LOOP
CLRF TMR0
INCF cnt,W
MOVWF cnt
CLRF GPIO ;switch off coil
XORLW 60 ;count to 1 minute
BTFSS STATUS,Z
GOTO LOOP
CLRF cnt ;clear counter
CLRF STATUS
BSF GPIO,0 ;turn on coil+
LOOP1 BTFSS TMR0,5 ;count to 1 second
GOTO LOOP1
CLRF TMR0
INCF cnt,W
MOVWF cnt
CLRF GPIO ;switch off coil
XORLW 60 ;count to 1 minute
BTFSS STATUS,Z
GOTO LOOP1
CLRF cnt ;clear counter
CLRF STATUS
BSF GPIO,1 ;turn on coil-
GOTO LOOP

ENDASM