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

Want to record total on-time of pic16f690

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



Joined: 09 Oct 2007
Posts: 62

View user's profile Send private message

Want to record total on-time of pic16f690
PostPosted: Wed Dec 26, 2007 5:17 pm     Reply with quote

I already have the Real Time Clock function thanks to Neutone.

I would like the PIC to save the total time that it is on into eeprom. That means for it to load the total elapsed time when it turns on and when it turns off, it adds its current on time with the total and saves it. When it turns on again it repeats the same process.

I just need an idea, I can come up with the code myself. Thanks as usual guys!
ECACE



Joined: 24 Jul 2006
Posts: 94

View user's profile Send private message

PostPosted: Wed Dec 26, 2007 6:10 pm     Reply with quote

Others may have a better way to to this, but one way may be to...

Since you have RTC working, just save the time to an address in EEPROM. When you power up, initialze the RTC and save it in an address that you will call startup time. Everytime you then update the time, save that time to another address called current time. Subtract the two and you have your uptime.

Keep in mind though that you will be repeatedly be rewriting to the same address. Over time, this could will wear out the EEPROM (Depends on how often it is updated and how long it is up for. You have to check the datasheets for that part and see how many times you can write to a location.) If that poses a problem, you could setup a bank of EEPROM, say 10 addresses, that you write the current time to, then each time you update the time, you write FF to the previous location and the current time to the next address up. This way you are not using the same address over and over. You roll the time to a different address each time. Then when you want to look up the current time, you look at the EEPROM bank you set up, you are going to look for addresses that are NOT FF. Then you know you have the time. Just an idea. You need to be sure you keep track of where you last wrote to so you don't write to a location that doesn't really exist for your device.

I would start smaller though. Get your code so you can aquire the uptime, then do the address rolling later on. Make sure the uptime works first. Good luck.
_________________
A HW Engineer 'trying' to do SW !!! Run!!!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Dec 26, 2007 6:13 pm     Reply with quote

You're describing a data logger which measures elapsed time.

Questions:

1. Is this the only function of this PIC ? Or is it doing other things ?

2. Does the PIC control any external circuits ?

3. Is power completely removed from the PIC ?
Is it controlled by a mechanical power switch ?

4. Does the PIC have an external EEPROM chip connected to it ?
If so, what is the part number ?

5. Is the circuit already designed and the board already built ?
crystal_lattice



Joined: 13 Jun 2006
Posts: 164

View user's profile Send private message

PIC Up Time
PostPosted: Thu Dec 27, 2007 5:46 am     Reply with quote

A very easy method of doing this is by using a RTC which has an elapsed seconds counter and a clock halt bit (The 1 wire DS1904 comes to mind).

When you start the PIC, enable the RTC, when you stop the PIC, disable the RTC. That way you never have to worry about saving any of the values for a "Lifetime on" counter. If you want a session timer then you take reading before/after and do the math Wink

Kind Regards
ThomasC



Joined: 09 Oct 2007
Posts: 62

View user's profile Send private message

PostPosted: Thu Dec 27, 2007 4:11 pm     Reply with quote

eace - That's a good idea. I will mess around with that and see how it works. I am only required to save the time every 10 minutes or so; it doesn't have to be extremely accurate. BTW, your signature is funny. I am also a hardware engineer trying to do software. Laughing

PCM programmer wrote:
You're describing a data logger which measures elapsed time.

Questions:

1. Is this the only function of this PIC ? Or is it doing other things ?

2. Does the PIC control any external circuits ?

3. Is power completely removed from the PIC ?
Is it controlled by a mechanical power switch ?

4. Does the PIC have an external EEPROM chip connected to it ?
If so, what is the part number ?

5. Is the circuit already designed and the board already built ?



1. No the PIC will have at least 4 more functions besides keeping time.

2. It will serve as an oscillator for the external circuits.

3. Power is completely removed from the PIC; it is controlled by a mechanical power switch.

4. The PIC doesn't have an external EEPROM chip connected to it.

5. Yes, the circuit is already designed and a prototype is built.


crystal_lattice - the circuit is already designed and I think it would be easiest not to add more parts. That is a good idea though....simple.


Last edited by ThomasC on Fri Dec 28, 2007 8:51 am; edited 3 times in total
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

PostPosted: Thu Dec 27, 2007 4:57 pm     Reply with quote

If the pic continues to run when the circuit is not operating its easy. You don't need to backup to EEPROM. While the circuit is operating, increment the elapsed time in the RTC timer interrupt.

If you are actually going to power the pic on and off load the elapsed time on power up from the EEPROM. While the circuit is operating, increment the elapsed time in the RTC timer interrupt. The math is much easier to keep up with if the value is always accurate. Forget about adding old and new elapsed times. If you can save the elapsed time just before powering off do that. If you can't, save the elapsed time once per 30 minute and you should be safe to avoid burning out the EEPROM location for about 8 years of elapsed time.
ThomasC



Joined: 09 Oct 2007
Posts: 62

View user's profile Send private message

PostPosted: Fri Dec 28, 2007 3:50 pm     Reply with quote

Where should I write the save function so it automatically does it when it hits a certain time? Within the TIMER1_isr() function perhaps?
Thx.
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

PostPosted: Sat Dec 29, 2007 5:27 pm     Reply with quote

ThomasC wrote:
Where should I write the save function so it automatically does it when it hits a certain time? Within the TIMER1_isr() function perhaps?
Thx.

Writes to EEPROM take about 5mS per write. I would suggest you set a flag in the interrupt to trigger a function in Main to do the write. I consider it to be a "Best Practice" to keep long duration code out of interrupts. It might work just fine as your code is written now but it could be a problem as your code grows. It would save you having to rewrite later if you put it in main in the first place.
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