I'm making a custom MCU with a Atmega328, and I want to know how to incorporate a momentary pushbutton as a power switch - and then somehow also have it automatically turn off after a set time? Is this possible? How would it be done?
Possible, of course. How? I imagine there are many ways this could be done, but I would also be interested in simplest and most efficient way
Same here. Would a schematic of my current circuit help?
It won’t hurt
So let’s define params
The button is momentary push button
First push powers up the board
Second push sends a signal to the board and waits for response for 1 second, if no response, it powers down. Positive response power down immediately, Negative response, cancel power down
The same response pin (could be the same as listening pin) can be used to power down programmatically
Sounds good?
@killzone_kid
Yeah, that sounds great! Can I also have the MCU automatically power up whenever I plug the board into a USB port? When it gets plugged in, it charges the inbuilt lithium battery. I want the MCU to display on the OLED screen the charging status (ie. the screen displays a charging symbol when it is currently charging).
This is similar to what I want - how does the circuit look to you @killzone_kid?
If I go with this, everything will be in SMD packages, and as small as possible - I have serious space limitations on my PCB.
where is the circuit diagram?
I’m thinking second long push will power down board in 1s unless there is abort signal from the board. Enough time to start shutdown routine on the board. Also the button is monitored by the board so it immediately receives press event and then can measure how long user holds it. the board can shut power after 0.75s itself not waiting for default circuit timeout. default timeout there only for when there is no board involvement
That schematic in that instructable you linked is quite hard to read. Have a look at this one instead;
In order to have the push button turn off the Arduino as well, you can have a look at the schematic from this thread;
You may get some mileage out if this kind of thing, many problems addressed and solved:
a7
use Atmega sleep.
Wake it on button press.
Send it to sleep by time - or
Send it to sleep on button press.
This is circuit layout I use for boards that might require this same option:
(only one MOSFET Q3 or Q4 is installed, as required)
You want the mcu to be able to detect if the usb bus is powered on or not.
ez. the VBus also go to one pin, but said pin cannot be accessed by VBat (e.g. using a blocking diode).
The intent of displaying a "battery is charging" status is good, however displaying said pattern on-screen require the mcu to be awake. So any intent of not actually turning on the arduino is simply thrown out of the window. At least during the charging phase.
You can do that by a simple status LED (e.g. on the charging IC). And then pair it up with a simple latching pushbutton that will switch between powering on the arduino (or not).
The only difference is in the ability for the Arduino to decide whether it can safely power-off or not.
I am thinking about a S-R latch rather than a T-flop, however it requires the mcu to be functioning correctly for the S-R latch to work (and the mcu might not). In which case a hard kill (maybe a reset) might be required.
If you want a simple momentary-button toggle (that powers the chip or not), just built a T-flop. It's still more wasteful (because power is needed to maintain the state of the T-flop) than a latching pushbutton.
I would raise the value of C1 and R3, but it does seem to work in theory, and it circumnavigates the problem with unknown state of mcu pins upon boot
Very nice, I hand rolled something similar after some experimentation, but this looks better
I've built it a few times, works great.
I'm always open to revisions though, can you explain why you'd change those values, and to what?
It was a community effort. Lots of helpful users helped me get it right.