Multiplexing a 7 segment with common cathode - timing problems

Hello,

I have written a working code for multiplexing a LED 7 segment display through a 16bit shift register.

The LED Display needs to be multiplexed using 2 transistors switched in code on 2 Digital output pins.

This means I need to constantly switch these two pins ON/OFF at certain frequency in the loop() function "manually" and every more complex execution of another code would be noticeable as flickering!? - Even if the display is static and not changing value etc.

I already though of two possible ways to solve this.

1.) Buy a dedicated arduino just for the job of driving the shift register and multiplexing the LED Display and somehow send the values to it from another arduino.

2.) Maybe you know a trick or best practice how to solve this with just one arduino. A kind of code-independent hardware switching function of the pins maybe?

Thanks for any suggestions.

Hi. There are more questions than answers...

Did you mean LED, not LCD?

How many digits?

Why have you not posted a schematic diagram? Hand drawn is OK.

Why have you not posted your sketch so far (using code tags of course)?

Answers: one Arduino can do this easily, you are making it more complicated than it really is. If the Arduino must run other complex code, there are techniques such as using timer interrupts which will ensure there is no visible flickering in almost every situation. In cases where this is not possible, and as a better solution anyway, you can use a chip such as max7219 to drive the display. This will mean a simpler circuit and simpler code.

@PaulRB
Oh I have no idea why I wrote "LCD" :smiley: - of course LED.. edited.

4 Digits

void loop() {

if (count>0){ // A interrupt PIN is doing its job here by executing (count++;)
one = count % 10;
ten = (count / 10) % 10;
hundred = (count / 100) % 10;
thousand = (count / 1000) % 10;
} 

if (thousand<1){
thousand = 14; // this is basically just setting the thousand-digit to "blank" when counter < 1000 to avoid displaying a 0 in the thousand digit. There is an character array with bits = [0,0,0,0,0,0,0] at position 14
}

construct_data(thousand,hundred,ten,one); //"Red_Buffer" and "Blue_Buffer" gets filled with the needed values in this function
shiftout(Red_Buffer);
refresh1h(10); // this is the part i am concerned of as its timing is crucial for the "visible part" of the code
shiftout(Blue_Buffer);
refresh2h(10); // this is the part i am concerned of as its timing is crucial for the "visible part" of the code
}
void refresh1h(unsigned int speed){
    digitalWrite(HALF1, HIGH);
    delay(speed);
    digitalWrite(HALF1, LOW);
}

void refresh2h(unsigned int speed){
    digitalWrite(HALF2, HIGH);
    delay(speed);
    digitalWrite(HALF2, LOW);
}

This is basically the part which i am concerned of, because these two functions need to be called without any delay to avoid flickering.

I am rather a noob and the whole code is written from scratch with common sense with almost no research on multiplexing therefore just quick&dirty for now, so bear with me if something is not quite right. :smiley:

ALL your code please! And remember that schematic.

@PaulRB
Unfortunately, I am unable to post schematics or more of the code as the project behind it doesnt belong to me.

After all I am just asking how to drive these 2 transistors on 2 Digital pins on a certain frequency without affecting the rest of the code. - This should be ok to answer without any additional info? The code as it is right now (only with the counter) works well without any problems, but I can imagine with rising amount of functions and background processing or whatever, this could be a problem.

With other worlds, the rest of the code shouldnt affect the seamless switching of these two transistors where each of them is enabling one half of the display, to avoid any flickering.

I have already read some ideas for this using the timer pins, and such but not very beginner friendly.

Anon2014:
@PaulRB
Unfortunately, I am unable to post schematics or more of the code as the project behind it doesnt belong to me.

Then, I'm sorry, but the help we can give will be very limited.

Anon2014:
After all I am just asking how to drive these 2 transistors on 2 Digital pins on a certain frequency without affecting the rest of the code. - This should be ok to answer without any additional info?

No, impossible to answer without the information you cannot give us.

Anon2014:
The code as it is right now (only with the counter) works well without any problems, but I can imagine with rising amount of functions and background processing or whatever, this could be a problem.

Then I would suggest going down the max7219 route. Simpler and better, and avoids the problem you are concerned about. At the moment, you have, or should have, two chips, two transistors, 8 or 16 series resistors, plus other sundry components (bypass caps, base resistors etc). With max7219 you would have one chip, one resistor and a couple of caps, use 3 Arduino pins, a brighter display with brightness control, simplify your code greatly and because the max chip does the multiplexing for you, no worries about flickering, no matter what the Arduino is doing.

If you must continue down the shift register road, then I suggest you remove all parts of the circuit and the sketch that you are not prepared to share with us. We can then advise on the simplified circuit/code. Once that is working to your satisfaction, you can then re-integrate that with the rest of your project.