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.