Counting Long Delays & Using a Heartbeat LED

LightGuy

New Member
Hi everyone,

Warning: Complete newbie to embedded processors here! I've recently begun working through the manuals and my mind is a-glow with whirling transient nodes of thought, careening through a cosmic vapor of invention with the possibilities of these wonderful chips. Right now, it's hard for me to stay focused on the basics when I keep coming up with new (to me) ideas. You know the feeling, I bet: I'm stuck in one of those "Do...While Having a New Idea" loops. :) The simulator on the Programming Editor is just too cool for words.

I need to have long delay times of multiple hours before firing a relay for a few seconds to a few minutes, but I would like to have a "heartbeat" led to reassure me that things are well. That means using Pause for long times is out, obviously.

A couple of quick questions about implementation, if you don't mind...

First, what's the most efficient way to do a long delay? Should I convert the delay time to minutes or use hours and minutes with the appropriate amount of nested loops? (Hours, Minutes, Seconds)

Second, is there a better way to do this than with nested loops? I assume the best way to have the led heartbeat is to have a loop at the core counting the seconds and switching the LED, but please let me know if there's an advanced technique that works better.

Third, split second accuracy isn't important right now, but how much trouble is it to hook up the DS1307 later? I have some 08 and 14 kits ordered, but can get the bigger ones, if needed.

Are the external crystal controlled PICs significantly more accurate for this?

BTW, power is not an issue for this since it will be hooked to a wallwart.

Thanks very much in advance!
 
Last edited:

BeanieBots

Moderator
Welcome to the wonderful world of PICAXE:)
Quite a few questions, I'll try to hit most of them.

Don't bother with Hours & mins unless you actually want to use them.
A word will hold 65535 seconds before it rolls over. Two words would give about 4.3E9 seconds. That's about 136 years. I guess that should be enough:eek:
A crystal or resonator controlled PICAXE will give much better accuracy than one with internal resonator.
The X1 variety has internal counters which can trigger interrupts. This could be a very useful feature for your application. Using pause statements for timing is not very accurate because you also need to take into account the time for the other commands which can vary depending on position and value of of any associated variables.

It is very easy to interface the DS1307. Two wires!
For just counting seconds, I would use the SQW output which can be programmed to 1Hz. Just hook it up to an input and read the state. If you don't want the time data, then a cheaper and easier method would be to use an old quartz clock movement. Very accurate. Many posting here about how to do that. Have a browse around using search.

If using a wallwart, you can also use mains frequency as an accurate timebase. 50/60Hz depending on location.

Nested loops is how I would do it, all working in seconds. If using the DS1307, I would read maybe the minutes, save it, then read again in a loop. If different to stored value, increment the minutes counter and store the new value again. Each time around the loop with a pause in it could flash the LED.
The "most efficient" or "best" way really depends on what else your code does, how it does it, and which PICAXE you choose. I don't want to promote bad practice but as long as it fits in memory and does what is required, does it really matter?
 
Last edited:

Technical

Technical Support
Staff member
The DS1307 also has a dedicated 1Hz output pin (as bb already stated), so you could add your heartbeat LED without any programming! Have a look at the AXE110 datalogger kit datasheet for some ideas.
 
Last edited:
If you decide to use the DS1307 you need to get at least an 18X, the 08 and the 14 don't have I2C drivers. If you stick with an 08 or 14 you'll need to use nested loops or an external time base.

That is assuming you want to read the time from the DS1307. If you just want to use the 1Hz output pin, I suppose you could get the time in with an 18X and then hook the square wave output to the 08 or 14.
 

LightGuy

New Member
Wow, thanks for the great input, guys! I will get a few samples from Maxim. IIRC, the DS1302 will run from a supercap, too. I'm not too familiar with anything other than their 1-Wire chips. So, I could use an 18X to "mission" the DS1307 with the date/time and to turn on the 1Hz output.

I will cut my teeth on the 08 and 14 with a nested loop, then move up to the other. Knowing me, it's definitely best to "limit" my options for now to keep from biting off more than I can chew.

So, the X1 chips have internal counters that you can set an interrupt to catch just like the IO pins? Neat! This low level hardware stuff is pretty cool.

Thanks to all who have responded and thanks to RevEd for making something so accessible.
 
Top