Connect with us

lighting a 7 segment LED

Discussion in 'Microcontrollers, Programming and IoT' started by foTONICS, Nov 11, 2013.

Thread Status:
Not open for further replies.
  1. foTONICS

    foTONICS

    332
    9
    Sep 30, 2011
    Hey all,

    I'm writing some code that counts the number of times an interrupt has occurred then displays it on the 7-segment display. When it comes to lighting each individual segment (a,b,c,d,e,f,g) is it normal practice to light all of them at once or in sequence? I ask because I've noticed when I have the number 8 displayed the LED's dim.

    I'm using a common-anode 7-segment display, a PIC16f627a, and a PICKIT2 programmer. I'm powering the circuit from the PICKIT.
     
  2. GreenGiant

    GreenGiant

    830
    5
    Feb 9, 2012
    it shouldnt matter if its all at once or together, my only thoughts are that you dont have the juice to power all the sections at once at full power, or there are some that do dim when all are on regardless of the power supplied to them.
     
  3. foTONICS

    foTONICS

    332
    9
    Sep 30, 2011
    I'm thinking that it's that I just don't have the juice because the same segments that light when a "1" is shown are brighter than when a "8" is shown
     
  4. foTONICS

    foTONICS

    332
    9
    Sep 30, 2011
    I was just being paranoid because I didn't want to damage my programmer by powering all 7 at once
     
  5. (*steve*)

    (*steve*) ¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd Moderator

    25,191
    2,692
    Jan 21, 2010
    Generally speaking you power all segments at the same time.

    If you are multiplexing, you generally display a digit at a time, although you could also display a segment at a time (over all displays).

    The important thing to note about multiplexing is that if you're multiplexing n things, the current should be n times the current required to get the brightness you want.

    I suspect that you are multiplexing the wrong way (and possibly unnecessarily)

    If you were to multiplex the segments, you should display a, b, c, d, e, f, g, dp. You allocate a time slice even if the segment is not lit.

    The correct way to display an 8 is a(on), b(on), c(on), d(on), e(on), f(on), g(on), dp(off)...

    The correct way to display a 1 is a(off), b(on), c(on), d(off), e(off), f(off), g(off), dp(off)...

    I suspect that what you are doing is:

    8: a(on), b(on), c(on), d(on), e(on), f(on), g(on)...
    1: b(on), c(on)...

    In my approach (it's not my approach by the way) each segment, when on is on for 1/8th of the time.

    In your case, for the 8, the segments are on for 1/7th of the time (you may not notice a significant difference), but for a 1, they are on for 1/2 of the time. The 1 will appear much brighter.

    You could reduce the current (that's hard), or display all the segments at once (that's probably best), or you could go through all the segments whether they are alight or not and only turn the ones on that need to be turned on, ensuring they get the same share of time and so appear the same brightness.
     
  6. KrisBlueNZ

    KrisBlueNZ Sadly passed away in 2015

    8,393
    1,266
    Nov 28, 2011
    Other possible reasons for the display being dim when more segments are lit are:

    1. The microcontroller may not be able to supply the necessary current when several outputs are driving LEDs directly. In this case you can use emitter followers between the outputs and the segments. For common cathode displays use NPN emitter followers with their collectors tied to VCC. For common anode displays use PNP emitter followers with their collectors tied to 0V. These will drop about 0.8V each so you will need to reduce the current limiting resistors accordingly, and if your supply rail is 3.3V or less, there may not be enough voltage to light the segments at all.

    2. The device that switches the common terminal of the display may not be able to handle the current and may be going out of saturation. Normally the common terminal is driven with a transistor or MOSFET that is controlled by a digit enable output on the micro. If the base resistor is too high, or if the gate-source voltage is not enough to fully saturate the MOSFET (e.g. if you're not using a "logic level gate" MOSFET), the device will drop voltage as the total current rises.

    3. If you're using a single resistor in path to the common terminal of the display to limit the current, you will see this effect. You need to have a separate current limiting resistor for each segment, although you can common the digits up, i.e. microcontroller segment "A" output --> (emitter follower if required) --> resistor --> first digit A segment, second digit A segment, third digit A segment, etc, and ditto for segments B~G or B~H. So you need seven or eight current limiting resistors, and you must not use resistors in series with the common terminals of the digits.

    4. Possibly the supply rail is dropping because it can't supply enough total current.
     
  7. dncky

    dncky

    15
    0
    Nov 10, 2013
    Schemtic for the current emitter setup?
     
  8. KrisBlueNZ

    KrisBlueNZ Sadly passed away in 2015

    8,393
    1,266
    Nov 28, 2011
    Emitter follower?

    To use a transistor to increase the output current capability of a microcontroller pin that is driving the segment pin(s) of one or more seven-segment LED displays:

    Base driven directly by I/O pin that controls the segment.
    Collector tied to VCC (for common cathode displays with NPN segment buffer transistors) or 0V (for common anode displays with PNP segment buffer transistors).
    Emitter connected through current limiting resistor to appropriate segment pin of all digit displays.

    A separate transistor and current limiting resistor is required for each segment.

    This assumes that the VCC supply voltage is high enough to drive the displays, including the added 0.8V (approx) that is lost in the emitter follower.

    https://en.wikipedia.org/wiki/Common_collector
     
  9. gorgon

    gorgon

    603
    23
    Jun 6, 2011
    It could be interesting to see the actual schematics used in this applicarion, since all the comments are based on the commenters own definition of what they understand.

    The OP does not say anything of how many 7-segment displays he use in this application, and from the text it looks like only one is used. The current limiting resistors are not described either, and if none is present, it could be the reason for the dimming of the display with the increased number of segments lit.
     
  10. KrisBlueNZ

    KrisBlueNZ Sadly passed away in 2015

    8,393
    1,266
    Nov 28, 2011
    I agree that it would be useful to see the schematic.

    My comments are based on all the possible mistakes I could think of that someone could make when connecting one or more seven segment displays to a microcontroller. It's up to the OP to read my comments and figure out which mistake(s) are present in his design.

    Or he could post the schematic and let us do that for him.
     
  11. foTONICS

    foTONICS

    332
    9
    Sep 30, 2011
    //Here is what my code looks like

    #include <xc.h>

    #pragma config FOSC = INTOSCIO // Oscillator Selection bits (INTOSC oscillator: CLKOUT function on RA6/OSC2/CLKOUT pin, I/O function on RA7/OSC1/CLKIN)
    #pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)
    #pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
    #pragma config MCLRE = OFF // RA5/MCLR/VPP Pin Function Select bit (RA5/MCLR/VPP pin function is digital input, MCLR internally tied to VDD)
    #pragma config BOREN = OFF // Brown-out Detect Enable bit (BOD disabled)
    #pragma config LVP = OFF // Low-Voltage Programming Enable bit (RB4/PGM pin has PGM function, low-voltage programming enabled)
    #pragma config CPD = OFF // Data EE Memory Code Protection bit (Data memory code protection off)
    #pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off)

    #define sF_LED sPORTB.port

    int delay=0,cnt=0;

    //rb0=N/A
    //rb1=e
    //rb2=f
    //rb3=a
    //rb4=c
    //rb5=d
    //rb6=g
    //rb7=b
    int zero= 0b10111110;
    int one= 0b10010000;
    int two= 0b11101010;
    int three= 0b11111000;
    int four= 0b11010100;
    int five= 0b01111100;
    int six= 0b01111110;
    int seven= 0b10011000;
    int eight= 0b11111111;
    int nine= 0b11111100;

    volatile union
    {
    int port;
    struct
    {
    unsigned RB0 : 1;
    unsigned RB1 : 1;
    unsigned RB2 : 1;
    unsigned RB3 : 1;
    unsigned RB4 : 1;
    unsigned RB5 : 1;
    unsigned RB6 : 1;
    unsigned RB7 : 1;
    };
    }sPORTB;

    main(void)
    {
    //configure port
    PORTB=0;
    sPORTB.port = 0;
    TRISB=0x00;

    //configure Timer0
    OPTION_REGbits.T0CS=0;
    OPTION_REGbits.PSA=0;
    OPTION_REGbits.PS=0b111;

    //enable interrupts
    INTCONbits.T0IE=1;
    ei();

    //main loop
    for ( ; ; )
    {
    //continually copy shadow PORTB to port
    PORTB=~sF_LED;

    }
    }

    //interrupt service routine
    void interrupt isr(void)
    {
    //service Timer0 ISR
    INTCONbits.T0IF=0; //clear interrupt flag

    if(++delay>1)
    {delay=0;

    if (++cnt==10)
    {cnt=0;}
    switch (cnt)
    {
    case 0: sF_LED=zero;
    break;
    case 1: sF_LED=one;
    break;
    case 2: sF_LED=two;
    break;
    case 3: sF_LED=three;
    break;
    case 4: sF_LED=four;
    break;
    case 5: sF_LED=five;
    break;
    case 6: sF_LED=six;
    break;
    case 7: sF_LED=seven;
    break;
    case 8: sF_LED=eight;
    break;
    case 9: sF_LED=nine;
    break;
    }
    }
    }
     
  12. KrisBlueNZ

    KrisBlueNZ Sadly passed away in 2015

    8,393
    1,266
    Nov 28, 2011
    Code != schematic
     
    Mark2019 likes this.
  13. foTONICS

    foTONICS

    332
    9
    Sep 30, 2011
    I don't have a schematic handy but basically I have:

    -The PIC16f627a powered by the PICKIT2
    -A 1K ohm resistor connecting Vpp to the common anode of the 7 segment display
    -I am using only one 7 segment display
    -Each cathode of the display connected by hook-up wire to a pin on the uController which I pull low to turn on the respective segment
    -I don't have individual resistors for each segment, guess I was being lazy about it
     
    Last edited: Nov 12, 2013
  14. KrisBlueNZ

    KrisBlueNZ Sadly passed away in 2015

    8,393
    1,266
    Nov 28, 2011
    See post #6 on this thread, item 3.
     
  15. BobK

    BobK

    7,625
    1,654
    Jan 5, 2010
    This is your problem. All of the current for all segments is going through this one resistor. The more segments you enable, the higher the voltage drop in this resistor and the lower the voltage each segment will see.

    You need to take out this resistor and place a separate resistor between each cathode and the micro output.

    Bob
     
  16. (*steve*)

    (*steve*) ¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd Moderator

    25,191
    2,692
    Jan 21, 2010
    However the lack of detail meant we posted a huge collection of possible problems and their cures.

    That lead to:

    :D
     
  17. gorgon

    gorgon

    603
    23
    Jun 6, 2011
    No offence to the posters, just an observation.
     
  18. KrisBlueNZ

    KrisBlueNZ Sadly passed away in 2015

    8,393
    1,266
    Nov 28, 2011
    Normally I agree that the OP should have posted a schematic right at the start of the thread.

    I replied with a generic and (hopefully) complete list of possible reasons for this problem so that my reply will be immediately useful to others who find this thread in future because they have the same symptom.

    That's why I covered both common anode and common cathode displays even though the OP told us he was using a common anode display, and the right way to connect multiple digits.

    All of the mistakes I listed are possible in real life.

    I neglected to explain the reasons behind point 3; BobK corrected that.
     
    Last edited: Nov 13, 2013
  19. dncky

    dncky

    15
    0
    Nov 10, 2013
    KBNZ, at the risk of hijacking the topic, let me pose a question real quick because I am about to make my own 7 segment display

    I am actually going to MAKE my seven segment display. Each segment consists of 20 LED's. Im going to have 4 parallel strands with 5 series LED each. Im going to toggle them with a mosfet.

    My question is, can I funnel all the current from the 4 strands through one mosfet, or does each of the strand need their own fet?

    Im putting a resistor in each of the 4 parallel strands btw
     
  20. KrisBlueNZ

    KrisBlueNZ Sadly passed away in 2015

    8,393
    1,266
    Nov 28, 2011
    You don't need a separate MOSFET for each strand. Each "strand" of five LEDs in series needs its own current limiting resistor in series with the five LEDs, as you said. Then each segment can be made into a two-terminal unit by connecting the four strands in parallel. This makes each "segment" similar to a single LED, like you would find in a standard seven-segment display, but with the following differences:

    1. No other series resistors are needed, and none should be used, because each segment includes its own current limiting and is simply voltage-driven.

    2. The total current consumption of each segment is equal to the current per strand multiplied by the number of strands, so you will need to use MOSFETs (or transistors, but MOSFETs are easier to drive) for the segment lines, unless you are running the LEDs at very low current. (If you have more than one digit, multiplexed, you will also need a MOSFET for each digit enable line.)

    3. Each segment needs a total voltage equal to five times the LED forward voltage plus an allowance for voltage drop across the series resistor. I use a rule of thumb that the voltage across the series resistor should be at least 15~20% of the total voltage. Generally, 20% is about right, unless you're using poor-quality LEDs whose forward voltage is more variable; in that case, 25~30% is better.

    So say you want to run the LEDs at 20 mA and each strand has five LEDs, each of which drops 2.4V at 20 mA. The total LED voltage is 12V, and 12V should be about 80% of the total strand (and segment) voltage, so the total segment voltage should be 15V, which leaves 3V (20% of 15V) across the limiting resistor in each strand.

    Assuming no significant voltage drop in the driving MOSFET(s), you will need a supply voltage of +15V. (Recalculate that value depending on the actual forward voltage of the LEDs; you can fine tune the display to a convenient power supply voltage such as 24V by increasing the voltage drop across the series resistors.)

    If you have a single digit, it's simplest to common the anodes of the segments and connect them to the high positive supply, and switch the cathodes to 0V using N-channel MOSFETs with their sources connected to 0V and their gates driven by the microcontroller (or other logic circuitry).

    If you are going to be multiplexing several digits, it's simplest to wire the displays as common anode, and switch the high positive supply to the digit anodes using a level shifter for each digit; a simple level shifter is a small N-channel MOSFET driven by an active high digit enable signal, with grounded source, whose drain pulls low the gate of a larger P-channel MOSFET with its source tied to the high positive supply; when this happens, the MOSFET feeds the high positive supply out its drain and to the common anode of its digit. The P-channel MOSFET needs a gate-source resistor and possibly gate overvoltage protection. The cathodes would be driven by N-channel "segment enable" MOSFETs as usual.

    If you can give me more information I will draw up a diagram. You need to tell me:
    a. What is the operating current of each LED?
    b. What is the forward voltage of each LED at that current? Give minimum, typical and maximum figures.
    c. How many digits do you want?
    d. Do you want them multiplexed?
    e. What high positive power supply voltage do you plan to use?
    f. What voltage is the logic circuitry running at?
    g. Do you want to use through-hole or surface-mounted components?
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Thread Status:
Not open for further replies.
Electronics Point Logo
Continue to site
Quote of the day

-