Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

elapsed timer?

Status
Not open for further replies.

karenhornby

New Member
Anyone know HOW I could implement an elapsed timer for my circuit?
What I've got so far is a 1 wire network, consisting of some ds18b20's, some ds2405's some relays and led's ect and a 4 line lcd module.
What i would like to do IF possible is somehow incorporate some kind of timer that would start when triggered, stop when triggered counting in seconds, BUT when power is removed it obviously goes off, but once power is turned it shows the total run time on the lcd display for a few seconds before the circuit carries on doing it's own thing again. and once the circuit is told to start counting again it carries on from where it was last at.
I'd like NOT to use a battery backup so that rules out using the pic's timers.
i could attach an eeprom but thats way more pins I want to use, Ideally a 1 wire timer would be ideal or maybe a 1 wire eeprom?
anyone got any ideas at all?
 
Why not use a small PIC with internal eeprom? Depending on how long you want the PIC to last last, you can save the current time every second... but note that you can only a million or so times before you get failures.

Using a 16F88 pic it only has 256 bytes of eeprom no idea if that is enough to store a time in binary or hex format, I would imagine the circuit will have a maximum run time of 10000 - 15000 hours
Oh apart from that I've no idea at all how to use the eeprom in the pic (yet)
Ahh the light is starting to dawn :)
IF I've got this right.. 20000 hours is 7200000000 seconds, and if the pic measured time once a second it would equate to 110101101001001110100100000000000 bytes?
all I'd have to do is figure out how to get the pic counting when told, and write to the eeprom when told
btw I'll be using PBPro
 
Last edited:
You can set it up like a normal clock, second, minutes, hours, days? That way you will only need 4 bytes in the eeprom, and you can time up to 255 days. Microchip have some sample clock code in some of the datasheets.

Edit to add: If you save the data to the eeprom once every minute, the eeprom should last more that 3 years. (note, not take 3 years to fill up, the eeprom "cells" can only be written to a certain amount of times before they fail.)
 
Last edited:
You could constantly update the NV RAM in a DS1307 RTC (it does have a tiny battery backup) You won't wear out the NV RAM and can write to it as much as you like.
 
I'm thinking its going to be simpler to use a timer inside the pic and save the info to it's internal eeprom once a minute that way if the circuit is turned off without the clock being told to stop it's still going to be pretty accurate!
I'm reading up on how to use the internal eeprom tomorrow, and got to study some picbasic examples of a real time clock but try and figure out some way of telling the pic to read the info from the eeprom and start counting from there!, display the time stored for a few seconds then carry on with the rest of it's tasks.
 
I'm thinking its going to be simpler to use a timer inside the pic and save the info to it's internal eeprom once a minute
There's one little thing to worry about with that idea. The PIC's EEPROM is rated to last minimum 100,000 writes. Writing once a minute you could potentially wear the PIC's EEPROM out in as little as 70 days.

Typical EEPROM endurance is one million writes, or 694 days, writing at once per minute.

It may not be an issue if this is just for fun, but if it's a product for sale and they all die within warranty, it'll cost ya. :p
 
no it's not a product for sale ir's only for my car, I'm constantly trying to improve it :)
Might have to look into proper eeproms then or come up with some other idea
 
Bill said:
You could constantly update the NV RAM in a DS1307 RTC (it does have a tiny battery backup) You won't wear out the NV RAM and can write to it as much as you like.

I like Bill's solution. It gives you battery backup of the actual time. You update the NV RAM in the DS1307 with you uC code so you have the same control as if you were using the uC's internal EEPROM. You also get rid of the clock code in the PIC.

If you still want to use the uC EEPROM there is a Microchip datasheet that talks about extending the life of an EEPROM. There are games you can play to get more out of it.
 
How about a DS2415? 1 wire Time Chip?
It seems like it's ideal IF I'm understanding what it does?
It seems like it's a real time clock that starts when power is applied AND the oscillator is turned on and you can read the time using the Read Clock [66h] command so that would fulfill my need to display the "up time" on power up after a few seconds delay.
I could start and stop the timer/clock by turning the oscillator on or off
IF I've got all that right,, the but I dont understand is this ...
"If the oscillator is intentionally stopped the real time clock counter behaves as a 4-byte nonvolatile memory"
(does that mean it stores the last figure in nonvolatile memory and once power is reapplied and the device is addressed and told to start counting again or oscillator restarted it would carry on from the last time stored?)

The only REALLY annoying thing about it if it works as I'm thinking is its a (swearing under my breath") surface mount device and I dont know of ANY adaptor to "convert" 6-pin TSOC package to some kind of dip solderable or solderable lead type thing.


OR would DS1904 work? clicky to datasheet as it's easier to mount the button 1 wire devices they aint surface mount :)

Nothing against what Bill said, but it's I²C bus device and as I'm using 1 wire already it would be way preferental to stay with it, especially as it wouldnt use any extra pins on the pic
 
Last edited:
:mad:GRR I HATE the fact you can only edit for 15 mins after posting:mad:, I could have saved it looking messy by adding this post...

With regard to the above devices I mentioned, although they both say...
"If the oscillator is intentionally stopped the real time clock counter behaves as a 4-byte nonvolatile memory"
what happens if power is turned off/removed i.e. oscillator not INTENTIONALLY stopped? do they store the time or reset and what happens when power is turned back on
 
"If the oscillator is intentionally stopped the real time clock counter behaves as a 4-byte nonvolatile memory"
(does that mean it stores the last figure in nonvolatile memory and once power is reapplied and the device is addressed and told to start counting again or oscillator restarted it would carry on from the last time stored?)

I looked at the DS1904 ibutton datasheet since it will be easier to solder.

I think this sort of device is often used as an hour meter for various types of equipment.

The counter and the NV RAM used to read it are distinct. I THINK the counter is also NV and it will always have the last count.

If you write the time with the osc running it will set the time the next time the I2C sends a reset.

It may help to think of the device as a little computer with a shared port (the NV RAM). The little computer must have its osc running to function.

If you write the time with the osc off it will not set the time. The little computer never sees the write command because it is off.

If you then start the osc it will not write the data in the NV ram to the clock because the WRITE command is long gone, this was a START OSC command.

If you read from the device with the osc off you get what was last in NV RAM because the little computer is not running and can not execute the READ command that would copy the time to NV RAM.

I am sorry if I made it too simplistic. I most often teach young people.
HTH
 
Need to add this.

The previous post was what I got from reading between the lines. I think I have it right. Read the datasheet again and see if it contradicts what I said.

Also if you use more the 1 I2C device on the same bus/(pic pin) you will need to do a MATCH_ROM command.
 
Last edited:
There's one little thing to worry about with that idea. The PIC's EEPROM is rated to last minimum 100,000 writes. Writing once a minute you could potentially wear the PIC's EEPROM out in as little as 70 days.

Typical EEPROM endurance is one million writes, or 694 days, writing at once per minute.

It may not be an issue if this is just for fun, but if it's a product for sale and they all die within warranty, it'll cost ya. :p

That is 100,000 to the program memory, and 1,000,000 to the eeprom minimum. If the OP is going to add some things later to make the project bigger/better, I would suggest staying with a PIC or equivalent.
 
That is 100,000 to the program memory, and 1,000,000 to the eeprom minimum.
EEPROM cell endurance minimum 100K. Typical cell endurance 1M.
Why is EEPROM byte endurance so much less? Minimum 10K. Typical 100K.
bleh.jpg
 
Last edited:
On the 18F's I used, it only shows byte endurance, and that is 100K min, 1M typ. One of my freinds ran some tests, and he got around 4M writes before failure. You can also switch your 4 RTC bytes you save to save to other eeprom bytes every 100 or so days to get more write cycles. If you save once per minute, you should get 2 years (1M saves).
 
On the 18F's I used, it only shows byte endurance, and that is 100K min, 1M typ. One of my freinds ran some tests, and he got around 4M writes before failure. You can also switch your 4 RTC bytes you save to save to other eeprom bytes every 100 or so days to get more write cycles. If you save once per minute, you should get 2 years (1M saves).
That page I posted was for an (now obsolete) 18F248. Two years isn't too bad as long as the chip is socketed, I guess.
 
If you put a diode feeding a capacitor that subsequently feeds your 5V reg, you will have enough time after the circuit is switched off to write the time to EEPROM. You will of course have to monitor the power line before the diode with a pic input. The size of the cap will be dependent on the current drawn by the pic. A simple way to work out how long you have is to write 0xff to all EEPROM locations at power up and then write 0x55 to all locations when you detect power failure. You can then check the EEPROM in your programmer, the time is approximately 4mS per byte written.

The advantage of this method is your EEPROM lasts for 1,000,000 power cycles.

Mike.
 
If you put a diode feeding a capacitor that subsequently feeds your 5V reg, you will have enough time after the circuit is switched off to write the time to EEPROM. You will of course have to monitor the power line before the diode with a pic input. The size of the cap will be dependent on the current drawn by the pic. A simple way to work out how long you have is to write 0xff to all EEPROM locations at power up and then write 0x55 to all locations when you detect power failure. You can then check the EEPROM in your programmer, the time is approximately 4mS per byte written.

The advantage of this method is your EEPROM lasts for 1,000,000 power cycles.

Mike.
sounds intriguing and I understand the cap idea to supply power to the pic for a few seconds after power failure but I just dont get the rest of the idea
surely if I'm writing to the eeprom while the program is running each of those writes count, and the extra one at power up and off so thats an extra 2 writes?
what happens to the clock timer data when the eeprom is written all 0Xff at power up, or 0X55 at power failure?

I'm still pretty interested in the DS1904

Need to add this.

The previous post was what I got from reading between the lines. I think I have it right. Read the datasheet again and see if it contradicts what I said.

Also if you use more the 1 I2C device on the same bus/(pic pin) you will need to do a MATCH_ROM command.
Thanks for your explanation and please dont worry, the simpler someone explains it the easier i can break it down in my heqd, visualise and understand it :)
What your trying to say I believe is that the ds1904 would be perfect as it only starts counting once the oscillator is started, stops counting once the oscillator is stopped (run timer :) ) So all I'd need to do is find the rom's mac id which isn't a problem as I'm using 4 other 1 wire devices, at power up after giving the lcd time to initialise, I send a match rom command, read the clock which IF I've got this right will have started at 00days 00hours 00 minutes and 00 seconds. display it on the lcd for the amount of time I need it to show then it will sit there NOT counting untill I tell it to start again, and say the last time the osc had before i turned it off was 00:01:21:31 it would start again at that point which is exactly what I need.
IF the power is disconnected without the oscillator being stopped, it will immediatly start timing from the last time point so what I'd need to do first thing is match rom, and stop the osc so it might be an idea if I put the command stop osc near the start of the program so IF there was a power out the first command the 1 wire bus gets is match rom to the ds1094 then stop it's oscillator.
That way (IF I've got it right) it will work perfectly as a run timer because ideally I ONLY want the time to count once both relays are activated which would be pretty simple as I'm going to use the DS2405's as 2 switches to control the relays, I could also incorporate the cap from above along with a voltage detector so that if the voltage drops it stops the osc but I dont think I'd need that as long as every time power is applied the first thing it does is stop the osc a few seconds out in the run time wont matter at all.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top