Erratic ClockI dismantled a cheap quartz clock and took control of its solenoid with quite a surreal effect. It has an erratic second hand, but the hour and minute hands keep good time. I had a little trouble with inductive kick, but I think it's functioning correctly now (currently in final stages of hardware testing). |
; Clock nobble hardware test (c) R Geleit February 2009 ; Version 0.1 ; Clock that has an erratic second hand, but the hour and minute hands keep good time. ; PIC16F84A ; Crystal frequency 3.2768MHz list p=16F84A ; list directive to define processor #include <p16F84A.inc> ; processor specific variable definitions __CONFIG _CP_OFF & _WDT_OFF & _PWRTE_OFF & _XT_OSC RADIX dec ;***** VARIABLE DEFINITIONS mark32 equ 0x0C ; postscaler = 1/100 sec hundths equ 0x0D secs equ 0x0E mins equ 0x0F hours equ 0x10 flags equ 0x11 ticking equ 0 ; tick/tock in progress (bit) tickno equ 0x13 ; current beep in list buztick equ 0x14 ; 1/100 sec postscaler for beep timing newtick equ 0x15 ; time for new tick? ttline equ 0x16 ; 4 or 8 (RA2 or RA3) tikstop equ 0x17 ; 60mS after tick start 0x17 mark50 equ 0x18 ; to wait half a second ;********************************************************************** ORG 0x000 ; processor reset vector goto start init clrf PORTA ; reset in/out clrf PORTB ; bsf STATUS,5 ; select bank 1 movlw 0 ; All output. RA2 RA3 are solenoid movwf TRISA movlw 8 ; RB3 = button movwf TRISB movlw 7+128 ; external timer, max prescale 00000111 (7) +no weak pullups movwf OPTION_REG bcf STATUS,5 ; select bank 0 clrf INTCON ; no interrupts retlw 0 start call init movlw 4 ; tick movwf ttline movlw 0 movwf tickno movwf newtick bcf flags,ticking swait movlw 128 ; stabilise for button subwf TMR0,W btfss STATUS,Z goto swait bwait btfss PORTB,3 ; wait 'till button pressed goto bwait movlw 23 movwf hours movlw 59 movwf mins movlw 30 movwf secs mloop call time ; update file regs with current time call ttover ; time to terminate a ticktock? call nextick ; time for a ticktock? goto mloop time movfw mark32 ; update clock registers subwf TMR0,W btfss STATUS,Z ; 32 ticks of TMR0? return movlw 32 ; reset postscaler addwf mark32,F incf hundths,F incf buztick,F movlw 100 subwf hundths,W btfss STATUS,Z ; 100 hundredths of a second? return clrf hundths ; call tiktok incf secs,F ; then increase seconds movlw 60 subwf secs,W btfss STATUS,Z ; 60 seconds? return clrf secs incf mins,F ; then increase minutes movlw 60 subwf mins,W btfss STATUS,Z ; 60 minutes? return clrf mins incf hours,F ; then increase hours movlw 24 subwf hours,W btfss STATUS,Z ; 24 hours? return clrf hours ; then midnight ; movlw 226 ; -30 seconds adjusts xtal default ; movwf secs call nobble return nextick movfw newtick ; time for ticktock? subwf buztick,W btfss STATUS,Z return incf tickno ; set next ticktock movfw tickno andlw 127 ; 128 ticks in list movwf tickno call nextt addwf buztick,W movwf newtick call tiktok return nextt movfw tickno addwf PCL,F retlw 69 retlw 45 retlw 87 retlw 221 retlw 30 retlw 96 retlw 153 retlw 57 retlw 255 retlw 58 retlw 255 retlw 89 retlw 91 retlw 92 retlw 31 retlw 255 retlw 93 retlw 255 retlw 64 retlw 41 retlw 28 retlw 25 retlw 54 retlw 84 retlw 82 retlw 25 retlw 98 retlw 52 retlw 45 retlw 125 retlw 46 retlw 255 retlw 36 retlw 45 retlw 83 retlw 255 retlw 56 retlw 25 retlw 25 retlw 215 retlw 68 retlw 88 retlw 70 retlw 95 retlw 223 retlw 54 retlw 43 retlw 25 retlw 187 retlw 231 retlw 85 retlw 87 retlw 74 retlw 75 retlw 53 retlw 191 retlw 43 retlw 60 retlw 25 retlw 189 retlw 71 retlw 255 retlw 48 retlw 95 retlw 80 retlw 36 retlw 94 retlw 223 retlw 47 retlw 41 retlw 167 retlw 75 retlw 55 retlw 89 retlw 25 retlw 180 retlw 82 retlw 255 retlw 32 retlw 255 retlw 38 retlw 40 retlw 25 retlw 64 retlw 122 retlw 25 retlw 101 retlw 143 retlw 208 retlw 25 retlw 94 retlw 71 retlw 81 retlw 131 retlw 99 retlw 152 retlw 78 retlw 190 retlw 57 retlw 45 retlw 175 retlw 255 retlw 66 retlw 26 retlw 38 retlw 28 retlw 203 retlw 64 retlw 68 retlw 25 retlw 119 retlw 255 retlw 74 retlw 26 retlw 74 retlw 50 retlw 241 retlw 68 retlw 25 retlw 83 retlw 255 retlw 78 retlw 95 retlw 255 retlw 61 retlw 41 retlw 65 retlw 31 nobble call wait50 call flip call wait8 call flop call wait50 call flip call wait8 call flop call wait50 call flip call wait8 call flop call wait50 call flip call wait8 call flop call wait50 call flip call wait8 call flop call wait50 call flip call wait8 call flop call wait50 call flip call wait8 call flop call wait50 call flip call wait8 call flop call wait50 call flip call wait8 call flop return wait50 movlw 50 movwf mark50 wait32 movfw mark32 subwf TMR0,W btfss STATUS,Z goto wait32 movlw 32 ; reset postscaler addwf mark32,F decfsz mark50 goto wait32 return wait8 movlw 8 movwf mark50 wait328 movfw mark32 subwf TMR0,W btfss STATUS,Z goto wait32 movlw 32 ; reset postscaler addwf mark32,F decfsz mark50 goto wait328 return flip movfw ttline ; swap output lines xorlw 0x0C movwf ttline movwf PORTA return flop clrf PORTA return tiktok movfw ttline ; swap output lines xorlw 0x0C movwf ttline movwf PORTA ; start tick/tock bsf flags,ticking movfw buztick ; set end of tick/tock addlw 8 ; 80mS movwf tikstop return ttover btfss flags,ticking ; tick/tock in progress? return movfw tikstop ; tick/tock ended? subwf buztick,W btfss STATUS,Z return clrf PORTA ; end tick/tock bcf flags,ticking return end