20X2 with the timing accuracy of a crystal

hippy

Technical Support
Staff member
Following on from other projects connecting a 32kHz watch crystal to a PICAXE, here's one way to do it with the 20X2.

The only downside is that the chip can no longer be programmed in-circuit and C.7 is unavailable for use, though it should be possible to add a 3-way molex to select between download 10K/22K or crystal.

For maximum accuracy you might have to play with crystal make and capacitor values. Worked on breadboard with no capacitors but I didn't check frequency.

The code enables the LP Oscillator and Timer 1 to use it, then watches the TMR1 register increment. The msb changes state every 32768 clock ticks which is conveniently one second. In most applications which loop in less than one second all that would be needed is to call a subroutine to check the msb has changed. The program as a whole can run at any speed up to 64MHz.

It might be possible to generate a genuine 'Interrupt:' every two seconds. Will need to investigate that further.
 

Attachments

hippy

Technical Support
Staff member
And with interrupts ...

No idea how accurate this is - filed away my stopwatch somewhere so having to play, "one alligator, two alligator" to check timing - but it alleviates having to poll the timer.

Because the interrupt occurs every 65536 ticks, that's every 2 seconds with 32kHz crystal. That can be made slower if need by by setting 'timer=65534" for four seconds, 'timer=65533' for six etc.
 

Attachments

marks

Senior Member
WOW! that looks interesting
Hippy always arrives with Help lol Thanks!!
 
Last edited:

hippy

Technical Support
Staff member
Link for using 18X and 08M ...

http://www.picaxeforum.co.uk/showthread.php?t=7142

If one wants a simple 'DS1307 substitute' an 08M and 32kHz is something I'd consider as a viable and cheaper option. Might even be able to get that working as low-power and with 3V battery backup.

Can't recall all other PICAXE I've tested this technique with 08M, 18A, 18X and 20X2 work, 18M should. The 08 and 18 don't.
 

hippy

Technical Support
Staff member
@ ckoehn : Not the same but similar. Follow the link in post #4.
 

ckoehn

Member
Thank Hippy! I like it because it can be modified so suit specific needs. The output pulse can just be a blip to simulate a button press for the interupt on another uC. The 1307 has a square wave so how do you deal with buttons and the square wave on the same interrupt? I made it work by setting the setint different, but then it runs the interrupt 2x a second. Thanks again.

Clint
 

hippy

Technical Support
Staff member
The PICAXE runs at its default speed, the Timer1 clock runs independently at 32kHz.

The PICAXE could run faster than default speed and even slower.
 
Top