PDA

View Full Version : 20X2 with the timing accuracy of a crystal



hippy
01-12-2009, 22:16
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.

hippy
01-12-2009, 22:34
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.

marks
03-06-2010, 17:17
WOW! that looks interesting
Hippy always arrives with Help lol Thanks!!

hippy
03-06-2010, 19:27
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.

Andrew Cowan
03-06-2010, 20:24
Hopefully Martin hasn't put his scope away yet...

Have you got a crystal you can try it with, Martin?

A

ckoehn
08-06-2010, 01:52
I came up on this during a search and wondered if you use an 08M, is the code the same?

Clint

hippy
08-06-2010, 08:40
@ ckoehn : Not the same but similar. Follow the link in post #4.

ckoehn
08-06-2010, 14:39
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