|
|
View previous topic :: View next topic |
Author |
Message |
Guest
|
What's the "best" way to measure a 24 hour period? |
Posted: Tue Mar 10, 2009 1:04 pm |
|
|
Hi All,
I'm looking for opinions on the "best" way to measure a 24 hour time period. I am building a 18F4620 based lighting controller that will allow up to 64 lights to be switched on and off remotely. Once on, however, a light shall only be permitted to stay on for 24 hours. The actual 24 hour period is not critical, it just needs to be approximate (say, plus or minus 10 minutes). I was thinking of establishing a "tick" clock to do this, and then calculating/storing the terminal tick count for each light once it's turned on. I could also add a hardware RTC (eg. DS1307), and then store the end time/date for each light. I think I've got plenty of resources (RAM, etc.) for each approach. At this point, I'm just looking to see how others would approach this problem!
Thanks!
Dave |
|
|
Sydney
Joined: 13 Feb 2009 Posts: 71
|
|
Posted: Tue Mar 10, 2009 3:25 pm |
|
|
I would use a timer2 interrupt, at say 20ms, to increment a minutes variable every 3000th interrupt, rolling back to 0 after 1439 minutes, using 2 int16 vars, which should also be as accurate as your crystal since timer2 interrupts can be set at round values.
Then you just gotta save in which minute the lamp turned on, and work out how you are going to check if it has been on for 1440 minutes, which will take a little thinking about since you cant use > 1439 minutes, and you dont want to check it before the minutes timer has rolled over.
IMO using a rtc will be overkill, since you would probably want to convert the time into 0 - 1439 minutes, which would be also as much work as setting up the interrupt minute counter.[/code] |
|
|
asmallri
Joined: 12 Aug 2004 Posts: 1636 Location: Perth, Australia
|
|
Posted: Tue Mar 10, 2009 3:32 pm |
|
|
If you code does not lose ticks then the way you are describing it is simplest. If you planned to add more parameters, such as dimming, flashing etc then I would use a control block for each lamp but for something as straight forward as you describe, a single dimensional array would do the trick. When you turn a lamp on you set the count into the array at the appropriate offset. Then each second (or some interval) you decrement all non zero array elements. Any element that reached 0 after the decrement then gets further processing (like turning off). _________________ Regards, Andrew
http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!! |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|