2
\$\begingroup\$

I'm trying to use a microcontroller (pic) to control external LEDs that are powered by batteries.

The actual control of the LED is working fine. I set an output pin high, and that drives a transistor that controls the LED.

What I'm looking for is a hardware circuit between the pic output pin and the transistor so that if the pic stops (while I'm debugging for example), the LED doesn't draw down all the power in my batteries. I think the circuit should probably short the output to ground after a second or two?

I assume there must be something based on a RC circuit that could be used, but I have no idea what it is called or how to set it up.

Any ideas would be appreciated.

\$\endgroup\$
7
  • 1
    \$\begingroup\$ Google watchdog timer. \$\endgroup\$
    – winny
    Commented Oct 23, 2017 at 16:42
  • \$\begingroup\$ Is the output that drives the LED a simple DC control signal or is it normally PWM. \$\endgroup\$
    – Trevor_G
    Commented Oct 23, 2017 at 16:53
  • 1
    \$\begingroup\$ You could put jumpers between your outputs and what they control, with pull-downs (or pull-ups as appropriate) so that the controlled outputs have a default condition they arrive at when disconnected from their driving pins. You'd have to manually pull them when debugging. There are automatic circuits, but that would be even more space and money. \$\endgroup\$
    – jonk
    Commented Oct 23, 2017 at 16:58
  • 1
    \$\begingroup\$ Do you have some other output you can toggle continuously in your main loop? \$\endgroup\$
    – Trevor_G
    Commented Oct 23, 2017 at 17:14
  • 1
    \$\begingroup\$ Replace the transistor with a mosfet and drive thew gate with a charge pump, you must then keep toggling the output to keep the mosfet turned on. Static high or low will cause the leds to go out in short order. \$\endgroup\$
    – Dan Mills
    Commented Oct 23, 2017 at 17:33

2 Answers 2

3
\$\begingroup\$

If you have another IO pin you can toggle at say 1kHz in your main loop in the processor, you can use it through a charge pump to store a charge on the gate of a MOSFET. The MOSFET should turn on when the clock is running and you can use the MOSFET to act as an additional switch in your LED drive or otherwise integrate it into the driver logic.

Some tuning of component sizes is required, MOSFET should have a low value threshold.

schematic

simulate this circuit – Schematic created using CircuitLab

Note: You could simply replace your current turn on circuit with this one and have the turn on function send out a suitable square wave instead of a DC level.

\$\endgroup\$
1
\$\begingroup\$

schematic

simulate this circuit – Schematic created using CircuitLab

I came up with this circuit myself and have neither simulated nor built it, so I very highly recommend you take this as a "concept" rather than a fully built circuit. The parts are arbitrarily picked (treat the 2N3904 simply as an arbitrary NPN etc.). As I don't know what kinds of transistors you're using I just used an NPN for your driving transistor.

D2, R4, Q1, and R3 are all parts that I assumed are in your circuit. The remaining parts make up the circuit I've added.

Let us assume the driving pin is high: The circuit begins with C1 initially at 0 volts, charging through R1 and R2. As the voltage over Q2's base-emitter section is well below it's threshold to sink any current through the collector, nearly no current is drawn. The circuit behaves as if nothing is happening and acts as you originally intended. As C1 charges through R1 and R2, Q2 begins to turn on a little bit and the voltage at Q1's base drops a small amount as Q2's collector begins pulling more current. As C1 charges further, eventually Q2 is on enough so that the voltage at Q1's base isn't enough to drive the transistor to drive the LED (around 0.6 volts or so probably), and thus Q1 is turned off after a delay.

When the driving pin goes low, the capacitor will discharge quickly through R1, much faster than it does through R2 and R1, resetting the circuit in about 100th of the time as it takes to be set in the first place (100 being roughly the ratio between R1 and R2).

Again, the values I've picked are arbitrary so you will likely have to experiment with R1 and R2 values until you find a delay that works for you. R1 I would say should always be 100 ohms or greater to protect the driving pin being damaged when the capacitor discharges. The R2:R1 ratio should be kept large to allow for fast discharge times, keep R2 at least 10 times greater than R1 I would say. C1 can be basically any value you want, but you'll probably end up with something around 1 microfarad. Q2 needs to be an NPN for this to work in it's current form, however the concept should be convertible to a form that uses any transistors you happen to be using. Q1 just needs to be a transistor that turns the LED on when the base is at a high voltage relative to it's grounded side (which I assumed was how your circuit works).

The time this circuit takes until it "activates" is dependant on R1, R2, and C1. Assuming the circuit activates once C1 has charged to about 1 volt and the driving pin uses 5V logic, I would estimate the time to activate would be (R1 + R2)*C1/5 or so. This a quick estimate based on the fact that the time it takes for the capacitor to charge up about 2/3 of the way is (R1 + R2)*C1.

Again, don't take this circuit for gospel as I have put this together very quickly. I recommend making your own version simply based on these ideas and then simulating and building it.

EDIT: As pipe pointed out, my value for R3 is too small, as it will allow ~5mA to flow while the LED is off. Replacing it with a larger value (20K or so) would make the circuit work with much less current draw. Increasing this value too high will prevent Q1 from being able to turn on at all, you will probably start having problems around 100K (another rough estimate).

\$\endgroup\$
4
  • 2
    \$\begingroup\$ If I'm not mistaken, at least 5 mA will flow through R3 while the protection circuit is activated. This negates the usefulness, since the idea was to prevent the LED current to deplete the battery. 5 mA is about the same order of magnitude as the LED. \$\endgroup\$
    – pipe
    Commented Oct 23, 2017 at 18:25
  • \$\begingroup\$ My mistake, you are correct. R3 should probably be a much larger value, I will edit my answer. \$\endgroup\$ Commented Oct 23, 2017 at 18:32
  • \$\begingroup\$ This approach looks very promising. One question though, what purpose does D1 serve? Can this diode be skipped? \$\endgroup\$ Commented Oct 23, 2017 at 19:01
  • \$\begingroup\$ D1 allows there to be a short over R2 while C1 is discharging, which speeds up the discharge by a lot. If you don't include D1, the time it takes for the capacitor to discharge will be the same as it takes to charge, so it may not be completely discharged in between cycles of the driving pin going high to low to high. If C1 isn't completely discharged, then it will take less time to charge up to triggering voltage on the next high, and the timer will be triggered in less time than if it was completely discharged. Unless you're always low for longer than you are high, it's required. \$\endgroup\$ Commented Oct 23, 2017 at 19:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.