This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to remember the number of power switch

How to remember the number of power switch,
Note:the power is main power,if the power off time is too long,MCU was stop working. sod ,off time less then 400ms,and MCU have a big cap to save power.
question:
if on/off power switch 1 times MCU output 500Hz on/off power switch 2 times MCU output 1000Hz ....................................
anyone have a method?
thx you .

  • I have read your post many times and still can not make head or tail of it.
    do you mean that you want to record how many times the power has been off long enough for the capacitot to discharge.

    anyhow to help you the followibng will be needed
    a) which micro (ALL that letters and numbers)
    b) do you have (or can you) have a serial EEPROM attached

    Erik

    PS when "MCU have a big cap to save power" it is essential that you have a supervisor chip on the reset.

  • It's a bit tricky to work with the external power, unless you also make sure you have a suitable reset circuit that will reset the chip correctly if the voltage (after your cap) drops to unsafe levels where the processor may go wild, but do not reset the chip as long as supply voltage is stable enough.

    Then you just need to add a diode on power and feed a processor pin the power before the diode, and feed the cap after the diode. Then the processor can get an interrupt when external power goes away while the cap still keeps the processor running.

    If you select a good processor, you can even change the processor to a lower power mode to conserve power in the capacitor while you count time waiting for power to come back (or reset to stop the program if power was off too long).

    As long as the cap can feed the processor, you don't need anything special. Just run your program and store state information in normal variables.

    A good processor can be powered and count time and still consume much, much, much lower than 1mA. Quite a number of processors can do it while drawing 50uA or less. Some chips can go way lower than that. Remember that processors with power-save can stop program execution with timers still ticking. So they count time while the processor core is stopped. It's just crystal oscillator + timer that needs to run.

  • a) what Per outlines above
    b) if you do not use a watchdog and your uC is never reset by anything but power up, you can simply pot the "counter" in the initializier. There is no difference between counting power off and counting power on.
    c) should you want to count also the instances where you cap keep it alive have the (properly configured) power (50/60 Hz) activate an interrupt and start a timer, when it times out count.

    if you combine a/b and c you can get both counts.

    of course you will need NV memory to hold the counter.

    Erik

  • I have read your post many times ...

    That sounds like a guy/gal having too much time on its hand.

  • "That sounds like a guy/gal having too much time on its hand."

    And your post doesn't indicate that you have too much time on your hand???

  • You guys are not understanding the problem. my dear friend wants to turn the power on once to select 500kHz, twice within a short interval to select 1MHz. He needs to count off time, so an EEPROM isn't going to work.

    A simple RC on the power supply with a reasonably high time constant. Power up and look at that voltage as the first thing you do. If it was powered before that voltage will be higher than if it wasn't. Up to you if you want to control the discharge with another resistor. Make sure you diode isolate this RC so it is not discharged by the rest of the circuit when powered down.

    Another way to do it is to NOT power the MCU down at all, just the rest of the circuit. You can put the CPU to sleep, so power use is next to zero and just keep the timer block running. If you can access the mains, you can also count zero crossings to determine the time as well.

  • "You guys are not understanding the problem."

    And there is where you are wrong. I have already posted an answer, where the processor do count time - and do not make use of any EEPROM, F-RAM or similar. With a correctly selected processor, you can drive the processor for a long time on a tiny capacitor so the processor can make use of the internal timers and power on/off can be fed to a processor pin (either interrupt pin or a pin gating a timer) so the processor core can sleep while waiting for power on - or the timer overrruns, in which case the "off" was considered too long to be part of multi on/off sequence.

  • Another way to do it is to NOT power the MCU down at all, just the rest of the circuit. You can put the CPU to sleep, so power use is next to zero and just keep the timer block running. If you can access the mains, you can also count zero crossings to determine the time as well.

    yo vipy mate.

    this idea is great , which I/O pin can be use? can you suggest?
    i want MCU working mode: when switch is pwoer off,mcu into sleep mode,and timer start.when power switch on. mcu into normal mode ,dispose continuance time from power off to power on . it is OK? thx you.

  • which I/O pin can be use
    there is, in this thread, no indication, whatsoever which uC you use.
    so the answer is "pin x"

    Erik

  • Saving to data on power down usually implement a separation of mcu vcc to the rest using a low Vf diode and a buffer cap, an analog comparator or adc of the mcu detect the voltage drop on the main supply indicating a power switched off. At first power on just do 500Hz, if a short power off detected then switch mode to 1000 Hz, another one switched back to 500Hz, and so on.

    A side note, disable all I/O immediately at power off detected - do not let your high current led driver drain the buffer cap to fast.. :->

  • (either interrupt pin or a pin gating a timer)
    P1.4 is neither on any derivative I know of.
    anyhow stating a specific pin without knowing the actual derivative is outright ridiculous.

    Erik

  • hi vip chummy boy.

    thx for the ace detail. i will use p1.4

    i o u 1

    u r the best :->

  • No - the same person communicating with himself because of his erratic brain patterns. But then again, communicating with himself is the best way to get responses saying how clever he is.

    Maturity comes with age - or sometimes never.