Timer that stores time without power - Page 1
Forum section: electronics / projects

author: NilsLeu
author_rank: Newbie
timestamp: October 06, 2020, 03:16:25 pm
content: Hello allI am looking for a timer circuit that keeps the time, even when there is no power. After a certain amount of time has passed (Probably about 1500 hours) It should just turn on a red LED. To reset the time, I want to press a button or short out two pads. It doesn't have to be exact, but as small as possible. The operating voltage will be 5v. The circuit will be used in a device, that has filters, which need changing every about 1500 hours. But the device won't be connected to power quite often. I do not want to use a battery to keep the time, if that is somehow possible. Does someone have a good idea? Thank you for any suggestions

author: drvtech
author_rank: Regular Contributor
timestamp: October 06, 2020, 03:29:42 pm
content: ATTiny85. Store the elapsed time in the EEPROM every now and then. The length of "every now and then" is constrained by how accurate you want to be, how often the power fails typically and the fact that the life of the EEPROM is specified as 100,000 writes (I think). If you really need to write the EEPROM more than 100,000 times during the life of the product there are well defined techniques for using multiple locations to spread the wear.

author: Zero999
author_rank: Super Contributor
timestamp: October 06, 2020, 03:36:13 pm
content: You need a real time clock, with a wake up alarm. Obviously it will need a power source. If the power isn't applied for a long enough period, to charge a battery, then a super capacitor could be used, or go for a non-rechargeable battery, which is replaced, along with the filter, so it will never be left to the point when it dies.https://en.wikipedia.org/wiki/Real-time_clock

author: Miti
author_rank: Super Contributor
timestamp: October 06, 2020, 03:42:38 pm
content: Look at I2C FRAMs + a small MCU.

author: MarkR42
author_rank: Regular Contributor
timestamp: October 06, 2020, 03:45:16 pm
content: If you want to keep the time in the device, it will probably need some power, but not much.Consider using some kind of battery, either a primary lithium (long lived, low self-discharge), or perhaps a rechargable cell of some kind. Modern micros use very little power just keeping time.Alternatively, either harvest some power from the environment (solar cell etc) or receive time signals from somewhere external. Good luck!

author: Doctorandus_P
author_rank: Super Contributor
timestamp: October 06, 2020, 03:51:12 pm
content: First I was confused about lighting a LED without power...Then I thought it's probably some air filter with a fan motor, and plenty of power while plugged in, but often the thing is in storage or in an attic without any power.Correct?Any small uC with built in EEprom will do, (or add some external EEprom, or indeed FRAM, which does not wear out, but is more then you need, but if the price is right, why not.).You don't need an external "realtime clock" circuit, nor even a crystal to run the uC.Running from the internal RC oscillator you usually get a clock accurate within a few percent, which is good enough for this.There are some tricks to getting it to work reliably.The simplest is indeed to periodically write the elapsed time to EEprom. But don't write raw data to the EEprom. Add some checksumming feature, and use multiple copies, and write some code to compare the lapsed time with the data stored in EEprom.For example:Use a structure for a 32 bit counter and a 16 bit checksum.Make 10 copies of that structure in EEprom.Increment one of the structures (and checksum) each 6 minutes, so round robin every hour (this also reduces EEprom wear)Then, every time your gadget starts, the first thing the uC does is read all 10 structures, and figures out which one was last updated, and continues counting from there.This simple algorithm fails if your gadged is usually turned on for less then 10 minutes at a time. So figure out a suitable interval.You can try to do some complicated guesswork if the checksum fails, but this gets very difficult very fast. symply ignoring any counter with a failed checksum is easy and plenty good, especially because you have so many copies.----------A more complicated setup monitors the power supply voltage, and writes intermediate counter values to EEprom at the moment it detects a dip in the power supply voltage.A moderately sized Elco is plenty to power the uC long enough to write some data to EEprom.----------As feature creep you can add a serial port that periodically outputs a string of text with data.Version number, github link, your name number of runtime hours, how many times the unit was plugged in, anything else you can think of.I would not recommend the ATTINY84.If you want to use any of the AVR microntrollers, then just grab an ATMEGA328, or any other of the Mega's.Those former Atmel controllers have lots of gotcha's and incompatibilities between different variants, and if you also start mixing Mega's and Tiny's it only gets worse. Often the Tinies don't even have a decent serial port, I2C is handled very differently from the Mega's and that's the start of a long list.I had my final wakup call when I started with one of the 32 bit ARM cortex controllers. Started reading a datasheet about the workings of their timer peripheral, and then it had a small note: There are seven of these in this uC. If an AVR controller has 4 timers, it's likely 3 of them are different.Price difference between Mega328 and a Tiny84 is completely insignificant for hobbyists. While the hours of figuring out the incompatibilities is not.

author: NilsLeu
author_rank: Newbie
timestamp: October 06, 2020, 04:34:07 pm
content: Wow, that was quick. Didn't expect so many answers in such a short time period. Doctorandus_P's idea will probably be the best fit for the project. The EEprom of an ATTiny85 lasts 100 000 write cycles. So with the 10 copies way, it would theoretically last 100 000 hours, which is plenty. I also like the idea of a serial output. The only problem is, that I have no idea how to program an ATTiny85, I only know the very basics of the Arduino language. But nothing I can't learn...I will report back, when I have any new findings. Thank you very much for all the answers

author: magic
author_rank: Super Contributor
timestamp: October 06, 2020, 04:39:08 pm
content: If you want to go with AVR, there are some newer tinyAVR 1-series and 0-series chips. I believe they have less power consumption and lower minimum operating voltages than the old ones. They also use new programming interfaces, sometimes awkward, but some of them are just UART and can be programmed with any USB UART dongle and appropriate software.You would have to ask around for details, I have never used them.

author: Doctorandus_P
author_rank: Super Contributor
timestamp: October 06, 2020, 04:41:06 pm
content: This is what I meant.Your regular of the shelf "arduino" board has a ATMEGA328, and for a smaller board you can go to the "arduino nano", or even use an "openlog" board, and they all have the same M328 and should work with "arduino" with no extra learning curve needed.Edit:Microchip follows Atmels tradition of changing the programming interface every 2 years or so. Yet another reason I don't like them much.For this application current consumption is completely irrelevant, and a (real!) ATMEGA328 can also sleep at uA currents, or even less than a uA (I think) if you take the "PicoPower" version of the chip. Again: All the same uC, no reading of 5 different datasheets needed.

author: NilsLeu
author_rank: Newbie
timestamp: October 06, 2020, 04:48:55 pm
content: The problem is space. The whole circuit including a usb-C Port for powering the whole Device and red (smd)LED should fit on a 30mm*30mm custom PCB.

author: drvtech
author_rank: Regular Contributor
timestamp: October 06, 2020, 04:53:47 pm
content: Whilst I take on board the comments regarding ease of programming the 328, I suggested an ATTiny85 because the OP specified "as small as possible". The complete ATTiny85 solution could be done on a PCB about 10-15mm square, including a pushbutton, LED and microUSB. Sorry, just noticed USBC but, if you're just supplying it with 5 volts any old connector will do 🙂

author: ledtester
author_rank: Super Contributor
timestamp: October 06, 2020, 04:58:09 pm
content: Maybe the attiny85 digispark board would work.https://youtu.be/0B88dsW93SAAlso comes in this variety:https://www.amazon.com/Comimark-Digispark-Kickstarter-ATTINY85-Development/dp/B07W84TFJC/ref=sr_1_5Even comes with an LED on board!

author: Mechatrommer
author_rank: Super Contributor
timestamp: October 06, 2020, 05:09:21 pm
content: Quote from: Doctorandus_P on October 06, 2020, 03:51:12 pmthe OP said, even with "no power", sleeping mcu will still need power (battery), by the time when not enough power to even sleep, all time tracking will be gone. if this is an option, i will just go with cheap RTC module in ebay, that chip is designed for low power and should run a pretty long hours on a cell battery and more accurate i think. even if any mcu can beat it, internal clock will still drift, even clock crystal will drift within weeks. the truly "no power" keeping time is afaik is by getting data from GPS when power is connectedhttps://www.allaboutcircuits.com/projects/pic-based-gps-clock/

author: ledtester
author_rank: Super Contributor
timestamp: October 06, 2020, 05:12:10 pm
content: Quote from: Mechatrommer on October 06, 2020, 05:06:44 pmI was confused about this, too. My current interpretation of the requirements is that the OP only wants to measure how long the device is running - and after 1500 hours of run-time the LED should turn on.So no timekeeping has to take place when there is no power. Perhaps the OP could clarify this point.

author: Doctorandus_P
author_rank: Super Contributor
timestamp: October 06, 2020, 05:19:47 pm
content: Again:30mm *30mm is huge for a simple project like this.A mounting hole for an M3 bolt is bigger than a M328 in mlfBut the TQFP is still easy to solder by hand and is 9*9mm Smaller then a DIP8 and much lower volume as it's only a mm thick.The "openlog" board I mentioned has a M328 on one side, and a connector for uSD card on the other, and size is smaller then a postage stamp.The "arduino nano" is 44mm long, but you can cut off most of it if you don't need the CH341, or cut off a bit less if you don't need the I/O on the other side.If there is a need to go "small", I'm thinking about the 6 pinned SOT-23 or those bare die things of 2*2mm All completely over the top for a project like this.In this case the space savings come from using internal EEprom, and RC oscillator instead of an external RTC chip. 2% is plenty accurate of time keeping for replacing air filters. No need whatsoever to drag in some GPS disciplined Rubidium time standard.It's a simple project with plenty of space available, and there is no need to add any further complication.--------------Alternatively: Use an off the shelf "hour meter" Those with numbers on rotating cylinders never loose memory when unpowered. I don't know about the LCD versions.

author: NilsLeu
author_rank: Newbie
timestamp: October 06, 2020, 05:58:38 pm
content: I'm sorry for the confusion. I DO NOT need any Time-Keeping. Just a device, that turns on a red LED after 1500 hours and that has a button to reset the timer. It has to be able to store the amount of hours when there is no power. I think an ATTiny85 is going to be the simplest way to do this project. Or what alternatives are there. There will be a few other components on that 30*30mm board, so I am going to design a custom PCB. I just don't know how to write the code for the thing, is there some example somewhere. Or can someone here write it for me, I am happy to pay.

author: aheid
author_rank: Regular Contributor
timestamp: October 06, 2020, 08:50:16 pm
content: Just to be clear, the device will record total running time while under power, keep the total running time while unpowered, and after 1500 hours of running time it will light up a LED while powered until a reset button is pushed?

author: Zero999
author_rank: Super Contributor
timestamp: October 06, 2020, 09:16:51 pm
content: Quote from: aheid on October 06, 2020, 08:50:16 pmThat's much easier. All that's required is a microcontroller, with some non-volatile memory. When the device is running, the microcontroller just needs to increment, at a regular interval, say every second which is stored in the non-volatile memory, when the power is disconnected. When the counter reaches a certain number, it can turn on an LED, to signal a new filter is required.If a microcontroller is impractical, then how about a mechanical solution? A small motor driving a a very low ratio gearbox, with a cam to activate a switch, when the correct time has elapsed.

author: jbb
author_rank: Super Contributor
timestamp: October 06, 2020, 10:11:33 pm
content: How about an MSP430FR2100?- needs 3.3V regulator+ can program over UART+ FRAM memory inside. Very good write endurance, you could update once per second if you want+ can use external XTAL for accuracy+ cheaper than ATtiny, ATmega

author: ledtester
author_rank: Super Contributor
timestamp: October 06, 2020, 10:21:09 pm
content: Does the device have a 12.6V rail?https://youtu.be/Cxj399LuX1M

author: notsob
author_rank: Frequent Contributor
timestamp: October 06, 2020, 10:32:17 pm
content: I was about to mention the mercury unit - we had them decades ago on Burroughs disk drives ( and they were for when to change the main filter in the drive). They were reset by lifting the top part of the unit (which had the mercury capillary) rotating it 180 degrees and plugging it back on

author: Mechatrommer
author_rank: Super Contributor
timestamp: October 06, 2020, 11:44:12 pm
content: Quote from: NilsLeu on October 06, 2020, 05:58:38 pmso there are 2 devices here, one is with the filter, and another one is the counter. the "power" mentioned refer to the power to the device with a filter right? the counting device will constantly under power. so a mcu will do the job. another better solution instead of mercury or mechanical motor is imho this note..... "jan, march, may, july, sept, nov.. just stick it on the device that need change filter. on first day of the written months, change filter. 1500 hours is about 2 months, perpetual counting device that needs 0uA current. fancier perpetual and more resettable counter i can think of is overlap calendar in circle 6 arrows so they can slide to anywhere when filter is changed (attached)..

author: Doctorandus_P
author_rank: Super Contributor
timestamp: October 07, 2020, 10:45:05 am
content: If you want to do it "properly", then simply counting hours is by far not the best approach.Much better would be tho measure the differential pressure over the air filter at a calibrated air flow.Sensor like the Bosch BMP180 are extremely sensitive (and also small) and you can even do it with one sensor, by first measuring atmosferic pressure when the motor is off, and then measure the pressure change after the motor turns on. You could measure RPM of the fan and include that in the calculations, but that's probably more trouble then it's worth.This sensor is so ridiculously sensitive that it can measure height with a resolution of 17cm by changes in ambient air pressure.When going to feature creep, you can do both. Make a log of the hours it is used, and also log the pressure differential.Unfortunately, pressure drop over the filter is also not a ideal measurement. It works good with filters that get contaminated by particles (The bag in a vacuum cleaner), but it does not work good with open filters such as active carbon which rely on attraction of the contaminants, but stay open even if the filter particles are saturated.