Shop OBEX P1 Docs P2 Docs Learn Events
Perfecting The TC54 Brownout Detector To Backup Variables In The EEPROM — Parallax Forums

Perfecting The TC54 Brownout Detector To Backup Variables In The EEPROM

MahonroyMahonroy Posts: 175
edited 2014-10-16 08:12 in Propeller 1
Hey guys,
I have a project circuit setup that is similar to the education kit tutorial setup, here is a photo for reference:
http://www.parallax.com/sites/default/files/styles/full-size-product/public/32305a.png?itok=J6DWZOG0

I am also using a 12V voltage regulator, which is in parallel with the 5V voltage regulator. The 3.3V voltage regulator is powered from the 5V voltage regulator (similar to the education kit).

I have the brownout detector connected to the 12V output, and will activate at 8.6V (I'm using the 4.3V brownout detector, and using a voltage divider of 2x 50K resistors so I can read 8.6V instead.). I am using a pullup resistor, and a diode, and have this connected to a propeller pin.

I also have some capacitors surrounding the input and output of all the voltage regulators.

In the propeller spin program, I am monitoring a pin, and as soon as it goes low, the propeller chip saves all of the data I want to the EEPROM. So far this works great, but I have a couple questions.

I have a 1000uf capacitor on the output of the 5V voltage regulator. This does not give the program enough time to save data to the EEPROM before loosing power. Using 2x of these capacitors in parallel (2000uf equivalent) also is not enough time. But 3x capacitors (3000uf equivalent) and it works every time.

So my question is, should I use a single 5000uf capacitor to be on the safe side? Would a 0.01f capacitor be overkill? What do you guys think is the best way to handle this? Or has anyone hooked this up differently?
Thanks and any help/advice is greatly appreciated!

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2014-10-10 11:42
    What are you using for the 12V regulator? It could be that the caps are discharging back through the 12V regulator when its input drops. If so, a diode between the 12V output and some large caps on the 5V input might buy your program a little more time. You will need to add another, smaller cap directly onto the 12V output to keep that regulator stable. And keep the brownout detector wired directly to the 12V regulator output as well.

    Also, what are you using for your 3.3V regulator? With only a 5V input, it needs to be of the low-dropout variety.

    -Phil
  • MahonroyMahonroy Posts: 175
    edited 2014-10-10 12:03
    What are you using for the 12V regulator? It could be that the caps are discharging back through the 12V regulator when its input drops. If so, a diode between the 12V output and some large caps on the 5V input might buy your program a little more time. You will need to add another, smaller cap directly onto the 12V output to keep that regulator stable. And keep the brownout detector wired directly to the 12V regulator output as well.

    Also, what are you using for your 3.3V regulator? With only a 5V input, it needs to be of the low-dropout variety.

    -Phil

    Thanks for the reply!
    Here are the links for the regulators I'm using:
    12v: http://www.mouser.com/ProductDetail/ON-Semiconductor/MC7812CDTG/?qs=%2fha2pyFaduirlRo6%2b6i1uL%2baN6Q8hIO%2b37J7F9kx%2bQa%2bV6TblXtdrw%3d%3d
    5v: http://www.mouser.com/ProductDetail/STMicroelectronics/L7805ACD2T-TR/?qs=%2fha2pyFadujE9KQ1BxQHaJhNdIfs376LTVhKKFHwq0HqIltLh27UEg%3d%3d
    3.3v: http://www.mouser.com/ProductDetail/Diodes-Incorporated/AZ1117D-33TRE1/?qs=%2fha2pyFaduhVsYvw8V7yKDVonnmFlWxloYdZVlYmAhphETUXqM7LuCqNMsjCu5K%2f

    I attached a diagram showing how everything is currently connected, as well as the caps that I have in there so far.
    1024 x 728 - 37K
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2014-10-10 16:02
    You've got the voltage detection circuit connected to the 1000uF cap. That cap has to begin discharging before the voltage detector sees a brownout condition. Here's the way I would do it:

    attachment.php?attachmentid=111385&d=1412982103

    This way, when the 12V supply starts to go low, the 47uF cap will discharge, letting the voltage detector see the brownout condition. But the diode will be reverse-biased at this point, so the voltage on the 1000uF cap can only discharge into the 5V regulator and circuitry further downstream, allowing more time for the backup.
    253 x 207 - 3K
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2014-10-10 16:26
    You've got the voltage detection circuit connected to the 1000uF cap. That cap has to begin discharging before the voltage detector sees a brownout condition. Here's the way I would do it:

    attachment.php?attachmentid=111385&d=1412982103

    This way, when the 12V supply starts to go low, the 47uF cap will discharge, letting the voltage detector see the brownout condition. But the diode will be reverse-biased at this point, so the voltage on the 1000uF cap can only discharge into the 5V regulator and circuitry further downstream, allowing more time for the backup.

    Yes, that's what you would need to do.

    Power fail detection used to be quite common but most systems these days are designed so that it just works without it. For instance, if you have variables that need to be backed up into EEPROM then depending upon what that is you can use a method which just checks for changes every few seconds or so and writes it to the EEPROM. But with this simple scheme the EEPROM will wear out some may exclaim yet simple maths tells you that 1 million MINIMUM guaranteed writes to the same location every 5 minutes of every day would still be fine after 10 years. If you are logging then normally the location changes so that is even less of a problem.

    BTW, looking at the project board picture with the 9V battery I always wonder why the PropPlugs don't provide 5V out and just jolly well power the whole board anyway.
  • MahonroyMahonroy Posts: 175
    edited 2014-10-10 18:37
    You've got the voltage detection circuit connected to the 1000uF cap. That cap has to begin discharging before the voltage detector sees a brownout condition. Here's the way I would do it:

    attachment.php?attachmentid=111385&d=1412982103

    This way, when the 12V supply starts to go low, the 47uF cap will discharge, letting the voltage detector see the brownout condition. But the diode will be reverse-biased at this point, so the voltage on the 1000uF cap can only discharge into the 5V regulator and circuitry further downstream, allowing more time for the backup.

    Ok so I gave this a try and wired everything up like you described, and here are my results.

    Before change:
    1 capacitor: 10ms of time before power loss
    2 capacitors: 13ms
    3 capacitors: 16ms

    After change:
    1 capacitor: 13ms
    2 capacitors: 16ms
    3 capacitors: 20ms

    So it did allow for more time this way. Do you think this is enough though? It seems like its taking 14-16ms to save the data.
    Yes, that's what you would need to do.

    Power fail detection used to be quite common but most systems these days are designed so that it just works without it. For instance, if you have variables that need to be backed up into EEPROM then depending upon what that is you can use a method which just checks for changes every few seconds or so and writes it to the EEPROM. But with this simple scheme the EEPROM will wear out some may exclaim yet simple maths tells you that 1 million MINIMUM guaranteed writes to the same location every 5 minutes of every day would still be fine after 10 years. If you are logging then normally the location changes so that is even less of a problem.

    BTW, looking at the project board picture with the 9V battery I always wonder why the PropPlugs don't provide 5V out and just jolly well power the whole board anyway.

    Peter, my old design worked by just saving the data to the EEPROM every time it changed. While this did work perfectly fine, it just seemed like a better design to save the data when the user is done with it (e.g. at power down), so I figured I would get a voltage detector to work. This also frees up some time that it takes to write the data every time.
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2014-10-10 19:58
    Mahonroy wrote: »
    Ok so I gave this a try and wired everything up like you described, and here are my results.

    Before change:
    1 capacitor: 10ms of time before power loss
    2 capacitors: 13ms
    3 capacitors: 16ms

    After change:
    1 capacitor: 13ms
    2 capacitors: 16ms
    3 capacitors: 20ms

    So it did allow for more time this way. Do you think this is enough though? It seems like its taking 14-16ms to save the data.



    Peter, my old design worked by just saving the data to the EEPROM every time it changed. While this did work perfectly fine, it just seemed like a better design to save the data when the user is done with it (e.g. at power down), so I figured I would get a voltage detector to work. This also frees up some time that it takes to write the data every time.

    It takes 5 to 10ms to write a byte to EEPROM and it takes 5 to 10ms to write a page of 64 bytes as well. However there is no need for your software to sit and wait for it to be done, all it needs to do is perform the sequential write and issue an I2C stop after which the EEPROM will look after itself, it doesn't need the Prop to hold its hand. But this means that if you try to do this again too soon that it will still be busy but this is normally taken care of by the EEPROM addressing as it should keep trying if it doesn't get an ack because of the chip being busy. Still, I doubt very much that this would ever be the case so if you can try this then good.

    Power fail methods are way too dependant not only upon the discharge rate but also the response time and so normally this is tied to a non-maskable interrupt and the equivalent in the Prop is to dedicate a cog to this function, once it detects a power fail it should stop all other cogs to conserve power before attempting any backup and then not waiting for the EEPROM to finish but also shut down the power-fail cog too. That is if you really feel you should do it this way though I would avoid it.

    BTW, change the 47uF to the minimum or 10uF as you need it to react almost immediately. Normally I would have put the PF detect before the +12V to catch the input supply droop. What is you input supply?
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2014-10-10 22:50
    ... once it detects a power fail it should stop all other cogs to conserve power before attempting any backup ...
    Peter beat me to it! I was going to suggest the same thing.

    -Phil
  • jmgjmg Posts: 15,151
    edited 2014-10-10 23:16
    Mahonroy wrote: »
    Before change:
    1 capacitor: 10ms of time before power loss
    2 capacitors: 13ms
    3 capacitors: 16ms

    After change:
    1 capacitor: 13ms
    2 capacitors: 16ms
    3 capacitors: 20ms

    You can buy more time, with a minor change :
    Move the Diode + to the Power In, so the 5V Reg has full Vin applied.
    You can move the Fail sense to the 12V reg in, and set to 10-12V, and use the smallest cap on the 12V reg you can.
    That means the Vin and 12V fall quickly, and the 5V/3V chain has the longest decay time, and higher voltage change.
    Change of the ancient 7805 to a lower power, lower drop LDO like LP2951, will buy more ms too.
    The LP2951 also has a PGOOD pin, you can test to verify you did make the save in time.
  • ManAtWorkManAtWork Posts: 2,105
    edited 2014-10-11 06:41
    That's how I would do it:
    PowerGoodSignal.png

    The Switching regulator has a higher efficiency than the 7805 and gives you more backup time for the same capacitance. If possible, connect the diode to the main power input if it's below 28V (C1 has to be >16V then). This also has the benfit that you get reverse polarity protection for free.
    879 x 653 - 17K
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2014-10-11 08:37
    Still think you are overcomplicating this by attempting power-fail detect, holding up the supply in that period, and backing up. Your absolute best bet is to not wait until this happens and just backup as you need or else use a FRAM memory instead of the EEPROM as you can write as much as you like to that chip and it's pin compatible with the EEPROM so you just end up swapping the chip instead of all this power-fail circuitry and critical software.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2014-10-11 14:02
    Peter,

    But what happens if the power fails during a write sequence? Mightn't the FRAM/EEPROM contents be corrupted?

    -Phil
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2014-10-11 15:44
    Peter,

    But what happens if the power fails during a write sequence? Mightn't the FRAM/EEPROM contents be corrupted?

    -Phil

    Besides meteorite and lightning strikes and including Vogons destroying the Earth to make way for an intergalactic highway, there are millions of other things that can happen in this universe Phil :).
    So it is possible that just as the power is failing that the user jumps on the unit and changes a variable and how long will it take to write this information? On EEPROM around 5ms, on FRAM it's just like RAM, around 150ns.

    EDIT: even so, it is possible to handle power failure and EEPROM simply in software using redundant methods.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2014-10-11 19:34
    Here's what I would propose for periodic writes, then. Use an EEPROM that works down to 1.8V. Put a voltage detector on nRST that trips at, say 2.6V. Put a low value pullup on SCK and a higher-value pullup on SDA with maybe 10pF capacitor to ground. When the power fails, the EEPROM can finish a write cycle that it's already started. But if the Prop is still writing data to it, the reset will tristate SDA and SCL, with the resistors and cap creating an immediate STOP sequence on the I2C bus.

    -Phil
  • AribaAriba Posts: 2,682
    edited 2014-10-13 11:40
    With Phils circuit it may also help to add a resistor to discharge the capacitor faster. Otherwise there is nearly no load if the voltage at the 47u cap is under the voltage at the 1000uF (+ 0.6V).
    If you anyway add a resistor you can add also 2 resistors and make a voltage divider to a Prop pin. So you need no brownout detector chip anymore.
    With the 10k/1.8k resistors in the proposed circuit the Prop pin goes Low when the voltage at the 12V regulator is under ~ 9.3V.
    brownout2.gif


    Andy
    383 x 223 - 4K
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2014-10-13 11:46
    Good point about the resistor, Andy, and I like the divider idea.

    -Phil
  • MahonroyMahonroy Posts: 175
    edited 2014-10-16 08:12
    Thanks for all of the pointers! I ended up doing something similar to all of the suggestions... I put to use a slightly larger capacitor, and I incorporated a diode as well. Since its working perfectly now, I didn't want to change the design too much. But in the future, I like the idea of just skipping the TC54 voltage detector all together, and just using a capacitor connected directly to an input pin (with voltage divider) instead.
Sign In or Register to comment.