Mcu output to capacitor (simple question :))

Discussion in 'General Electronics Chat' started by AlmightyJu, Jan 22, 2013.

  1. AlmightyJu

    Thread Starter New Member

    Oct 14, 2011
    20
    0
    Hi guys, I think I know the answer to this one but want to just check!

    In short is the "bad" attachment a big no no and the "good" is the right way?

    Details:
    I basically have an output from a pic (max 20ma) which is going to a transistor base, I want to put a capacitor on the base so when the pic output goes off it fades the transistor out, but without a resistor between the pic output and the capacitor how much current would it take? in theory the resistance would be 0 so to instantly fill 4.7uf would most likely be over 20mA, then after the cap is full it would go down to the intended 1mA? so I'm guessing my "bad" pic is really a no no, is that right?

    Thanks again :)
     
    • bad.png
      bad.png
      File size:
      33.7 KB
      Views:
      53
    • good.png
      good.png
      File size:
      33.7 KB
      Views:
      54
  2. radiohead

    Active Member

    May 28, 2009
    474
    31
    In my opinion, either one would work. However, the one without the additional resistor will discharge the capacitor faster than the one with the resistor. Have you breadboarded these circuits to prove/disprove your theory?
     
  3. nigelwright7557

    Senior Member

    May 10, 2008
    487
    71
    I would never drive an MCU into a capacitor.
    It puts a strain on the output pin.
    I would advise putting a small resistor in series.
     
  4. bug13

    Well-Known Member

    Feb 13, 2012
    1,208
    38
    I think I will do this:

    set the output pin high to charge the cap, then set the pin to input/high impedance state (disable pull up or pull down resistor), and let the cap discharge mainly through the base resistor.

    but I am no PIC expert, please let me know if I am wrong
     
  5. AlmightyJu

    Thread Starter New Member

    Oct 14, 2011
    20
    0
    Well it would happen so fast I have no way to measure the current drawn for a totally drained cap :/ I've tested it powering from 3V and the drain time is fine in series, I'm just unsure on the current draw while the cap charges without any resistance (well near none)

    That was my thinking

    The only downside to that is the cap would also drain through the pic, and without a resistor in the way its gonna get ugly so I'm just going to switch the output from a high state to charge the cap and set it low and the cap will drain to the base
     
  6. GopherT

    AAC Fanatic!

    Nov 23, 2012
    6,059
    3,823
    Good idea Bug13.

    When set as an input, the PIC's inpedence is high and drainage into the PIC would be very slow vs. draining through the Transistor. You could also replace R1 with a diode (or diode/resistor pair) to keep everything in your preferred direction.
     
  7. bug13

    Well-Known Member

    Feb 13, 2012
    1,208
    38
    I think if I am using a normal digital I/O pin (as input), the input impedance going to be in mega ohm range. the input leakage current is going to be so small that you can ignore it. (a few uA?)
     
  8. GopherT

    AAC Fanatic!

    Nov 23, 2012
    6,059
    3,823
    Another option would be to use all features of the PIC and your programming skills to pulse-width modulate the LED directly, running the duty cycle lower and lower until it is off. The only hardware that will take is a resistor and your LED.

    In the end, everything is a balance of hardware intensity and complexity vs. software intensity and complexity.
     
  9. AlmightyJu

    Thread Starter New Member

    Oct 14, 2011
    20
    0
    I'll have to take a look at the input impedance idea, didnt realise it was mohm range :eek: but that might be a nicer solution.

    I did originally plan to use PWM but its just so much easier with a cap :D

    You've given me quite a few ideas guys so thanks for the input :) gonna see what I come up with tomorrow
     
  10. GopherT

    AAC Fanatic!

    Nov 23, 2012
    6,059
    3,823
    Did you have a chance to breadboard your circuit yet? I think the LED will turn off much faster than you can notice with your eye. You might need a cap over 22uF to even notice a soft turn off. Something near 100 to 150 for a real slow 4-5 second shutdown.
     
  11. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,392
    1,606
    I doubt the cap will show any discernable dimming as it discharges. The transistor will basically be on or off, just delayed a tad. The only "dimming" occurs as the transistor is turning off

    bug's idea to charge the cap is very good, Microchip suggests similar schemes to boost a low voltage output to a higher voltage. But the cap is still a problem.

    PWM is the way to go here
     
  12. GopherT

    AAC Fanatic!

    Nov 23, 2012
    6,059
    3,823
    His goal was full on with a soft (slow) power off. I was just thinking his cap was too small to notice the slow shut-off effect with our slow human eyes.
     
  13. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    Might work with a MOSFET and a large resistance to ground. Doubtful with a bipolar transistor.

    PWM would be the simplest and lowest component count method, even a software pwm loop.
     
Loading...