Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
April 19, 2024, 08:32:49 20:32


Login with username, password and session length


Pages: [1]
Print
Author Topic: How to remember the number of power switch  (Read 3793 times)
0 Members and 1 Guest are viewing this topic.
jamen
Junior Member
**
Offline Offline

Posts: 41

Thank You
-Given: 31
-Receive: 7


« 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 .
 
Logged
SteveyG
Newbie
*
Offline Offline

Posts: 23

Thank You
-Given: 4
-Receive: 9


« Reply #1 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?
Logged
Ichan
Hero Member
*****
Offline Offline

Posts: 833

Thank You
-Given: 312
-Receive: 392



WWW
« Reply #2 on: May 21, 2012, 06:05:11 18:05 »

Something similar with saving to eeprom at power-down, google will show it.

-ichan
Logged

There is Gray, not only Black or White.
solutions
Hero Member
*****
Offline Offline

Posts: 1823

Thank You
-Given: 655
-Receive: 900



« Reply #3 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.
Logged
jamen
Junior Member
**
Offline Offline

Posts: 41

Thank You
-Given: 31
-Receive: 7


« Reply #4 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.
Logged
Ichan
Hero Member
*****
Offline Offline

Posts: 833

Thank You
-Given: 312
-Receive: 392



WWW
« Reply #5 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..  Wink

-ichan
Logged

There is Gray, not only Black or White.
jamen
Junior Member
**
Offline Offline

Posts: 41

Thank You
-Given: 31
-Receive: 7


« Reply #6 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.
Logged
Parmin
Hero Member
*****
Offline Offline

Posts: 582

Thank You
-Given: 494
-Receive: 133


Very Wise (and grouchy) Old Man


« Reply #7 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..
Logged

If I have said something that offends you, please let me know, so I can say it again later.
jamen
Junior Member
**
Offline Offline

Posts: 41

Thank You
-Given: 31
-Receive: 7


« Reply #8 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.
Logged
metal
Global Moderator
Hero Member
*****
Offline Offline

Posts: 2420

Thank You
-Given: 862
-Receive: 678


Top Topic Starter


« Reply #9 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.
Logged
Pages: [1]
Print
Jump to:  


DISCLAIMER
WE DONT HOST ANY ILLEGAL FILES ON THE SERVER
USE CONTACT US TO REPORT ILLEGAL FILES
ADMINISTRATORS CANNOT BE HELD RESPONSIBLE FOR USERS POSTS AND LINKS

... Copyright © 2003-2999 Sonsivri.to ...
Powered by SMF 1.1.18 | SMF © 2006-2009, Simple Machines LLC | HarzeM Dilber MC