Sonsivri

Electronics => Projects => Topic started by: jamen on May 21, 2012, 07:27:41 07:27



Title: How to remember the number of power switch
Post by: jamen on May 21, 2012, 07:27:41 07:27
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.so ,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 .
 


Title: Re: How to remember the number of power switch
Post by: SteveyG on May 21, 2012, 02:50:47 14:50
Could you be a little more clear? Do you want to store the number of times the power has been cycled and store in non volatile memory? Or are you saying you want to set the mode of the device based on the number of times the switch was pressed?


Title: Re: How to remember the number of power switch
Post by: Ichan on May 21, 2012, 06:05:11 18:05
Something similar with saving to eeprom at power-down, google will show it.

-ichan


Title: Re: How to remember the number of power switch
Post by: solutions on May 22, 2012, 02:19:54 02:19
You guys are not understanding the problem. He 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.


Title: Re: How to remember the number of power switch
Post by: jamen on May 22, 2012, 02:49:32 02:49
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.
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.


Title: Re: How to remember the number of power switch
Post by: Ichan on May 22, 2012, 04:18:12 04:18
Saving to eeprom 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..  ;)

-ichan


Title: Re: How to remember the number of power switch
Post by: jamen on May 22, 2012, 06:25:30 06:25
Something similar with saving to eeprom at power-down, google will show it.

-ichan
hi gus,which word is google search?are you have a example? thx you for your help.


Title: Re: How to remember the number of power switch
Post by: Parmin on May 24, 2012, 05:25:04 05:25
This sounds similar to the operation of LED torch, you press the button once it'll give you 100% power, press again it'll give 50% power, and again it'll give 25% power, then it'll give SOS program etc.

Basically, you have a large cap in the power leads to keep the Uc operating for a few moment,
and a power line connection to on of the I/O pins to read the state of power from the switch.

In the program, you will increment a variable with every press of the switch, and
use the variable to point to whatever program required for that state.

I'm too lazy to sketch..


Title: Re: How to remember the number of power switch
Post by: jamen on May 24, 2012, 09:01:00 09:01
This sounds similar to the operation of LED torch, you press the button once it'll give you 100% power, press again it'll give 50% power, and again it'll give 25% power, then it'll give SOS program etc.

Basically, you have a large cap in the power leads to keep the Uc operating for a few moment,
and a power line connection to on of the I/O pins to read the state of power from the switch.

In the program, you will increment a variable with every press of the switch, and
use the variable to point to whatever program required for that state.

I'm too lazy to sketch..
yes, you mean is right,it is sos program,Do you have a example to study for me.
thx you.
still now,i don't know,how to try it.


Title: Re: How to remember the number of power switch
Post by: metal on May 24, 2012, 01:28:56 13:28
in the first post, download the code and try to understand it: http://www.mikrocontroller.net/topic/12176#new
there is a way there to handle double press, a real nice way.