-
Pull-up hack for turning inputs into outputs and saving components
08/30/2018 at 21:55 • 0 commentsIn several of my projects I use the output of a microcontroller to control a bipolar transistor. For example one of my projects was a electronic water gun set. The users of the water guns carry wetness sensors connected to ATmega microcontrollers. If one of the microcontrollers detects the user has been “shooted” it disables his water gun temporally using a solenoid. The microcontroller supply voltage was 3 volts, but the CMOS circuit controlling the solenoid required three input signals with an H voltage of 6 volts. So I used this simple level shifter:
The problem is that I had to generate several of these signals and there was very little space for the circuit in the water gun. Of course I also wanted to reduce the number of components to solder because of my natural laziness so I removed the base resistor Rb. At first glance it is not possible to connect the output pins directly to the base of the transistors because the base–emitter junction works as a diode: If the voltage of the base were as high as the H voltage of the microcontroller then base current would be of some amperes. However, there is a way to do it safely. The key is that most microcontrollers integrate something similar to the base resistor, although for another purpose: They are supposed to be used as pull-ups for input pins. Since they are used to implement binary inputs they do not need to be -and are usually not- ohmic. As an application example, suppose you want to use an input pin of a microcontroller to see if a switch is open or closed. The following circuit can be used:
As shown in the picture, when a pin is configured as input the microcontroller can be instructed to connect it to Vcc through an internal pull-up. So, if the external switch is open the microcontroller will read a logical high at the input pin. Otherwise it will read a logical low. The current flowing through the internal pull-up is usually very low. However, depending on the microcontroller this current can be enough to saturate a bipolar transistor. So, what I did with my water gun was to connect the base of the bipolar transistors directly to the microcontroller pins and configure them as inputs instead of as outputs. By enabling or disabling the pull-up path I can put the transistor in saturation or in cut-off and control the solenoid as shown here:
This hack is also useful when the microcontroller does not have enough output pins for your needs. For example, recently I made a VGA to SCART adapter using a PIC10F322 microcontroller. This microcontroller has only four I/O pins (RA0, RA1, RA2, RA3) and a Configurable Logic Cell (CLC). I used the CLC to generate the composite sync signal of the SCART connector from the vertical and horizontal VGA sync signals. I wanted to use one of the output pins to control the SCART RGB status signal and the charge-pump DC-DC converter generating the 12 volts of the SCART CVBS status signal. Unfortunately, the CLC can only use the pins RA0, RA1 and RA2. The only I/O left, RA3, is an input pin. However, it has a selectable pull-up that, according to the manufacturer, can supply at least 25 μA. This is enough to saturate a BC547 transistor so I used the hack to turn RA3 into an output in this way: