This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CAN NOT DELAY ON LED MATRIX

Other Parts Discussed in Thread: MSP430G2211, MSP430F2011

I'm programming about MSP430G2211 to show text on 4 LED matrix 8x8 (32 column, 8 row) but I can't delay as I want. In fact, every time " I scan a column, I scan rows" and repeat 20 times. Therefore, I  must scan quickly to show text so I use __delay_cycles(10) but time delay is very slow, I can't show text. I tried to use crystal 8MHz but result too.

What should I do?

  • __delay_cycles(10) will exactly delay 10 clock cycles = 1.25µs on 8MHz.. The delay alone would take 8*1,25µs=10µs for 8 rows. This would be 100kHz multiplex frequency. Surely fast enough. But the rest of your code that sets up the data and (re)programs the ports is most likely very slow. So the display is off most of the time and the multiplex rate is slow.

    You should rework the code. E.g. calculate the data two write before you switch the display off, so it is off only for a the few clock cycles you need to write the new column values.
    It would be best done in assembly, so you can hold all values readily in registers.

    You can even put your code into an ISR, so your main code can concentrate on gathering the data to show while it is interrupted by the timer for the next update. THis way you can use the delay time (in which the display is on) for something useful.

  • I found cause why can not delay. In fact, my hardware uses inverter gate so it take a little time. Therefore, I can not delay as I want.

    I designed the hardware and it's ok.

    But I still a problem with Led matrix is that:

    How should I delay to show text on Led matrix brightest and clearest ? (4 Led matrix 8x8 => 32 columns, 8 rows)

     

  • Tioni Lu said:
    How should I delay to show text on Led matrix brightest and clearest ?


    Keep the cycle time (for one complete cycle through all 32 columns) short enough so that no flicker is noticed (>25Hz). Keep the time where all segments are off (while switching the columns) as short as possible.
    Increasing the frequency increases the number of changes and therefore the relative off time.

    To increase brightness, you can power the LEDs with overcurrent. Since they are ON only <1/32 of the time, an overcurrent to increase brighness during the short on time is no problem.

    Another optimization is the organization.

    You can multiplex the individual LEDs and their segments (two-level multiplexing, e.g. with a chip-select signal). Then you'll need only 8+8+4 signal lines. This is, however, the worst solution for the display itself.

    Second is that you have 32 separate column lines and apply the row values to an 8 bit port. This means 32 switches per cycle but minimizes the tiem to set up for the next column.

    Or you use the row signals for multiplexing, so you only have 8 steps per cycle. This maximizes the time a complete row is on, but reauires to change 32 bit for the columns on each cycle, increasing the OFF time between steps.
    However, the total ON time for the segments will be maximized. Or the cycle frequency can be raised.
    So I think it is the best way to do it.

    Both last options require 40 I/O lines.

    With 4 external 8 bit latches, you can drop this to 12 I/O lines, using one 8 bit port for outputting 8 signals while 4 more lines define which of the 4 external latches is loaded wiht htis. It increases the required switch time (and therefore the OFF time of all segments), and requires additional hardware, but requires minimum MSP resources.

  • At present, I still have with Delay. In fact, I need to supply current for Led matrix. Every time I scan a column - 8 Led. 1 Led need 20mA to bright, so 8 Led is 8*20 = 160 mA.

    Therefore, I use IC ULN2803 or Transistor to supply current for Led matrix (Anode). However, it makes increasing time while scan column, so I can't delay to show text clearly (I don't understant this). If I use IC 74245 to supply current for Led matrix, it shows text clearly but I think its output current isn't enough to supply current fo Led matrix.

    To be not affect to time for scanning column, how can I supply current for Led matrix?

  • A transistor array shouldn't add a deley to the display. However, a transistor should provide the necessary base current factor (beta) and a base resistor when driven from the MSP, or else there will be a delay because of saturation effects and the drain of the MSP port pins.
    Or oyu can use a FET instead of a bipolar transistor. It switches fast and depending on the type you use, you can automatically limit the current of the LED (so you don't destoy them by overcurrent). You don't need any resistor for the LEDs then.

    I just took a look at the MSP datasheet. The port pins are capable of driving up to 45mA per port pin with Vcc=3V. However, there is a significant voltage drop then.
    Assuming your LEDs have a kathode voltage of 2V, a high MSP output pin will drive up to 25mA if directly connected to the MSP. However, since your are driving a matrix, you'll require a driver for the common pin, as it has to drive the combined currents of all active LEDs, and the MSP definitely cannot drive this.
    You can use a Darlington array, but a good MOSFET is probably best. In out laser supply, we use a MOSFET to control currents of up to 70A with an analog signal of >30kHz. So one of the smaller FETs will be definitely sufficient for your needs.
    One of the advantages of FETs is that they are voltage controlled, so they don't need any output current (except for a small current to charge or discharge the gate when the state changes). So the ports of the MSP do not have to drive anything (while they had on bipolar transistors or the ULN).

    Without further information about the exact type of LED matrix in use (Datasheet), or maybe a schematics (as far as it exists), I cannot be of further help with this issue.

  • If I use transistor or IC ULN 2803, how should I design it to increase its respond?

    If not, how should I do ? I don't understand about FET that you said and FET is more expensive.

    This is my circuit:         http://www.mediafire.com/?u9y2ydaj29rfsj9

    I use IC 74245 to widen Port of MSP to control Led matrix.

     

  • If I use transistor or IC ULN 2803, how should I design it to increase its respond?

    If not, how should I do ? I don't understand about FET that you said and FET is more expensive.

    This is my circuit:         http://www.mediafire.com/?u9y2ydaj29rfsj9

    I use IC 74245 to widen Port of MSP to control Led matrix.

     

  • Tioni Lu said:
    I use IC 74245 to widen Port of MSP to control Led matrix.


    Why that? The way you use it, it is simply a buffer (which is not necessary, as the MSP can easily drive 4 LSTTL inputs) that adds some ns propagation delay and some ns additional rise/fall time.

    I see that with an MSP430F2011 and its 8 port pins (the other two are used for the crystal) you'll need some serial transfer, but I don't see why you do it so complex. And why the pullup resistors? The ULNs drive to GND or to nothing. And if you drive one side of the LED high and the other to nothing, well, it simply stays dark. What is what you want.

    Well, the serial shifting is relatively slow, but if it has to be a 2011...
    You could use the 2012 instead and use the USI module to do the shifting using the USI SPI funcitonality - muuuch faster)

    In theory, you can have OE tied to GND permanently - but you can keep it on an MSP pin to shut off the whole display independent of the content. ST_CP can be permanently high too. As well as MR.

    To clear the display, shift 0 into to your U8 (column), set DS low for U4 to U7 chain (row select) then toggle SH_CP 32 times to ensure that the display is blank and no row is active. That is the 'display reset'. You can use MR instead, but that requires a pin you could use for something else. :)

    To output things, shift the first column data into U8. Here you need ST_CP, so the data doesn't change during the shift, but it can be connected to the others 595s SH_CP.
    Then set DS high for the row, and pull SH_CP (and U8s ST_CP) high and low. Now set DS high again, shift the next column into U8, pull SH_CP high and low, and so on until you are through with all 32 columns.

    What happens?
    U8 receives teh first columns data, but doesn't output it yet. When you pull SH_CP th e first time, U8 outputs its data while the high DS appears on Q0 of U4.
    Now U8 receives the next columsn data but doesn't output it. When SH_CP is pulled high the next time, now with DS low, the '1' on Q0 moves to Q1 while Q0 gets low again. And at the same time U8 outputs the data it just received for the second column.

    This way, the synchronization of the row and columsn drivers takes just the thime for two RMWQ operations. if you put theSH_CP signals for U8 and for the U4 to U7 to the one of the 0..3 bits of Port 1, this takes only 6 CPU cycles to pull and release these lines (if you use a 2012 with USI, U8 will be controlled by hardware, which is even faster, pins 5..7 require two more clock cycles to set or clear a bit)
    And except for the initial start bit, the row selection process does not need any CPU action other than the SH_CP (the '1' bit fed into DS at cycle start automatically propagates through all 32 locations without further intervention), which is unified with the U8 ST_CP and therefore does not require any time at all.

    With this algorithm, and the content of the matry prepared in a 32 byte array, it should take around 2-3ms for a complete cycle (without USI, and with 1MHz system clock). Or if you do the programming for a column in an interrupt that happens every ms, it would do a cycle every 32ms, so 31Hz update frequency, which should be almost flicker-free, and leaves 90% of the CPU power available for anything else.
    Just a raw estimation.

    So the minimum requirement are 5 MSP pins, and two optional ones which are not really necessary.

    P.s.: if you encounter some ghosting based on the synchroneous triggering of the U8 output and the row selection bit, while the row selection bit requires some propagation time, you can delay the U8 output by adding a series resistor and a capacitor to GND before U8s ST_CP line. Depending on capacitor size and resistor size, the output change of U8 is then delayed a bit relative to the row selection bit propagation.

    p.p.s.: You seem to use a 32kHz watch crystal. I hope you don't try to use this as you system clock. If so, I don't think you can get more than about 10Hz refresh rate (which will definitely flicker) even with my optimized setup.

  • First, thank you for helping of you!

    I use DOC of MSP. It's 1 MHz.

    At present, my problem is how to drive current for led matrix. I use ULN 2803 to drive current for Led matrix (ULN 2803 drive columns) ( Led bright when column = high level and row =low level). However, when I scan row to show text, Voltage of Led matrix decrease. This make Led bright not good! I understand this.

    In fact, when I scan first row and let data to columns (32 columns), the current from ULN 2803 will drive for 1 row (first row of Led) => 1 row of Led bright. However, other rows (7 row) will be not driven by ULN 2803 => current of ULN 2803 through registor to mass => this current is large => ULN 2803 is not enough current to drive for first row => decrease voltage.

    Therefore, I am thinking how to drive current for Led matrix.

    How do I drive current for Led matrix ?

  • Hi, Tioni.

    You said "I use ULN 2803 to drive current for Led matrix (ULN 2803 drive columns) ( Led bright when column = high level and row =low level)."

    According to your diagram, the ULN2803 (U3, U9, U10, U11) do not source current to turn on the leds because a LOW at an input will make the correspondent output to float (it is an open-collector  inverter).   Only the 330 ohm resistor connected to +5 will source current thru the LED to the U8 output pin (if this output is at LOW level). 

    You need the opposite situation, a component that sources current.  I did a quick search and found the Micrel MIC2981/2982  (8-channel, high-voltage, high-current source driver array) .    Be careful they are not directly replaceable in the circuit, the Vs and Gnd pins are not compatible with the ULN2803.     You have also to modify the connection from each driver output to the corresponding led in the array: instead of a straight connection, insert one of the 330 ohm resistors that you will remove from the actual connection to +5V.

    Moreover, the U8 can only sink a few milliamps, so you must insert one ULN2803 in the lines between U8 and the led array.

    After this, think that you have to invert the logic signals to the shift registers, now the drivers are logically inverted to the original ones. 

    Wow!  All this will be a big change in your circuit, but I believe that leds will shine with 10 mA each!          Think also about the former suggestion to reduce the resistors value to drive the leds with a higher current as they are on for a short time.  In this case, make all the development and debug with the actual resistors, only put the low value leds when the software and circuit are ok.   ;-) 

  • I've forgot to say that the important point is to introduce an ULN2803 between U8 and the led array.  With this new ULN2803 inverter in the circuit, it is wise to connect the U8 pin 10 (MR)  to the same signal used to reset the other latches.  So a reset will shut down the new ULN drivers and the led matrix will be "off" independently of the state of the column latches and drivers.             Notice that you don't need to modify the actual column circuit (with ULN2803 and resistors tied to +5V) if you don't mind about the overal current consumption, as for each column in the "off" state the current flows from the resistor to ground thru the ULN2803.

    Last but not least, let's talk about the HC245.   If you are using +5V for the 74HCxxx you should use a 74AHCT245 or 74HCT245 to "convert" the voltage level from the MSP to the 74HC595 latches.   See more about interfacing the 3-V MSP430 to 5-V circuits at  http://www.ti.com/lit/an/slaa148/slaa148.pdf .       If the logic is not powered from +5V then the HC245 is not necessary because the MSP430 outputs are strong enough to drive the HC595 inputs and  the voltage levels are compatible.  

    Have fun!

     

  • Can you draw diagram? I don't understand how decrease or remove the current flows from the resistor to ground thru the ULN2803 when each column in the "off".

    I think that if you can draw a diagram, it's easy to understand for me!

    Uh, I'm thinking how to design a 5V source circuit (output current is 3A) to drive ULN 2803 but I still get a little trouble ? At present, I use 7805 to make source 5V - 1A, so it don't enough drive the current for ULN 2803.

  • Tioni,

    See a diagram at http://www.mediafire.com/i/?ogiy975zmsy2c7s

    The parts within red boxes are the most important modifications.   The worst problem in your actual circuit is that U8 is not capable of dealing all the current from the leds.   You have to increase this capacity by inserting an ULN2803 between U8 and the led matrix.    After this, if you connect U8 pin 10 to the pin 10 of anyone of the remaining latches (U4 to U7) will assure that a reset command issued to them will turn off the leds and it will not be necessary to load U8 with a specif value just to turn off the leds.   Also replace the 74HC245 by 74AHCT245 to improve reliability of the communicaton from MSP430 to the logic ICs.

    By now, you can forget the suggestion to substitute U3, U9, U10 and U11 by MIC2891, as schetched in the green box.  

    The good notice is that your actual 7805 power supply is enough to supply the circuit, don't forget to use a heat sink.   Your concern about a 3A power supply for the ULNs is a mistake, do a research about logic circuits with "open collector" outputs.    Each ULN2803 is group of 8 darlington transistors where each collector is tied to an output pin of the IC and can only conduct to ground the external current that comes from the circuit connected to this pin.      

    If you understand the open collector concept you will realize that in your circuit when all the ULNs outputs are "LOW" (from a HIGH level in the inputs) they will drain about 480 mA from the +5V (32 x 15 mA from each resistor); on the other hand, if inputs are LOW the outputs will FLOAT  (they don't have a HIGH state as regular logic, this is the open collector characteristic)  so leds will receive current from resistors and will shine if the cathodes are somehow connected to ground.

     

  • Thank you,

    Finally, I understood what you say and I think it's very good!

    In addition, I understood logic circuits with "open collector" outputs.

    Thank you for your help! ^ ^

  • AH, I forget ask you somethings. Some friends of me, they are also design Led matrix as me. They also use ULN 2803 as I before. However, they add NOT Gates (74HC14) between ULN 2803 and Led matrix. They said me Led is bright good. I don't understand this because I think the output current of 74HC14 is not enough to drive Led matrix. Do you understand this?

  •  

    Tioni, I believe that this conversation has drifted far beyond the scope of the MSP430 forum.   Adding any HC component  between ULNs and the led columns is nonsense, I strongly suggest you and friends to try the circuit as I sketched (with MIC2981 driving the columns), I am sure that it will perform better than any of your former attempts.

    You received wise recommendations from Mr. Gross and also my humble contribution.    Let's stop here, good luck in your experiments.

     


**Attention** This is a public forum