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 support@ccsinfo.com

How to Keep track of time?

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



Joined: 15 Dec 2006
Posts: 109

View user's profile Send private message

How to Keep track of time?
PostPosted: Thu Jul 08, 2010 1:25 am     Reply with quote

I need to keep track of a lamp operating time. Have to save values in-between power cuts. What will be the best way to do this?

Hope someone can give me ideas.

Thanks and Regards.
Jai.
Jerson



Joined: 31 Jul 2009
Posts: 122
Location: Bombay, India

View user's profile Send private message Visit poster's website

PostPosted: Thu Jul 08, 2010 4:05 am     Reply with quote

1. Use an RTC chip like the DS1307
2. Implement a firmware timer code along with a power fail early warning interrupt that you use to save the time values to the EEPROM
_________________
Regards
Jerson Fernandes
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Thu Jul 08, 2010 4:08 am     Reply with quote

The last post brings up the question of:-
Does the PIC loose power during the power cut or do you monitor the power outage another way ?

I assumed the PIC was running on battery or something.

If your PIC has RTCC built in then just use that. Also what accuracy do you need ? Second, ms ?
jaikumar



Joined: 15 Dec 2006
Posts: 109

View user's profile Send private message

PostPosted: Thu Jul 08, 2010 4:25 am     Reply with quote

I don't want to use RTC. Don't need to be very accurate. The Clock is 4Mhz crystal.
I have seen other posts on this issue. Want to know whether a diode and huge cap supply for the pic alone and a voltage divider sample idea.Save to internal eeprom. will it work? have to save 4 bytes.
vsmguy



Joined: 13 Jan 2007
Posts: 91

View user's profile Send private message Visit poster's website

PostPosted: Thu Jul 08, 2010 4:55 am     Reply with quote

You would not need an RTC - there is a thesis on the net about getting precise 1sec delays in a PIC.

It's in PDF format.

How you manage to keep the PIC powered is at your discretion.
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Thu Jul 08, 2010 5:19 am     Reply with quote

WIth a cap you could proberbly keep the PIC running for a little while when the power goes off, depending on current draw.

I assume then you will not be powering the PIC whilst the power is off?
Are you expecting the cap to keep the pic powered up whilst the power is off or do you just want it to keep it on for long enough to store the values ?
jaikumar



Joined: 15 Dec 2006
Posts: 109

View user's profile Send private message

PostPosted: Thu Jul 08, 2010 7:08 am     Reply with quote

Are you expecting the cap to keep the pic powered up whilst the power is off - I ONLY WISH.
No Just Long enough to store the 4 byte values on the internal eeprom of pic.
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Thu Jul 08, 2010 7:12 am     Reply with quote

So what are the 4 bytes ?

The pic will have no knowledge of how long it was off and it will not be able to work out how long it was off unless you have some extenal timer.

Each time the pic powers up will you be setting the time info on it somehow?

You will only be able to monitor how long the pic was on for each time. This will not tell you how long the power was off.
vsmguy



Joined: 13 Jan 2007
Posts: 91

View user's profile Send private message Visit poster's website

PostPosted: Thu Jul 08, 2010 9:08 am     Reply with quote

This is going to get complicated.

As I said at the beginning - How you manage to keep the PIC powered is at your discretion.

This is a forum for the CCS compiler.

Keeping the PIC powered has nothing to do with it.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Thu Jul 08, 2010 3:07 pm     Reply with quote

vsmguy wrote:
This is a forum for the CCS compiler.

Keeping the PIC powered has nothing to do with it.
True, but this forum does allow threads that are slightly off topic as long as they are PIC related. From the CCS Forum Policy and Guidelines:
Quote:
6. Stay on topic

This forum's sole purpose is to help people with programming Microchip's in CCS PIC C. Also, generally any discussion about Microchip's, firmware designing and electronic components in embedded systems is considered on topic.
I like the question and would like to see an answer.
vsmguy



Joined: 13 Jan 2007
Posts: 91

View user's profile Send private message Visit poster's website

PostPosted: Thu Jul 08, 2010 3:38 pm     Reply with quote

A good way to power the PIC would be to have a LDO connected to the regular 9V battery via a relay/FET that switches when there is no external power.

This would give the PIC all the backup it would ever need.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Thu Jul 08, 2010 5:13 pm     Reply with quote

Here are some other threads on this issue, including formulas:
http://www.ccsinfo.com/forum/viewtopic.php?t=38936
http://www.ccsinfo.com/forum/viewtopic.php?p=30962
http://www.ccsinfo.com/forum/viewtopic.php?t=25733
http://pic-c.ccsinfo.com/forum/viewtopic.php?p=23543
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Thu Jul 08, 2010 7:14 pm     Reply with quote

Quote:

Does the PIC loose power during the power cut or do you monitor the power outage another way ?

This question had not been answered and it is decisive in this stage.
Another data that you must know previously is current drain of the whole circuit in idle state.
The PIC drain current depends mainly of how do you set the oscillator circuits while in sleep/idle mode
minimizing its internal modules activity. If your application is able to run in this way, you will get the PIC
running at VERY LOW consumption (uA level) and a the 9V battery option would be applicable.
In order to consider the autonomy of operation with 9V battery I attach this info:
http://data.energizer.com/PDFs/522.pdf

Humberto
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