Page 1 of 1

Re: GPIO pins and ground

Posted: Wed May 09, 2012 9:25 pm
by brandon
It's been well discussed that the gpio pins can't  provide much 3.3v or 5v current so powering LED's and other electronics isn't possible without transistors or fets.

This got me wondering if the gpio pins can be used to pwm external circuits to ground.

The example case would be for using an IC or other electronics to provide the +5 or +12 for LED's, fets and such and then use the GPIO pins to short or pwm those circuits to ground.  Obviously load would still be limited but would the traces on the r-pi work for say a 5v @ 500ma, 1000ma, 3000ma, or more?  Or is it impossible to use the gpio pins in this way?

Re: GPIO pins and ground

Posted: Wed May 09, 2012 10:07 pm
by nick.mccloud
I think you are going to find out what blue smoke is all about in your near future

I very much doubt you can run anything other than 0v or 3.3v through the GPIO pins which are directly connected to the main chip.

I'd bet body parts on you not being able to run more than a few milliamps through either the chip and certainly not 500mA through the very tiny circuit board traces - the only ones setup for that sort of level are on the USB.

The good news is a couple of small resistors and a small transistor and you'll be good to go.

Re: GPIO pins and ground

Posted: Wed May 09, 2012 10:34 pm
by jbeale
In practice the GPIO pins can sink 30 mA absolute max (and the official maximum rating is only 16 mA). Also, they are 3.3V logic level and not 5V tolerant. Do not plan to put more than 3.3V on or 16 mA current through any GPIO pin, if you count on the Pi to be still working.

To control larger voltages and currents, you should be using external transistors, relays, etc.

Re: GPIO pins and ground

Posted: Thu May 10, 2012 12:05 am
by error404
Whether you're switching to ground or Vdd, the current must still pass through the SoC's miniscule bond wires and transistors. Sometimes you can get more current one way than the other, but not the sort of current you're looking for. You need an external switching device.

Re: GPIO pins and ground

Posted: Thu May 10, 2012 12:54 am
by mahjongg
3000mA, that is three whole amperes! You need traces at least 0,3mm wide for that, I'm afraid the small (micrometers thick) gold bonding wires to connect the pins (BGA) of the chip holder and the chip would simply vaporise at that kinds of currents!

The ground wire isn't something that magically can enhance the current transfer of the R-PI, its just a "return path".

jbeale is completely right, if you want to control that kind of currents (PWM or otherwise)
you need an external switching "agent", be it a chip, or a transistor....

Re: GPIO pins and ground

Posted: Thu May 10, 2012 3:16 am
by brandon
That all makes sense, I was thinking that was the case but being a CS rather than EE I didn't know.  Now to maybe find an IC that can handle higher switching loads for all 8 gpio pins...

Re: GPIO pins and ground

Posted: Thu May 10, 2012 5:00 am
by jbeale
Below are two example of such a driver board. They have their own output pins to support moderate currents up to 0.5 or 1.5 amps. You talk to them through I2C, and just yesterday there was a working I2C driver for the R-Pi announced.

http://jeelabs.net/projects/ha.....utput_Plug

The Output Plug is a small board containing an 8-bit I/O expander plus NPN darlington array. Each pin can sink up to 500 mA @ 50V. By connecting the common clamping diode line to the supply voltage, relays and other small inductive loads can be used.

http://jeelabs.net/projects/ha.....Motor_Plug

The board uses an I2C I/O expander to support the two motor drivers as well as 4 freely available I/O pins. ...based on the TC4424 chip, which is mainly intended for driving MOSFET chips, but which happens to also work well to drive small motors forward or backward. Motors with stall currents up to about 1.5A @ 4.5..18V should work just fine.

Re: GPIO pins and ground

Posted: Thu May 10, 2012 5:06 am
by error404
Or you could just use a high current buffer like the jellybean ULN2803, which is good for 500mA per output and you'd just hook it in series with the existing GPIO. Even 'simpler' you could just use any low Vgs MOSFET or a transistor and base resistor.

Re: GPIO pins and ground

Posted: Thu May 10, 2012 10:28 am
by Gert van Loo
brandon said:


It's been well discussed that the gpio pins can't  provide much 3.3v or 5v current so powering LED's and other electronics isn't possible without transistors or fets.

...

I don't know about 'other electronics' but you an easily drive LEDs from the GPIO pins. It has been demonstrated already. Also a modern high efficiency LED will light up with 1mA. I have used 470 Ohm with LED's straight from  the GPIO pins. No problem!

Re: GPIO pins and ground

Posted: Thu May 10, 2012 12:27 pm
by gordon@drogon.net
Gert said:


brandon said:


It's been well discussed that the gpio pins can't  provide much 3.3v or 5v current so powering LED's and other electronics isn't possible without transistors or fets.

...


I don't know about 'other electronics' but you an easily drive LEDs from the GPIO pins. It has been demonstrated already. Also a modern high efficiency LED will light up with 1mA. I have used 470 Ohm with LED's straight from  the GPIO pins. No problem!



Hurrah for modern LEDs! I've been driving some with 330 ohm resistors and they're very bright - my old (30+ year old) LEDs were somewhat DIM, but I splashed out on some new ones for the Pi!


Re: GPIO pins and ground

Posted: Thu May 10, 2012 2:18 pm
by brandon
My project is for 30+ G scale locomotives which have anything from a single small ma LED's to several high brightness LED's in series, 30 year old incandescent bulbs, smoke generators (5v .25A to 20v 1.4A units depending on locomotive age), and so on.

After doing some more research it does appear that the method companies are using to put DCC and RC control is by throwing 500ma transistors on the end of the circuit that connect the paths to ground (and there are reports of burning up those 500ma transistors on older smoke units).  So since this seems to be the method companies are taking I'll reproduce the same idea.  I found a TIP31A that does 3A for $.39 which should be a safe "catch all" for what I'm dealing with.  I don't imagine anyone knows of an IC that has 8 of these built into a single chip or another part that would help keep the prototype board smaller and/or cleaner looking?  Each locomotive will need 8 transistors so that's over 180 of these so if I can cut parts and other things down that would be helpful.

Re: GPIO pins and ground

Posted: Thu May 10, 2012 2:24 pm
by gordon@drogon.net
brandon said:


My project is for 30+ G scale locomotives which have anything from a single small ma LED's to several high brightness LED's in series, 30 year old incandescent bulbs, smoke generators (5v .25A to 20v 1.4A units depending on locomotive age), and so on.

After doing some more research it does appear that the method companies are using to put DCC and RC control is by throwing 500ma transistors on the end of the circuit that connect the paths to ground (and there are reports of burning up those 500ma transistors on older smoke units).  So since this seems to be the method companies are taking I'll reproduce the same idea.  I found a TIP31A that does 3A for $.39 which should be a safe "catch all" for what I'm dealing with.  I don't imagine anyone knows of an IC that has 8 of these built into a single chip or another part that would help keep the prototype board smaller and/or cleaner looking?  Each locomotive will need 8 transistors so that's over 180 of these so if I can cut parts and other things down that would be helpful.



Look at the ULN2003A series of darlington drivers. 7 in a package which can do up to 500mA each (IIRC) they can also be paired up for more current capacity.

Gordon

Re: GPIO pins and ground

Posted: Thu May 10, 2012 2:44 pm
by Dave_G_2
@brandon

You can also have a look at the uPA1526 made by NEC.

It has 4 power fets each rated at 28V @ 2A in a SIP10 package.

If your duty cycle is low, then they can handle up to 8 Amps.

Re: GPIO pins and ground

Posted: Thu May 10, 2012 5:21 pm
by brandon
Maybe I should have double majored…

So the only difference I see by looking at the chip datasheets between the ULN2803 and the ULN2003A is the 2803 has 8 channels rather than 7 as the 2003a does (same 500ma max and any voltage over 24v isn"t needed for my situation).  One thing I"m not understanding is what the com pin is for.  I could be wrong but I think it's the same as adding multiple transistors together for the "Darlington" multiplication?

From my research, I believe the specific chip I would need is a "low side" switch as I"m looking to just switch on grounding for the different circuits.  Now one issue may be that each Vc inputs could be anything from 3v to 20v pins 1-7/8 (if it"s a circuit of led"s, smoke, or something else) and I don"t want to assume all Vc"s can be different but from my reading it appears they can.

Also, can you use the r-pi"s gpio pins in a pwm manner to toggle the chips Vb quickly to dim leds or potentially pwm for servo"s or do these two chips not allow fast enough Vb switching for this?

Last, what happens when you burn out one of these chips, does the chip typically stop all currents or does it short out and thus could damage various circuits?

Thanks for the help.

Re: GPIO pins and ground

Posted: Thu May 10, 2012 5:39 pm
by gordon@drogon.net
brandon said:


Maybe I should have double majored…


Some of us are just old


So the only difference I see by looking at the chip datasheets between the ULN2803 and the ULN2003A is the 2803 has 8 channels rather than 7 as the 2003a does (same 500ma max and any voltage over 24v isn"t needed for my situation).  One thing I"m not understanding is what the com pin is for.  I could be wrong but I think it"s the same as adding multiple transistors together for the "Darlington" multiplication?


The COM pin can be ignored unless your driving inductive loads (relays) in which case connect it to the common +ve line that the relays are connected to.


From my research, I believe the specific chip I would need is a "low side" switch as I"m looking to just switch on grounding for the different circuits.  Now one issue may be that each Vc inputs could be anything from 3v to 20v pins 1-7/8 (if it"s a circuit of led"s, smoke, or something else) and I don"t want to assume all Vc"s can be different but from my reading it appears they can.


You might need one uln chip per different Vc supply...


Also, can you use the r-pi"s gpio pins in a pwm manner to toggle the chips Vb quickly to dim leds or potentially pwm for servo"s or do these two chips not allow fast enough Vb switching for this?


There is only ONE easilly avalable PWM output. The chip supports 2, but you can't easilly get the 2nd one out.


Last, what happens when you burn out one of these chips, does the chip typically stop all currents or does it short out and thus could damage various circuits?


I've been lucky enough to not burn one out..

It's just struck me though - you're going to need a lot more outputs than the Pi can provide! You have a maximum of 17 pins on the Pi (if you sacrifice serial, i2c and spi) My own thoughts might be to use something else to do the control - e.g. an Adruino Mega which has lots of digital IO and PWM, and just send it higher level commands from the Pi which is doing the overall control (and e.g. putting up a pretty picture on the display of the track layout, etc.)

Gordon

Re: GPIO pins and ground

Posted: Thu May 10, 2012 6:04 pm
by Gert van Loo
brandon said:


Maybe I should have double majored…

...
I did double major: Electronics and Computer science

Depending on what you need, you can use the higher voltage to your advantage. It allows you to put more LEDs in series thus drastically reducing the required current. But then all LEDs in that one chain go on and off at once.

The COM is if you have inductive loads and is connected to your supply. The diodes will then 'quench' any excessive inductive voltages. (look up on the internet  'switching relay off') It is NOT adding transistors together.

For switching LEDs on and off you can take one supply for all LEDs. Each output can cope with a different voltage but you must make sure all grounds are connected together.

The raspberry PI has a single PWM output on the GPIO connector. You can set the PWM speed and it can go slow enough that these chips will easily drive it. (See the Gertboard2 video on Youtube. It has a the PWM driving a motor bridge which is much slower then switching LEDs). If you want off/of individual lights and a common intensity control it gets a bit more complex. I would use one big high side switch controlled by the PWM and then low side switches for on/off.

You should never guess the failure mode of a device. You circuit should be basically safe.  On the other hand the probability of the high voltage coming back through the input into your PI is very low and the Raspberry-Pi is so cheap that I would take the risk.  Note that fuses do not always protect against this type of damage as the circuit can blow before the fuse. They do protect against things like fire risk.

Re: GPIO pins and ground

Posted: Thu May 10, 2012 6:13 pm
by brandon
GordonH said:

You might need one uln chip per different Vc supply...
What are the cases for "might"?

There is only ONE easilly avalable PWM output. The chip supports 2, but you can't easilly get the 2nd one out.
I'm assuming you're referring to the r-pi only having one easily available PWM output?  I may need to rethink this, I thought all the gpio's could be toggled on/off quickly?

It's just struck me though - you're going to need a lot more outputs than the Pi can provide! You have a maximum of 17 pins on the Pi (if you sacrifice serial, i2c and spi) My own thoughts might be to use something else to do the control - e.g. an Adruino Mega which has lots of digital IO and PWM, and just send it higher level commands from the Pi which is doing the overall control (and e.g. putting up a pretty picture on the display of the track layout, etc.)
Gordon


I can get by with fewer but my current idea was to have individual control over:

Front headlights

Rear headlights

Interior Cab light

Smoke Unit

Ditch Lights (there are two led's and they either are both on or they cross fade with each other -- this is what I wanted to PWM for, so I could have a gpio for each headlight and pwm them independently to dim/cross fade when needed)

So I'd need 6 channels/gpio pins ideally.  In the future I might also do servo controlled couplers but not atm and they would have two states obviously, open or closed so I'd need 8 channels/gpio pins at most.

I don't think there's anything I'd use serial for.  I want to keep wiring/circuits as simple as possible (I'm planning on making this all plug into the G scale plug-n-play sockets so it's a drop in solution) and I'm already writing software to automate a layout based on rfid tags under the track and each locomotive will have a rfid reader and wifi so trains can talk thus make this all easy for other hobbiests to implement, including even outside of Garden Railroading.

Re: GPIO pins and ground

Posted: Thu May 10, 2012 6:25 pm
by gordon@drogon.net
brandon said:


GordonH said:


You might need one uln chip per different Vc supply...


What are the cases for "might"?


Well, everycase. If you have a set of 5v for LEDs, then 12V for bulbs, then 2 driver chips, etc.



There is only ONE easilly avalable PWM output. The chip supports 2, but you can't easilly get the 2nd one out.


I'm assuming you're referring to the r-pi only having one easily available PWM output?  I may need to rethink this, I thought all the gpio's could be toggled on/off quickly?


There is one pin that can be controlled in a PWM fashion by the hardware - you write a value and it gets on with it.

You can toggle the other pins on & off - but it will need a very tight-loop of a program to do it to achieve something usable - and that will leave nothing left for other program to run and it will not be smooth as Linux will periodically interrupt the program to do something else...



It's just struck me though - you're going to need a lot more outputs than the Pi can provide! You have a maximum of 17 pins on the Pi (if you sacrifice serial, i2c and spi) My own thoughts might be to use something else to do the control - e.g. an Adruino Mega which has lots of digital IO and PWM, and just send it higher level commands from the Pi which is doing the overall control (and e.g. putting up a pretty picture on the display of the track layout, etc.)
Gordon


I can get by with fewer but my current idea was to have individual control over:

Front headlights

Rear headlights

Interior Cab light

Smoke Unit

Ditch Lights (there are two led's and they either are both on or they cross fade with each other -- this is what I wanted to PWM for, so I could have a gpio for each headlight and pwm them independently to dim/cross fade when needed)


Now here is an intersting thing - You can cross fade 2 LEDs with one PWM output. You wire the pin via a series resistor (e.g. 220 ohms) then to the mid-point of 2 LEDs wired from +3.3 to ground in reverse. When the output pin is high, one LED will light, when it's low the other will light. Make that the PWM pin and you can cross-fade from one to the other... I've done this on my Pi.


So I'd need 6 channels/gpio pins ideally.  In the future I might also do servo controlled couplers but not atm and they would have two states obviously, open or closed so I'd need 8 channels/gpio pins at most.


sounds like enough then.


I don't think there's anything I'd use serial for.  I want to keep wiring/circuits as simple as possible (I'm planning on making this all plug into the G scale plug-n-play sockets so it's a drop in solution) and I'm already writing software to automate a layout based on rfid tags under the track and each locomotive will have a rfid reader and wifi so trains can talk thus make this all easy for other hobbiests to implement, including even outside of Garden Railroading.


So are you putting a Pi on each train? Have to say, I'd probably use something else for this like an arduino, however the Pi solution might be "cooler" ...

Gordon

Re: GPIO pins and ground

Posted: Thu May 10, 2012 6:32 pm
by brandon
Gert: I'll keep re-reading your post, I understand 95% of it and the other 5% will click with some more research I'm sure, thanks.

I was planning on using the gertboard but then I started to wonder if there were enough resources just with the r-pi gpio's to do what I need.

The ditch lights/pwm need is actually already in some of the locomotives (the circuit waits for motor voltage to go over about 7v and it automatically switches from cross fade to solid) so I could actually control that with a single switch but I was considering adding ditch lights to other locomotives but if the first idea I had using pwm doesn't work I could just make a circuit that on 0v they cross fade and on 3v they go solid.

High-side switching I'm learning now (after looking at wiring diagrams of and physical wiring in the locomotives) would be less desirable since the locomotives already have the wiring done a certain way that works well and the plug-n-play sockets are all designed as low-side switches to toggle functionality.  Basically I just pull a dummy plug off their plug-n-play sockets and insert a header that goes back to a IC of transistors that's controlled by r-pi gpio pins or pins on a gertboard.  I was originally considering re-wiring all the locomotives from scratch but now that I understand how the plug-n-play sockets work I think this would be the best solution, especially if I want to make it easiest for others to do too.

Re: GPIO pins and ground

Posted: Thu May 10, 2012 6:38 pm
by brandon
GordonH said:

Now here is an intersting thing - You can cross fade 2 LEDs with one PWM output. You wire the pin via a series resistor (e.g. 220 ohms) then to the mid-point of 2 LEDs wired from +3.3 to ground in reverse. When the output pin is high, one LED will light, when it's low the other will light. Make that the PWM pin and you can cross-fade from one to the other... I've done this on my Pi.
This will work too, just more parts which is fine, I was hoping to do it in software and keep part #'s lower is all.

So are you putting a Pi on each train? Have to say, I'd probably use something else for this like an arduino, however the Pi solution might be "cooler" ...
Gordon


I plan on adding usb cameras to some cabs, playing dynamic sounds/mp3's, having each train web and network api enabled for simple remote control, so I've been waiting almost a year for the r-pi to do all this rather than going the arduino route.  And yes, there's a cool factor -- I've been a linux guy for over 20 years and I've always wanted to do this.

Re: GPIO pins and ground

Posted: Thu May 10, 2012 6:51 pm
by error404
You can probably get away with low frequency, low resolution PWM in software but it may be difficult to get consistent brightness.

Low side switching is better if you can use it; you don't need to connect to the (possibly multiple) power supplies, don't need a gate driver or bootstrapping, the parts are less lossy and more readily available, and it's positive logic.

Re: GPIO pins and ground

Posted: Thu May 10, 2012 9:25 pm
by brandon
On the need of a different IC package for each voltage, I have a couple questions.

Obviously there's a single voltage input, the battery (or track power).  A locomotive circuit often has several voltage regulators and PWM packages for different effects. Considering there's one voltage input does that mean I only need one transistor IC package (I think this is the right term?), or do I need to use a different transistor package for each voltage regulator/each time a voltage regulator is used?  I understand now how pin 10 is used to feed voltage back to the circuit to prevent back-emf/voltage spiking from an inductive load, though I won't be dealing with any inductive items I believe.

If someone is curious and wouldn't mind looking at a locomotive circuit, here's a circuit for one locomotive: http://www.girr.org/girr/tips/.....pcb-01.gif

How many transistor ic packages are needed for this diagram?

Re: GPIO pins and ground

Posted: Fri May 11, 2012 12:41 am
by error404
If you switch the low side, it doesn't matter how many or what voltage the supplies are, as long as they're below the transistor's maximum Vce voltage rating.

Re: GPIO pins and ground

Posted: Fri May 11, 2012 8:41 pm
by brandon
So here"s a VERY crude layout of my plan based of what has been talked about. This drawing will probably scare just about anyone because it"s ugly, I"ve never used geda before and don"t know how to use it, lacks information, and uses "nets" to show basic USB connection between devices — Nasty.   But hopefully this idea will work.

This drawing is how I"d connect to the standard aristocraft/dcc/plug-n-play headers (2 of them, though the second aux is only used to attach to the speaker) so ditch lights and automatic couplers that will be aftermarket modifications aren"t shown.  I did separated out the smoke units 16transistor as this needs to be able to sink 1.5A so it will probably be on its own.