dah85
Posts: 3
Joined: Mon Nov 04, 2019 5:56 pm

Use GPIO for PWM in "open collector mode" ?

Mon Nov 04, 2019 6:16 pm

Hi,

I am trying to apply a PWM signal to a high power LED.
For that, I am following this tutorial on building a CC source that can be interfaced with a microcontroller: https://www.instructables.com/id/Circui ... ower-LED-s
The following diagram from the website shows the circuit that I am going to use:
Image

In the description it says:
if your micro-controller is 3.3V or less, you need to use circuit #4, and set your micro-controller's output pin to be "open collector" - which allows the micro to pull down the pin, but lets the R1 resistor pull it up to 5V which is needed to fully turn on Q2.
Maybe I am too stupid to understand this ... does this mean that there should be a software setting called "open collector" that I have to use when I initialize the GPIO pin in python (like initializing an input pin and setting the initial value to high or low)?
The search gave me lots of hits for "open collector", but I couldn't find any that was dealing with a software setting ...

How do I set my GPIO pin to "open collector" mode?? Or does it mean something completely different?

Thank you!

PiGraham
Posts: 4205
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: Use GPIO for PWM in "open collector mode" ?

Mon Nov 04, 2019 6:35 pm

You can't connect RPi gpio like that. The LED supply voltage is almost certainly too high for a Pi (3.3V)

You could add a second transistor like Q1. Lets call it Q3. Connect collector to collector and emitter to emitter.
Drive the base from your gpio output through a 100 ohm resistor.

When the GPIO is high Q3 tuerns on and disables the FET. When gpio is low Q3 is off and Q2 regulates the current.

Q3 serve as the "open collector".

I don't know of micros / microcontrollers with gpio that can operate open collecter at high voltages.

dah85
Posts: 3
Joined: Mon Nov 04, 2019 5:56 pm

Re: Use GPIO for PWM in "open collector mode" ?

Wed Nov 06, 2019 4:53 pm

Thanks! Sounds good!
So "open collector" is a term that refers to switching via (another) transistor?
I don't know of micros / microcontrollers with gpio that can operate open collecter at high voltages.
I thought most microcontrollers operate at 5V (the arduino does that too).

I came across another alternative that was recommended by some physicists: I can simply bump up the voltage of the PWM signal to 5V with a level shifter (https://www.sparkfun.com/products/12009).

I will try both options. Thanks!

User avatar
rpdom
Posts: 17732
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Use GPIO for PWM in "open collector mode" ?

Wed Nov 06, 2019 5:02 pm

dah85 wrote:
Wed Nov 06, 2019 4:53 pm
I thought most microcontrollers operate at 5V
Many microcontrollers run at various voltages. The PIC range,for example, can run from 2V upwards, depending on the chip.

Also, the Pi is not a microcontroller. It is a computer.
Unreadable squiggle

PiGraham
Posts: 4205
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: Use GPIO for PWM in "open collector mode" ?

Wed Nov 06, 2019 11:28 pm

dah85 wrote:
Wed Nov 06, 2019 4:53 pm
Thanks! Sounds good!
So "open collector" is a term that refers to switching via (another) transistor?
Not it means the collector of the output transistor is not tied to another transistor or a pullup to a voltage rail. That it is, the collector is free to float at any applied voltage when the transistor is off.

The significance of that is you can connect muktiple such open collectors together and any one can pull the common line to ground.

In the LED circuit there is a current control transistor controlling the gate of the MOSFET. That could be at relatively high voltages. An open collector connected to that line can override, pulling it to ground, and when off, will allow the line to float at whatever level the rest of the circuit needs.
dah85 wrote:
Wed Nov 06, 2019 4:53 pm
I don't know of micros / microcontrollers with gpio that can operate open collecter at high voltages.
I thought most microcontrollers operate at 5V (the arduino does that too).
LED drive cicuit could drive lots of LED in series. In that case the voltages could be well above 5V. The sketch shows three LEDs which could just work with 5V. High brightness blue LED would need >6V and ten LEDs would need 16 to 20V. Note that R1 is a pullup to that power rail. The control device must be able to cope with that voltage.
dah85 wrote:
Wed Nov 06, 2019 4:53 pm
I came across another alternative that was recommended by some physicists: I can simply bump up the voltage of the PWM signal to 5V with a level shifter (https://www.sparkfun.com/products/12009).

I will try both options. Thanks!
You can use a level shifter, but you should take note of the voltage on the line you need to control. Don't assume anything is 5V

dah85
Posts: 3
Joined: Mon Nov 04, 2019 5:56 pm

Re: Use GPIO for PWM in "open collector mode" ?

Wed Nov 13, 2019 6:25 pm

Hi all,

I just wanted to say thank you! My project is completed!

In the end, the level shifter didn't do what I wanted. I ended up using a PNP transistor to modulate the signal. With the PNP the gate is open to ground and the LED is off.

Thank you!

Return to “General discussion”