Pages: [1]   Go Down
Author Topic: Yet another push-button Arduino power scheme  (Read 1537 times)
0 Members and 1 Guest are viewing this topic.
Siena Italia
Offline Offline
Full Member
***
Karma: 2
Posts: 149
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

There have been several discussions on the forum of how to turn an Arduino on and off using a momentary contact pushbutton and some electronics.  For a multi-node CAN bus project, with a 24V-DC power source, I need a bit more.  If the MCU is ON, but has been inactive for a while, it sends messages to stop all outputs, puts the other nodes on the network to sleep, puts the CAN controller and transceiver to sleep, and then puts itself into PWR_DOWN sleep.  Moreover, before turning power OFF, one node must do the same orderly shut down of the other nodes in the system.  I want one button to do all of this, and a simple push-on, push-off switching of DC will not do. 

I wanted the pushbutton to do three things:

(1) turn power ON if it is OFF
(2) turn power OFF, with an orderly shutdown of the CAN network,  if it is ON and the system is AWAKE
(3) interrupt SLEEP if the system is sleeping

The schematic of what I've come up with is attached as a jpg, and the attached zip contains pdf and DesignSpark files for the schematic and pcb layout, the data sheet for Recom R-78AAxx-0.5_SMD DC-DC converters, and a small sketch to show how I'm using it.  My test board was just built with through-hole components on a piece of scrap board, while the PCB (not yet ordered, so spotting errors would be appreciated) is formatted to mate with an Arduino Nano and with my CAN boards (already on hand and functioning), but has two extra rows of pads (as do the CAN boards) to make it easy to connect IO lines.

Here, I'll briefly describe the circuit.
The Recom (as for a number DC-DC switching converters from various manufacturers) has a sense pin (Vr in the schematic) that has to be either floating or high to turn the converter on.  The push-button connects 24V to the R1/R2 voltage divider to feed ~5V to Vr via diode D1.  R1 and R2 were chosen so that the voltage on Vr is within Recom's specs whether the 24V-nominal batteries are nearly discharged or if there's a battery charger still connected (i.e. from < 23.4 to > 29.4 volts).  These resistors are paralleled by a 10 uF capacitor to keep Vr high for a hefty RC time delay.  Vr is kept alive (through 47K current limiter R5) from pin A1 of the Nano, used as digital output, and R4 makes sure that pin A1 is pulled down if the Arduino power fails.  A1 is set OUTPUT, HIGH during Setup () thus keeping the DC-DC converter turned on.  Any pin could be used for this; A1 was not yet being used for other things. For a source voltage different from 24V, R1 and R2 would need to be changed.  Their sum should be kept about the same, however, to give the same RC delay.  As shown, the delay is sufficient to get Setup through the digitalWrite (A2, HIGH) instruction with a deliberate momentary push on the button, but not with just a "tap".

A single transistor inverts the voltage from the R1/R2 divider and this connects to Arduno pin 2 (= interrupt 0) which is configured as INPUT_HIGH.  I just used a 2N2222 and 100k bias and pull-down resistors for the trial board, but the schematic shows a transistor with those resistors buit-in.  Voltage can not get directly to the transistor's base from Vr because of D1.  Hence, pin 2 will go LOW whenever the pushbutton is pressed, then decay back to high when it is released.  If the Arduino is running, the sketch tests for digitalRead (2) == LOW to set A2 LOW and turn OFF the DC-DC converter.  If the Arduino is sleeping, pin 2 going low interrupts the sleep.  If the Arduino is OFF, the state of pin 2 is irrelevant except that the sketch must make sure that it goes low by the end of Setup so that a shutdown is not immediately triggered on entering Loop.

The actual CANbus master node sketch is quite lengthy and does lots of other things, and I'll eventually post something about that and the Nano-sized CAN boards.  For the demo sketch I've extracted just a few pieces from that, and added some lines so that you can see how it works with the Serial Monitor with or without having built an actual DC-DC board.

This circuit functions well and I think that I've designed it in a way that the Arduino is well protected.  Some of the more experienced people here, though, may find flaws.  If so, I'd dearly like to hear from you before I have boards made or, worse yet, fry something.

Ciao,
Lenny


* ON-OFF5 - Schematic.jpg (53.71 KB, 800x509 - viewed 70 times.)
* On_Off.zip (181.67 KB - downloaded 30 times.)
Logged

nr Bundaberg, Australia
Online Online
Tesla Member
***
Karma: 128
Posts: 8524
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Maybe you should use a modified Due with a SAM3X, that can do all that in the processor and has 2 CAN ports as well.

But in lieu of that I think your circuit will be OK. Why do you need the transistor?

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Siena Italia
Offline Offline
Full Member
***
Karma: 2
Posts: 149
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The Due is physically far too big for what I'm doing.  My network will have 4 nodes at different locations; four of my design, and one that is part of a commercial product.  The boxes must be kept small.  BTW, the due has 2 CAN controllers, but still needs to have external CAN transceivers.  Were I going to mass production with this I could think about using a due for development and then making a tiny, "bare" SAM3X board for the product, but I am just building this one network (and a very few others might want to copy it for their own use).  The Due, of course, does not have a 24 to 3.3V DC-DC converter either.  The Nano is quite sufficient for my needs.

There are two reasons for the transistor:

(1) I'm using the voltage on Vr to trigger external interrupt 0 (pin 2) to come out of PWR_DOWN sleep.  While with some trickery it is possible to use a HIGH signal for that interrupt [e.g. with interrupt (0, ISR, CHANGE) and careful arrangement of code to avoid timing problems ], the "standard" way is with an interrupt on LOW.

(2) Applying 5V to pin 2, even with large, current-limiting resistance, implies that at least for a moment there will be tension on a gate of an unpowered MCU.  By juggling resistor values, I was able to make a workable active-HIGH circuit, without transistor, that kept maximum current on pin 2 to less than 7.5 uA.  That's probably safe, but for the same parts count and only a few cents more cost, I figured it better to play it safe and make sure that there's never any voltage on an unpowered FET gate.

Ciao,
Lenny
Logged

nr Bundaberg, Australia
Online Online
Tesla Member
***
Karma: 128
Posts: 8524
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
The boxes must be kept small
You could use an LPC11C24, 32-bit ARM, TQFP48, can controller AND transceiver in the chip.

I'm planning to use them soon on a network project.

_____
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Artisan's Asylum, Somerville, MA, USA
Offline Offline
Newbie
*
Karma: 0
Posts: 37
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Just as a thought, once you get the circuits working properly, would it make any sense at all to spin a single board with just the minimum parts for the nano that you actually need?  Seems like that might help shrink the package, and possibly increase the safety by getting rid of any extra inputs that could cause problems...

I'm currently working on some lighting stuff that is far simpler, but that is what I'm planning to do once I get the circuit working.

ex-Gooserider
Logged

Pages: [1]   Go Up
Jump to: