CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

What's the "best" way to measure a 24 hour period?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Guest








What's the "best" way to measure a 24 hour period?
PostPosted: Tue Mar 10, 2009 1:04 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Mar 10, 2009 3:25 pm     Reply with quote

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: 1635
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Tue Mar 10, 2009 3:32 pm     Reply with quote

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!!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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