xian
Posts: 51
Joined: Thu Nov 01, 2012 8:42 pm

Solid sate power switch

Fri Jan 25, 2013 6:07 pm

I have been working on a way to have a micro controller switch my Pi on and off. The reason is that I want to be able to run it as part of a larger battery powered system where the Pi doesn't need to be on all the time. This is the circuit I'm using:
Image
See the parts list. Note, I'm not using 78xx regulators as the image shows.

The microcontroller runs a program that watches the PB3 pin and keeps PB4 high all the time that PB3 is high and for 60 seconds afterwards. This means that a button press turns the Pi on for long enough for it to use GPIO17 (controlled by an init script) to hold PB3 high itself. When the Pi shuts down, PB3 goes low (or high-Z depending on shutdown stage), and a minute later it loses power. I am using a long timeout as it takes the Pi some time to boot to a point where GPIO17 can be brought high.

The SCLK, MISO & MOSI connections between the ATtiny85 and the Pi are to allow the Pi the program the micro controller using avrdude. This can be done without the Pi losing power as PB4 is pulled high by R5. These do not need to be included once the chip is programmed.

The one down side to this setup is that a fair bit of power is lost in Q1 while the Pi is running, the voltage drop is about 0.73 volts, bringing the Pi's system voltage down to 4.16V, woefully low. However it seems to run nicely. Does anyone know a better way of doing things regarding Q1 & Q2? I was thinking of using a MOSFET but can't find out how to drive one from a microcontroller output.


I the final version I will be using a different microcontroller with more IO pins available and won't have to mix the GPIO and push button signals. I'll also investigate the three states of the GPIO pin (high, low, and high-Z) and see if my microcontroller program can be a bit smarter.

User avatar
Burngate
Posts: 6302
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: Solid sate power switch

Sat Jan 26, 2013 11:51 am

xian wrote:The one down side to this setup is that a fair bit of power is lost in Q1 while the Pi is running, the voltage drop is about 0.73 volts, bringing the Pi's system voltage down to 4.16V, woefully low. However it seems to run nicely. Does anyone know a better way of doing things regarding Q1 & Q2? I was thinking of using a MOSFET but can't find out how to drive one from a microcontroller output.
If Q1 has 0.73v across it, then it's not fully saturated. This could be because Q2 cannot provide it with enough base current, because its base isn't being pulled high enough (I haven't done the calculation, this is just a first look)
If you swap Q2 with R1, then Q2 will have ~2.7v across 11k driving its base and should(?) be saturated, giving you ~4.3v across 1k = ~4.3mA into Q1 base which should be better

I couldn't find which regulator you're using for the 5v rail. What are you using?

1HzCoder
Posts: 31
Joined: Thu Jul 12, 2012 1:15 am
Location: Lower Alabama

Re: Solid sate power switch

Sat Jan 26, 2013 6:41 pm

Xian,
Actually, (proper) mosfets are easier to drive with an mcu than most transistors.
This one https://www.adafruit.com/products/355 will work with a Pi because the gate voltage only needs to be 2.5 volts, and is capable of many times the current needs of a Pi, it also has a very low RDS on, so virtually no voltage drop to waste as heat. I usually use smd mosfets, but that is because I can get free samples, and rarely need the kinds of current that TO220 components are rated for. Lots of tutorials on the web about connecting these up.
TomJ
Einstein once said you don't really understand anything until you can explain it to your Grandmother

xian
Posts: 51
Joined: Thu Nov 01, 2012 8:42 pm

Re: Solid sate power switch

Sat Jan 26, 2013 7:50 pm

The 5V regulator is a TSR-1 2450 (sorry I miss-typed it on the parts list as TSR 1.2450, fixed now) available from adafruit and farnell. I'm going to look into what sort of power saving can be made from using the 3.3V version and removing the Pi's linear regulator, but that's a future bit of research.

Also I swapped Q2 & R1 but it hasn't made a difference.
Image
Some of the resistor values have changed to ensure that the transistors saturate.
About 6mA flows through Q2 collector and Q1 base. This will saturate Q1 as the Pi only draws about 500-700mA and Q1 has a min Hfe of 1000. I'm still experiencing a voltage (Vce) across Q1 of about 0.7V. I have noticed that Q1's base does not fall below 3.47V even though Q2's collector is not above 0.02V when on. I still have no idea why the Pi's voltage is so low.

User avatar
Redrobes
Posts: 80
Joined: Mon Dec 26, 2011 9:19 pm
Location: S.W. UK
Contact: Website

Re: Solid sate power switch

Sat Jan 26, 2013 9:28 pm

Looking up a TIP126 it seems its a darlington so that maybe 0.7V is a normal figure for that type of transistor array. If I see the PDF spec sheet for it then it shows about 0.7V VCE for a 0.7A IC current. So all seems normal to me. For switching I think a FET is probably a more sensible choice.

feverish
Posts: 486
Joined: Wed Jun 27, 2012 2:29 pm

Re: Solid sate power switch

Sat Jan 26, 2013 9:43 pm

For use with an Arduino, I bought on ebay some Fotek ssr-25 da-h 25-A solid-state relays. These can be triggered from 3 to 30 vdc and can control 90 to 480 vac loads. I am in the middle of changing over to Raspi to drive them directly from the GPIO, if ever I can figure out a way to make wiringPi work with Lazarus. (Hint ! Hint !!)
If discrimination is not challenged then we are effectively in collusion with the perpetrators of such behaviour:-Oxford dictionaries

xian
Posts: 51
Joined: Thu Nov 01, 2012 8:42 pm

Re: Solid sate power switch

Wed Feb 06, 2013 11:04 pm

Thank you guys for your ideas, I have decided to go with a MOSFET and it works beautifully. For completeness here is the new circuit diagram:
Image
and the parts list and MCU code.

The line from GPIO4 to PD4 is used as an interrupt to signal to the RPi to do something, probably shut down. Writing a daemon to watch it execute a task is the next challenge.

Future plans are to update the MCU firmware to speak I2C so the pi can change some of the parameters, and to allow it to read battery voltage.

Return to “General discussion”