Shop OBEX P1 Docs P2 Docs Learn Events
Power fail vs Reset indication — Parallax Forums

Power fail vs Reset indication

Could someone tell me if there is a location within the P1 that differentiates between a power fail startup and a reset driven startup. What I would like to find is an internal memory location or register that I can test to see which event caused a restart. Or possibly a location that can be modified during program execution and have that modification not be altered by pressing the reset button but does change when power is interrupted.

Comments

  • There is no location that will differentiate between the two classes of reset. I believe the POR circuitry even holds the reset line low until the processor has had time to stabilize. Check the description of the reset line in the Propeller Manual. You would need some sort of external reset circuitry to do this.
  • Thanks, Mike. I'm currently using a D type FF (74HC74) as a 1 bit latch which software will set after power up. Only a power fail restart will reset it. Downside is it uses two I/O pins. I think I might try a small serial SRAM and use the onboard I2C bus, store a defined set of bytes which the program will look for after a restart. I will set it up so that only a power fail will erase the bytes while pressing the reset will leave the SRAM alone and preserve the byte pattern. I'm doing this to see if I can speed up the startup process after a reset and not go through unnecessary lengthy peripheral initialisations.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2017-01-09 04:28
    What you want to do can be accomplished by a single external chip, a cap, and one data line on the Prop. Here's the chip:

    http://www.digikey.com/product-detail/en/torex-semiconductor-ltd/XC6119N27A7R-G/893-1239-1-ND/5879157

    When the supply voltage goes below threshold, the output goes low and stays low after powering up again for a period depending upon the timing cap. You need a timing cap large enough to accommodate the Prop's rather lengthy reset time. Then, when your program starts, just read the pin its output is connected to. If it's low, a power-fail reset occurred; if high, a push-button reset.

    There are other supervisor chips out there. Microchip makes a lot of them in three-pin TO92 packaging. But the hold times after power-up could range as low as 150 ms, even with a "350 ms" rated chip. That's why I focussed on the above chip with cap-programmable hold time.

    -Phil
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2017-01-09 07:12
    I often do the opposite, connect the reset pushbutton via a 100pF capacitor to RESn, and also connect the pushbutton directly to a free input pin with a pull-up resistor. The first instructions at startup capture the input state and if it is low, that means the pushbutton is being pressed. A short press < 50ms cannot be distinguished from a power-up, but a combination of the pull-up resistor and capacitor directly across the pushbutton (through 100Ω to prevent arcing) can hold the input low long enough to read low at 0.1 second.

    The idea can become a rudimentary UI by measuring by how long the button is kept pressed. Another pin with an led can provide user feedback; let them know when to let go in order to select the desired option. I often use that as a KISS interface for modes of operation, standby, run, calibration, etc...

  • Thank you, Phil and Tracy. You have given me terrific options for determining the cause of a restart. Both solutions are elegant in their simplicity. I'm going to try each one and see which will work better for me. Wondering if the upcoming P2 will have an internal register with several bits that will flag the reason for a restart.
  • I often do the opposite, connect the reset pushbutton via a 100pF capacitor to RESn, and also connect the pushbutton directly to a free input pin with a pull-up resistor. The first instructions at startup capture the input state and if it is low, that means the pushbutton is being pressed. A short press < 50ms cannot be distinguished from a power-up, but a combination of the pull-up resistor and capacitor directly across the pushbutton (through 100Ω to prevent arcing) can hold the input low long enough to read low at 0.1 second.

    The idea can become a rudimentary UI by measuring by how long the button is kept pressed. Another pin with an led can provide user feedback; let them know when to let go in order to select the desired option. I often use that as a KISS interface for modes of operation, standby, run, calibration, etc...

    Brilliant! I really love this idea and have a need for exactly what it does for a project in the works. Thanks for posting Tracy!!!

  • Tracy,

    Your method is quite ingenious! How do you connect DTR to your circuit, and how does it respond to a DTR reset?

    Thanks,
    -Phil
  • DTR from FT231X via 1nF to base of 10k:10k prebiased transistor, collector to RESn. Rising edge of DTR triggers reset as usual, pulling down hard on the 5kΩ input resistance of the RESn pin. I don't think the button circuit affects it even with a 0.1µF capacitor in parallel with the button. What concern did you have about it Phil?

    Hal, William, I do hope that helps. I think I first used the technique on the Stache Stamp programmer, built around an SX20 chip. A button and an LED let the user select which of 14 possible programs to load into the target Stamp.
Sign In or Register to comment.