Need help with 2n3904 and pic18f458

Discussion in 'Embedded Systems and Microcontrollers' started by johnnyinwa, Oct 2, 2013.

  1. johnnyinwa

    Thread Starter Member

    Jun 24, 2013
    41
    1
    Heh guys,
    Please refer to the attached schematic diagram for my question. I would like to know the value in ohms for the three resistors marked "X" on my diagram. The X resistors protect the bases of the three 2n3904 general purpose transistors that turn on the 7 segments at the appropriate time. Please show me the math and how you reached the correct answer. In addition I would appreciate it if you would point out any glaring errors in my schematic. This is my first microcontroller project so any help would be appreciated! :confused:
    Thanks for your time guys.
     
  2. WBahn

    Moderator

    Mar 31, 2012
    17,715
    4,788
    Take the maximum current that each 7-segment display can draw (all segments on). As a rule of thumb, you want the base current to be 10% of that. The voltage at the transistor base (when on) will be about 0.7V.
     
  3. johnnyinwa

    Thread Starter Member

    Jun 24, 2013
    41
    1
    I could really use an answer to this problem. Can you do the math and tell me the value of the "x" resistors in my circuit (refer to the diagram in the original post). The current on each 7 segment is 70 milliamps with all segments on. The voltage from the chip to the base of the transistors is approximately five volts. Using ohm's law I get a value of 615 ohms for the transistors -- is this correct? Any help here would be appreciated. :)
     
  4. WBahn

    Moderator

    Mar 31, 2012
    17,715
    4,788
    I could, but then you will have learned nothing and that is not why I am here.

    I'll buy that. That means that each segment is pulling 10mA which means that you are dropping 3.3V across the 330Ω resistor. Assuming output voltages of 5V from the MCU, that leaves 1.7V (a tad less) for the LED in the segment. My guess is that you are actually pulling a bit less since I suspect the segment LEDs are probably dropping 2V or a bit more. But it's in the ballpark and using a total of 70mA when the actual total is probably closer to 60mA gives you some margin.

    Not if the transistor is operating properly. The voltage from the base to the emitter of the transistors, when on, should be about 0.7V. If the output of the MCU is 5V, then that should give you about 4.3V for the voltage across your X resistors.

    Transistors aren't resistors, so Ohm's law doesn't apply. For the base resistors, you will have about 4.3V across them and you want the base current to be about 10% of your 70mA collector current. So you want the resistors to be about

    Rx = 4.3V/7mA = 614Ω

    So, yes, you did it just right. You just didn't explain what you were doing too clearly.

    Now, you aren't going to find a 614Ω resistor. The nearest sizes in the E12 (10%) sequence are 560Ω or 680Ω, although finding the 630Ω option from the E24 (5%) sequence shouldn't be too difficult.

    Either choice (560Ω or 680Ω) should work fine. In fact, you can probably choose anything from about 330Ω up to about 10kΩ and you may not see much of a difference. Since you likely have some 1kΩ resistors laying around, try those and see if they work -- they almost certainly will work just fine.
     
  5. John P

    AAC Fanatic!

    Oct 14, 2008
    1,632
    224
    The problem there is that you'll never get 70mA out of the pins of the processor, and even if you could, 330 ohms will drop too much voltage to allow that much current. You really need to have transistors for both the digit drives as you have now, and the segment drives too. Then 3 volts at 70mA suggests that the current-limiting resistors would need to be something like 43 ohms.
     
  6. tracecom

    AAC Fanatic!

    Apr 16, 2010
    3,869
    1,393
    I don't see that. Each of the Port D pins only has to drive one segment, which is approximately 10-15 mA. What am I missing?
     
  7. John P

    AAC Fanatic!

    Oct 14, 2008
    1,632
    224
    Oops. I seem to be the one who missed something! I somehow got the idea that the the segment drive needs to be the same current as the digit drive, and it obviously doesn't. Seven segments at 10mA each add up to one digit at 70mA. But then each digit is only on for 1/3 of the time, so the current averaged over time is only 3.3mA; however, that ought to be enough for a small display viewed close up.
     
  8. johnnyinwa

    Thread Starter Member

    Jun 24, 2013
    41
    1
    I will try 680 ohms and see if the circuit works -- thank you for your replies -- much appreciated.
     
  9. johnnyinwa

    Thread Starter Member

    Jun 24, 2013
    41
    1
    Hey guys,
    I thought I would post an updated schematic of my project for anyone who is interested. I figure when the coding is done (in C) I will post that too so anyone that is interested can build the project.
     
  10. tracecom

    AAC Fanatic!

    Apr 16, 2010
    3,869
    1,393
    You should add a .33uF cap on the input of the 7805 and a .1uF cap on the output of the 7805. Although your circuit may work without them, the datasheet calls for both caps to prevent oscillation. A 10uF cap on the output is good insurance against noise.
     
  11. johnnyinwa

    Thread Starter Member

    Jun 24, 2013
    41
    1
    I got the two caps on the 7805 but what datasheet are we talking about? I assume it is the datasheet for the 7805 perhaps? What about the 10uF capacitor -- output of what? You must understand this is my first micro-controller project. Thank you for all of your posts guys.
     
  12. johnnyinwa

    Thread Starter Member

    Jun 24, 2013
    41
    1
    You were right on (tracecom) with the two capacitors on the 7805 -- thanks alot. They were in fact on the data sheet. :)
     
  13. johnnyinwa

    Thread Starter Member

    Jun 24, 2013
    41
    1
    I have posted my most recent schematic on my project so you guys can tell me what is wrong with it. Thank you for your time in this matter.
     
Loading...