Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
December 04, 2016, 03:11:48 15:11


Login with username, password and session length


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

Posts: 41

Thank You
-Given: 29
-Receive: 6


« on: May 21, 2012, 08:27:41 08: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
V.I.P
Newbie
*****
Offline Offline

Posts: 21

Thank You
-Given: 2
-Receive: 9


« Reply #1 on: May 21, 2012, 03:50:47 15: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: 840

Thank You
-Given: 312
-Receive: 387



WWW
« Reply #2 on: May 21, 2012, 07:05:11 19: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: 1446

Thank You
-Given: 590
-Receive: 851



« Reply #3 on: May 22, 2012, 03:19:54 03: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: 29
-Receive: 6


« Reply #4 on: May 22, 2012, 03:49:32 03: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: 840

Thank You
-Given: 312
-Receive: 387



WWW
« Reply #5 on: May 22, 2012, 05:18:12 05: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: 29
-Receive: 6


« Reply #6 on: May 22, 2012, 07:25:30 07: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: 544

Thank You
-Given: 357
-Receive: 126


Very Wise (and grouchy) Old Man


« Reply #7 on: May 24, 2012, 06:25:04 06: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: 29
-Receive: 6


« Reply #8 on: May 24, 2012, 10:01:00 10: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: 2018

Thank You
-Given: 514
-Receive: 477


Top Topic Starter


« Reply #9 on: May 24, 2012, 02:28:56 14: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

nothing to say..
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