+ Post New Thread
Results 1 to 11 of 11
  1. #1
    Full Member level 6
    Points: 2,985, Level: 12
    Achievements:
    7 years registered

    Join Date
    Apr 2011
    Posts
    337
    Helped
    23 / 23
    Points
    2,985
    Level
    12

    MAX7219 and Common Anode LED Display

    Dear friends,

    MCU : PIC16F1938
    LED DISPLAY (BIG SIZED): 6 DIGITS
    VDD (LED DISPLAY) = +12V
    LED DIGIT SIZE: 3.5" x 5"
    DISPLAY: COMMON ANODE ***
    POWER SUPPLY:
    MAX7219 & PIC MCU = +5V
    LED DISPLAY = +12V, 500mA POWER ADAPTER


    I have to interface LED DISPLAY (6 Digits) from PIC MCU thru' MAX7219 IC. MAX7219 for common cathode display. I have used ULN2003 and PNP (BC557) transistors to make it work on MAX7219. I am using bitbanging (not SPI module) method (RA1 - SDO, RA2 - SS, RA3 - SCK).

    Code works OK. But, if data sent to one digit, it writes on all digits. Also, when first data sent, it clears all other segments correctly and correct digit displayed on Digits. but after second data sent, it overlaps on earlier digit we have already written.

    Code C - [expand]
    1
    2
    3
    4
    5
    6
    
    MAX7219 DIG PIN -> 4K7 RESISTOR -> BASE PIN PNP.
    BASE PIN OF PNP -> 47K -> +12V
    +12V -> 300R RESISTOR -> EMITTER PIN OF PNP
    COLLECTOR PIN OF PNP -> VDD PINS of INDIVIDUAL LED DIGIT
     
    MAX7219 SEG PINS -> ULN2003 -> LED SEGMENT PINS.

    sample picture attached FYR.

    what could be the problem?

    thanks in advance.

  2. #2
    Super Moderator
    Points: 29,210, Level: 41
    andre_teprom's Avatar
    Join Date
    Nov 2006
    Location
    Brazil
    Posts
    8,695
    Helped
    1102 / 1102
    Points
    29,210
    Level
    41
    Blog Entries
    9

    Re: MAX7219 and Common Anode LED Display

    what could be the problem?
    No schematic, no code...
    Are you serious ?
    --------------------------------------------------------------------------------------------------
    Part of the world that you live in, You are the part that you're giving ( Renaissance )



    •   AltAdvertisement

        
       

  3. #3
    Super Moderator
    Points: 79,430, Level: 68
    Achievements:
    7 years registered
    Awards:
    2nd Helpful Member
    betwixt's Avatar
    Join Date
    Jul 2009
    Location
    Aberdyfi, West Wales, UK
    Posts
    13,011
    Helped
    4345 / 4345
    Points
    79,430
    Level
    68

    Re: MAX7219 and Common Anode LED Display

    Follow Andre's advice.

    The most likely reasons are:
    1. You have an electrical fault and the digits that should be on are off and vice versa. This means one of the digits is probably slightly different to the others but they are all similar. You can check this by dimming them, if dimming works in reverse you have the digit drive signal inverted.

    2. You have a software fault and the address bits in the SPI word are incorrect.

    My guess is the electrical scenario, remember the outputs of the MAX7219 are expected to sink current or source current so you may need to add resistors appropriately to allow some current to flow instead of just assuming voltages are turning on or off.

    Brian.
    PLEASE - no friends requests or private emails, I simply don't have time to reply to them all.
    It's better to share your questions and answers on Edaboard so we can all benefit from each others experiences.



    •   AltAdvertisement

        
       

  4. #4
    Super Moderator
    Points: 29,210, Level: 41
    andre_teprom's Avatar
    Join Date
    Nov 2006
    Location
    Brazil
    Posts
    8,695
    Helped
    1102 / 1102
    Points
    29,210
    Level
    41
    Blog Entries
    9

    Re: MAX7219 and Common Anode LED Display

    Whenever possible, take a time to make a movie of the problem; with the code and being able to see how the system behaves, one can have an insight and say exactly where the error lies at your code.
    --------------------------------------------------------------------------------------------------
    Part of the world that you live in, You are the part that you're giving ( Renaissance )



    •   AltAdvertisement

        
       

  5. #5
    Full Member level 6
    Points: 2,985, Level: 12
    Achievements:
    7 years registered

    Join Date
    Apr 2011
    Posts
    337
    Helped
    23 / 23
    Points
    2,985
    Level
    12

    Re: MAX7219 and Common Anode LED Display

    No schematic, no code...
    Are you serious ?
    Code C - [expand]
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    
    static void Send16bits (unsigned short output)
    {
     
      unsigned char i;
     
      for (i=16; i>0; i--) 
      {
        unsigned short mask = 1 << (i - 1); // calculate bitmask
        
        SERCLK = LOW;
        
        // Send one bit on the data pin
        
        if (output & mask)
          LED_DATA = HIGH;
        else
          LED_DATA = LOW;
        
        SERCLK = HIGH;
        SERCLK = LOW;
      }
    }
    // Take a reg numer and data and send to the max7219
     
    static void MAX7219Send (unsigned char reg_number, unsigned char dataout)
    {
        LOAD_DATA = 1;
        Send16bits((reg_number << 8) + dataout);   // send 16 bits ( reg number + dataout )
        LOAD_DATA = 0;
        LOAD_DATA = 1;
    }
    void init_MAX7219_NEW(void){
        
        // set decode mode
        MAX7219Send(0x09, 0xFF);
        
        // set intensity
        MAX7219Send(0x0A, 0x0F);
        
        // set scan limit 0-7
        MAX7219Send(0x0B, 0x05); // 6 digits
        
        // set for normal operation
        MAX7219Send(0x0C, 0x01);
        
        // NO TEST
        MAX7219Send(0x0F, 0x00);
        
        // clear MAX7219 all zeros
        // BCD mode all off otherwise
        for(int i = 1; i <= 6; i++){
            MAX7219Send(i, 0x00);
        }
    } 
     
    int decToBcd(int val){
    // Convert normal decimal numbers to binary coded decimal
      return ( (val/10*16) + (val%10) );
    }
     
    int bcdToDec(int val){
    // Convert binary coded decimal to normal decimal numbers
      return ( (val/16*10) + (val%16) );
     
     
    }
    When running "for" loop, instead of clear the LED digits, it shows the numbers that we supplied.

    Code C - [expand]
    1
    2
    3
    4
    5
    6
    
    main(){
        unsigned char bcd; 
        bcd = decToBcd(1);
        MAX7219Send(0x01, bcd);
     while(1);
    }
    When this code runs, it overlaps on previously written digits. i.e. not clear the previous digits.

    You have an electrical fault and the digits that should be on are off and vice versa
    LED DISPLAY (all LED Digits) randomly on/off (like glitching). It is not staying on or off for a long time. What could be the reason. Now I have bought separate LED digits and combined myself to make LED DISPLAY. Earlier I have bought readymade LED Digit Panel (small 8 digits) from ebay. But that modules also showed same behaviour of glitching. But when we run the code, it displayed the result correct (SPI module used, NOT bitbanging).

    This means one of the digits is probably slightly different to the others but they are all similar
    One of 6 Digit is different from other 5 LED Digits. First I bought 1 LED for testing. After this, I bought 5 LED digits. Both are different make. I hope so. But all are common anode. One of the 6 digits luminosity intensity is different (dull) from other 5 digits.

    You have a software fault and the address bits in the SPI word are incorrect.
    The code is given above FYR. Pl check.

    Code C - [expand]
    1
    
    My guess is the electrical scenario, remember the outputs of the MAX7219 are expected to sink current or source current so you may need to add resistors appropriately to allow some current to flow instead of just assuming voltages are turning on or off.
    I have used 300R to give 40mA to each Digit. Is that not enough?

    any suggestions?
    thanks in advance.

    - - - Updated - - -

    +12V -> 300R -> PNP -> LED DIGIT VDD PIN when MAX7219 sink the DIG pin.
    Picture attached FYR.

    - - - Updated - - -

    10K RESISTOR USED AS Rset of MAX7219.



  6. #6
    Advanced Member level 5
    Points: 9,012, Level: 22
    Achievements:
    7 years registered
    Easyrider83's Avatar
    Join Date
    Oct 2011
    Location
    Tallinn, Estonia
    Posts
    1,588
    Helped
    362 / 362
    Points
    9,012
    Level
    22

    Re: MAX7219 and Common Anode LED Display

    This cirtuit will not work. Voltage level not alligned. You should add one more npn transistor to convert 5v pin voltage to 12v driving Q6 voltage.
    Love me or hate me. All infractions will be ignored.



  7. #7
    Super Moderator
    Points: 79,430, Level: 68
    Achievements:
    7 years registered
    Awards:
    2nd Helpful Member
    betwixt's Avatar
    Join Date
    Jul 2009
    Location
    Aberdyfi, West Wales, UK
    Posts
    13,011
    Helped
    4345 / 4345
    Points
    79,430
    Level
    68

    Re: MAX7219 and Common Anode LED Display

    You (and Easyrider83) are confirming what I thought. It's an electrical issue. Consider how the MAX7219 works internally, it basically has switches from the supply to the LED anodes and switches from the LED common cathodes to ground. When the switches are 'on' in the correct combination, the appropriate segment or LED lights up. When the switch is 'off' it doesn't remove the voltage, it just isolates it and effectively leaves the current path open circuit. Your driver circuit expect to be turned on or turned off by the voltage applied to it but what you actually have is current turned on or your circuit input disconnected. It isn't able to turn the unwanted digits off so they all show the same pattern.

    You can try adding resistors to mimic the normal LED operation, add resistors (guess ~1K) from the cathode drive to +Ve and from the anode drives to GND so the output voltage go to the opposite logic state when NOT being driven.

    Brian.
    PLEASE - no friends requests or private emails, I simply don't have time to reply to them all.
    It's better to share your questions and answers on Edaboard so we can all benefit from each others experiences.


    1 members found this post helpful.

  8. #8
    Full Member level 6
    Points: 2,985, Level: 12
    Achievements:
    7 years registered

    Join Date
    Apr 2011
    Posts
    337
    Helped
    23 / 23
    Points
    2,985
    Level
    12

    Re: MAX7219 and Common Anode LED Display

    You should add one more npn transistor to convert 5v pin voltage to 12v driving Q6 voltage.
    If MAX sinks the DIG pin, the current should flow and vice-versa. If we add npn transistor, the signal could be inverted. How can we solve this issue? Any suggestion?
    You (and Easyrider83) are confirming what I thought. It's an electrical issue
    Yes. I have tested the code with +5V COMMON CATHODE LED 8 digits(as I already told you that bought from ebay). It works fine. So code is not a problem.
    add resistors (guess ~1K) from the cathode drive to +Ve and from the anode drives to GND
    You mean, cathode drive to +Ve -> DIG PIN and from the anode drives to GND -> SEG PIN?

    thank you



  9. #9
    Advanced Member level 5
    Points: 9,012, Level: 22
    Achievements:
    7 years registered
    Easyrider83's Avatar
    Join Date
    Oct 2011
    Location
    Tallinn, Estonia
    Posts
    1,588
    Helped
    362 / 362
    Points
    9,012
    Level
    22

    Re: MAX7219 and Common Anode LED Display

    Inverting pin can be done by sw. But wrong schematic can't.
    There are special article can be googled in 5s btw:
    https://www.maximintegrated.com/en/a...ex.mvp/id/1196
    Love me or hate me. All infractions will be ignored.


    1 members found this post helpful.

  10. #10
    Super Moderator
    Points: 79,430, Level: 68
    Achievements:
    7 years registered
    Awards:
    2nd Helpful Member
    betwixt's Avatar
    Join Date
    Jul 2009
    Location
    Aberdyfi, West Wales, UK
    Posts
    13,011
    Helped
    4345 / 4345
    Points
    79,430
    Level
    68

    Re: MAX7219 and Common Anode LED Display

    From the data sheet Easyrider83 mentions:
    Digit Drivers
    The digit drive outputs of the MAX7219/7221 are power switches which go active low one at a time to turn a digit on, and high impedance when off.
    That isn't the same as going active low and active high. By adding your own external driver circuit you are no longer using the drive capability of the MAX7219, instead you are using it to create logic levels which your own driver can use. While the MAX7219 can sink or source current, it has no way to produce a high or low voltage (logic levels) at it's pins unless you actively pull them to the 'off' state with external resistors.

    Brian.
    PLEASE - no friends requests or private emails, I simply don't have time to reply to them all.
    It's better to share your questions and answers on Edaboard so we can all benefit from each others experiences.



    •   AltAdvertisement

        
       

  11. #11
    Full Member level 6
    Points: 2,985, Level: 12
    Achievements:
    7 years registered

    Join Date
    Apr 2011
    Posts
    337
    Helped
    23 / 23
    Points
    2,985
    Level
    12

    Re: MAX7219 and Common Anode LED Display

    I have implemented the circuit referred by Easyrider83. It works fine now. Thank you andre_teprom, Brian and Easyrider83. Circuit attached.

    Thank you.



--[[ ]]--