Detect low voltage (VIN) and save data to eeprom

Status
Not open for further replies.

jacko91

Active member
Hey,
I am using a Teensy 3.5 to drive a motor with encoder. As the encoder is not absolute I am saving the current position to the eeprom every time I completed a movement. If the teensy is powerded up, the eeprom is red and the position is known. But if during a movement the power is shut down, the idea is not working anymore. The teensy is powerded with 5V. And I want to detect a voltage drop, then stop the motion and write to eeprom before the power is down.
How do I detect a voltage drop? And will there then be enough time for writing to the eeprom? Or do I need a cap to give me the required extra time after shut down?

Thanks
 
EEPROM has a limited # of lifetime writes - it isn't a small number - but it is there. Potential numbers have been posted - in the 10's of thousands - you might find a post on that. Not sure how quickly voltage can drop - but writing to eeprom on failing power might not be the safest thing - it is quick - but there is some amount of overhead as it takes some management to get the new data written and the structures updated. The EEPROM presented is one part of a many backed area that migrates to offer wear leveling (the noted overhead). You might Zero ( write 0xFF's [or 0xffff depending on data size] as that is the typical zero'd state? ) to a known area/range and then on startup the last non 0xFF location is the last stored position - then continue updates from there until reaching the end and repeating the clearing and moving after each write. Perhaps on detecting loss of power write it once then increment and write again - or if unchanged since last write just write it again, then on startup ideally it can be trusted if the last two entries agree.

Is there a vBat 3V supply to the T_3.5? There are RAM locations in the battery backed store that might hold that information across power loss - and be safer and faster to update without wear worry. That was posted sometime months back though I don't have the details at hand.

Many such things may have been linked in the rather long Wiki Coming thread - otherwise a Bing/Google search with the right context words might find useful posts.
 
This may depend on a few different things. That is how is the voltage level dropping? If it is because a user flicked a switch which turned off the power of the +5v DC, then you may have little or no time...

If however it is for example running off of a battery or the like. You can do things like create a voltage divider circuit that connects the voltage up to an analog pin and when it gets down to some threshold it shuts down, with hopefully enough time left before the processor shutdown.

I believe most if not all of the Teensy boards you can get the current voltage going to the processor. (Vref), which on the Teensy 3.5/3.6 I believe that this is logical pin 71. That is you can do analogRead(71) and get an idea of the voltage going into the actual processor. Note: when you are powering the Teensy from a 5v (VIN), there is a built in voltage regulator that converts this down to a lower voltage. I have not played with this for a long while (probably since 3.5 beta), so don't remember things like, how low the voltage will go before you start to the see the values drop on this, and how low can this go before the processor stops working properly...

Hopefully others here who have played more with this, will chime in and give you some additional ideas. But maybe this will give you a few ideas to start investigating.
 
Hey
thanks for the input.
So the szenario is that the power is fully turned off, and I want to detect this. I have been reading about the Vref. As far as I understand it, the data people gather for this is: that as long as VIN is over 3.3V, it will not influence the pin71 reading. I am thinking to attach a cap inbetween the teensy and the power supply to extend the time until shut down.
 
Status
Not open for further replies.
Back
Top