PWM of 7-segment led with common anode?

Discussion in 'The Projects Forum' started by mbabayan, Oct 20, 2010.

  1. mbabayan

    Thread Starter Member

    Jul 12, 2010
    30
    1
    Hello,

    I'm trying to interface Arduino with 7-segment common anode indicator.
    I've got the basic functionality done;
    I'm basically sinking appropriate pins to LOW to enable segments. Anode is connected to +5v.

    Now, I need to dim the indicator depending on ambient light. I figured the photocell interfacing, etc. The issue I'm having is that I don't have enough PWM pins to drive all 7 segments.

    Instead, I am planning on PWM the common anode. Also, on the segment controlling pins, instead of going from HIGH to LOW to enable a segment, I'd keep it in LOW and switch from INPUT to OUTPUT.
    In OUTPUT, LOW will sink to ground, thus enabling the segment.
    In INPUT, LOW will disconnect from the pull-up thus effectively breaking the circuit.
    The PWM-d common anode should take care of variable brightness (I suppose). The issue is that total possible current through common anode is about 140 mA, which cannot be driven by a pin, so I have to include a transistor. I have included the schematic for reference - would this work?

    Thanks,
    -MB
     
    • gpi.png
      gpi.png
      File size:
      11.3 KB
      Views:
      257
  2. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    I think you should replace the transistor with a PNP one and decrease R8 to 470 ohms, then it should work well.
     
    Last edited: Oct 20, 2010
  3. mbabayan

    Thread Starter Member

    Jul 12, 2010
    30
    1
    Could you please elaborate more? I honestly don't follow.

    PWM here is a 0 to 5 pulse - As far as I understand, when it would be at 5, gate would be above emitter, the transistor would be open.
    Also, why particularly 470?

    Thank you,
    MB
     
  4. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    Markd77's on the right track, but it needs a bit more than that.

    You've stated that with all of the segments on, the 7-segment display LED's maximum current requirement is 140mA.

    So, you need 1/10 that much current in the base of a transistor to saturate it.

    Since your Vcc=5v, then:
    Rbase = (Vin - Vbe ) / (Ic / 10)
    where:
    Vin = the voltage output from your uC, referenced from the emitter of the transistor.
    Vbe = the voltage on the base referenced to the emitter when current is flowing through the BE junction.
    Ic = the desired collector current; in your case it's 140mA.

    So:
    Rbase = (-5v - (-0.8v)) / (-140mA / 10)
    Rbase = -4.2v / -14mA
    Rbase = 300 Ohms, which is a standard value of resistance.

    It's a good idea to also include a base return resistor. 3 to 5 times the base resistor value is a good target. I've added a 1.5k base return resistor to your schematic.

    Note that I've circled some areas that need junctions. It looks like you are using Cadsoft's Eagle. Junctions are required anyplace that a wire terminates in the middle of another wire, or more than one wire comes off of a terminal.

    Use the Erc function early, and use it often. If you try to make a PCB when you have errors in Erc, your life will really be unpleasant.

    Sparkfun.com has a good tutorial on Cadsoft Eagle. If you haven't gone through it, spend the time and do so. It will save you lots of grief later on.
     
    • gpi.png
      gpi.png
      File size:
      30.1 KB
      Views:
      67
  5. mbabayan

    Thread Starter Member

    Jul 12, 2010
    30
    1
    Thanks a lot for detailed explanation.
    Did some more reading too, it makes a lot more sense now.

    To clarify - I'd have to reverse the PWM to get the desired effect, right?
    - at 100% duty cycle the transistor will be closed.

    As far as the Eagle, thanks for the tip. - I actually wasn't trying to build schematic for the purposes of designing a PCB just yet. As of now, the project is a horror on the perfboard :)
    I might refactor it at some point though.
     
    Last edited: Oct 21, 2010
  6. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    Good. :)

    Correct. If D11 is high, the transistor will not source any current. If D11 is low, the transistor will be sourcing up to 140mA current.

    That's OK. Getting it to work and tidying things up is a good learning process.

    You might try laying out some PCB's once you get everything working. You don't necessarily actually have to make the boards, but it's good practice for when you actually do start making them.
     
  7. John P

    AAC Fanatic!

    Oct 14, 2008
    1,632
    224
    You could exchange the transistor for a P-channel MOSFET and eliminate the two resistors near the transistor, plus save some operating power. On the other hand, that'll be a little more expensive. Your choice.

    Oh, it has to be a "logic level" FET, but they're easy to find.
     
  8. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    Here's a P-ch logic level MOSFET in a TO-92 package that would work:
    http://search.digikey.com/scripts/DkSearch/dksus.dll?Detail&name=ZVP2106A-ND

    Even though you could connect it without using a resistor, I recommend using at least a 250 Ohm resistor from the gate to the I/O pin, as in case the MOSFET gate gets shorted to the drain or source terminal (a common failure mode) the resistor will protect the I/O pin from excessive current. Also, a resistor will keep the gate from "ringing" due to the C of the gate and the L of the interconnecting wiring.
     
Loading...