08M Clock Accuracy

sailgene

Member
Hello. I've built an automatic cat feeder using an 08M chip with a simple program to run a small motor every 12 hours. The motor runs for approximately 8 seconds to turn a cylinder which dispenses the food.

The problem is that there seems to be a 2+ minute delay for every 24 hours. This isn't a huge issue but I'm wondering if the internal clock is less than accurate or if it's a problem with the program I've written. I realize that the 25+/- seconds/day pause and motor run time would be an issue but what about the other 90+ seconds?

The program is designed for two inputs - one is for a manual feeding and the other for a timed feeding. This issue involves the timed feeding ("away" routine). The program is shown below. Any help or explanation would be appreciated. Thanks.

MAIN:

PAUSE 1000
IF PIN3=1 THEN MANUAL
IF PIN4=1 THEN AWAY
GOTO MAIN


MANUAL:

PAUSE 3000 'WAIT 3 SECONDS BEFORE DUMPING FOOD
HIGH 2 'TURN ON OUTPUT TO SWITCH ON TIMER & MOTOR CURRENT W/MOMENTARY SWITCH
PAUSE 8425 'RUN MOTOR FOR 8.425 SECONDS (360 DEGREE TURN)
LOW 2 'STOP MOTOR TO REFILL HOPPER
GOTO MAIN


AWAY:

PAUSE 3000 'WAIT 3 SECONDS BEFORE DUMPING FOOD
HIGH 2 'TURN ON OUTPUT TO SWITCH ON TIMER & MOTOR CURRENT
PAUSE 8425 'RUN MOTOR FOR 8.425 SECONDS (360 DEGREE TURN)
LOW 2 'STOP MOTOR TO REFILL HOPPER
FOR B1 = 1 TO 200 'START COUNTER
PAUSE 60000 'PAUSE FOR 60 SECONDS PER CYCLE (200 CYCLES = 3 HOURS 20 MINUTES)
NEXT B1
FOR B2 = 1 TO 200 'START COUNTER
PAUSE 60000 'PAUSE FOR 60 SECONDS PER CYCLE (200 CYCLES = 3 HOURS 20 MINUTES)
NEXT B2
FOR B3 = 1 TO 200 'START COUNTER
PAUSE 60000 'PAUSE FOR 60 SECONDS PER CYCLE (200 CYCLES = 3 HOURS 20 MINUTES)
NEXT B3
FOR B4 = 1 TO 120 'START COUNTER
PAUSE 60000 'PAUSE FOR 60 SECONDS PER CYCLE (120 CYCLES = 2 HOURS)
NEXT B4
GOTO MAIN 'START OVER AND CHECK IF PIN 4 IS STILL HIGH
 

hippy

Ex-Staff (retired)
Two minutes a day is actually quite impressive. Manufacturer's tolerance is +/-1% at 3V6 supply and 25C, +/-2% generally, +/-5% for extremes. 1% of a day is approximately 15 minutes.
 

BeanieBots

Moderator
In addition to what Hippy has stated about the basic tollerance, don't forget that all your other command lines also take time to execute so even if the pause statements were perfect, your code would run slower than ideal.

You might be able to get it more accurate with a little experimentation but the internal oscillator is affected by temperature and voltage so even if you had it perfect today, it might not be tomorrow.

For your application, it would probably overkill to use a real-time-clock chip but you can get simple crystal controlled oscillators quite cheap. You could use one to generate an accurate 1Hz clock pulse. Others here have used the guts of a cheap clock to generate a 1Hz clock pulse for long term accurate timing.
 

KMoffett

Senior Member
I would go with Beaniebot's suggestion. The attached is a circuit I've used for a 1 second clock. I compared two digital counters over three days. One connected to the power line through a divide-by-60 counter and the other connected to this circuit. Logged it twice a day. There were a variations between the counters of +/- 10 counts (seconds) over that time. Not sure which was varying, but I suspect it may have been the line since it always agreed at several points.

Ken
 

Attachments

John West

Senior Member
The ac line frequency around the US shifts somewhat as power-plant sync and load leveling is done. But it is pretty much brought back to an overall precise total value over the course of several hours. (Thus the reason you never have to reset simple clocks that run on AC - except for Daylight Savings Time.)

It can be used as a very good convenient counter for longer time periods - assuming your circuit needs AC mains power to begin with.

Something you may want to consider is the possibility of power failures. Unhappy cats are something you do not want to have to face.
 

KMoffett

Senior Member
Yup, knew that (brother worked for Nevada Light and Power). That's why I suspected the power line , but didn't have a secondary standard for verification.

Ken
 

sailgene

Member
Thanks

Thanks everyone for the answers. I was not aware of the tolerances and so I feel better now. As for power outages, our cat could afford to go on a diet....




Two minutes a day is actually quite impressive. Manufacturer's tolerance is +/-1% at 3V6 supply and 25C, +/-2% generally, +/-5% for extremes. 1% of a day is approximately 15 minutes.
 

KMoffett

Senior Member
It might be possible to derive a 1 second clock from the power line, with a backup clock from my 1.5V clock circuit, switched-in if power is lost.

Ken
 

kranenborg

Senior Member
Hippy has shown in 2007 that you can actually get a very accurate timer on any picaxe with basically only a 32kHz watch crystal connected to the PIC's low-power oscillator which is built just for that, see the following link: http://www.picaxeforum.co.uk/showthread.php?t=7142&highlight=08m+ds1307+watch+crystal

Maybe this and your app still fit on a single 08m, otherwise on a 14m? Presumably this should work on an 18M2 as well

EDIT: Have a look at the codes that hippy points to in the thread I provided: in particular LPOSC2 - LPOSC5 are interesting, including the option to run the PICAXE at lower system clock frequency (and thus saving power) whilst still maintaining excellent accuracy. Note also that the additional code required to run the oscillator and check the Timer1 value is minimal, in the order of 38 bytes, meaning that it will fit in most existing applications.

Regards,
Jurjen
 
Last edited:

Jeremy Leach

Senior Member
I wonder what the cat's tolerance is ? :) It would be interesting to see how accurate it's body clock is when it turns up for food!

Also there was another thread about synchronising to daylight. This might work for you too. You could add an LDR, and then have simple 'Sunrise detection' code along the lines of : 'if it's been dark for a long while and then it gets light then assume Sunrise'. Then just pause for a while before feeding puddy (or make it work for whenever puddy's feeding time is). Not super-accurate but might be good enough.
 

sailgene

Member
Thanks

Thanks again, everyone. As the feeder is indoors and runs twice daily, the use of a resistor checking for light levels would not be practical. And seeing as this particular 08M is keeping pretty good time, I think I'll simply rest on my laurels (sp) and leave well enough alone.

As for our cat's "body clock", it's ALWAYS ready to eat. But the sound of the feeding motor does provide some amazing antics as the cat takes off on a b-line for the food dish.

This is a great forum. Thanks again.



I wonder what the cat's tolerance is ? :) It would be interesting to see how accurate it's body clock is when it turns up for food!

Also there was another thread about synchronising to daylight. This might work for you too. You could add an LDR, and then have simple 'Sunrise detection' code along the lines of : 'if it's been dark for a long while and then it gets light then assume Sunrise'. Then just pause for a while before feeding puddy (or make it work for whenever puddy's feeding time is). Not super-accurate but might be good enough.
 

hippy

Ex-Staff (retired)
@ Jeremy : This may be of interest ...

http://ptaff.ca/soleil/?lang=en_CA

When looking at southern England, if one can get a good measure of sunrise and sunset, halfway between the two seems a fairly consistent time and a fudge factor could be applied knowing how far through the year one is or by using the amount of daylight. Not sure how that pans out further afield.
 

sailgene

Member
Simulator Timing

I forgot to ask: When running the simulator, is the chip really as slow as depicted on the program? In other words, the simulator shows each line being read before jumping to one subroutine or the other. Is that actually how long it takes the chip in real time? If so, I'm surprised.

Thanks.



Two minutes a day is actually quite impressive. Manufacturer's tolerance is +/-1% at 3V6 supply and 25C, +/-2% generally, +/-5% for extremes. 1% of a day is approximately 15 minutes.
 

hippy

Ex-Staff (retired)
Simulation is artificially slowed down so it doesn't all look like a blur, plus there's all the overhead of the simulator updating the screen graphics, internal databases and the like which slows it down compared to a real PICAXE. View -> Options -> Simulation can be used to set the simulation speed, speed it up, slow it down.
 

sailgene

Member
Simulation Speed

That makes perfect sense. And so when factoring in for programmed pause times, I won't overfactor for chip "speed".


Simulation is artificially slowed down so it doesn't all look like a blur, plus there's all the overhead of the simulator updating the screen graphics, internal databases and the like which slows it down compared to a real PICAXE. View -> Options -> Simulation can be used to set the simulation speed, speed it up, slow it down.
 

Jeremy Leach

Senior Member
Thanks for that link Hippy. It's an interesting idea - but I've not got an application for it at the moment. There's probably something to do with gardening that it could be applied to.
 

fernando_g

Senior Member
As for our cat's "body clock", it's ALWAYS ready to eat. But the sound of the feeding motor does provide some amazing antics as the cat takes off on a b-line for the food dish.
.

I know the feeling...we had a cute little kitten that ended up looking like Garfield because its daily routine was essentially sleep/eat, sleep/eat...etc.
 

westaust55

Moderator
For future reference,
if you do need to remove a duplicate post or whatever, then use EDIT and GO ADVANCED
then you have the options at the bottom to completely remove the post
 

John West

Senior Member
For future reference,
if you do need to remove a duplicate post or whatever, then use EDIT and GO ADVANCED
then you have the options at the bottom to completely remove the post
Thanks for the info. Now... if I could only do that when I'm speaking....
 
Top