Arduino Forum

Using Arduino => LEDs and Multiplexing => Topic started by: The_KOC on Nov 21, 2016, 03:16 am

Title: Multiplexing question
Post by: The_KOC on Nov 21, 2016, 03:16 am
Hello,

I have a question about multiplexing after building a 4 digit timer that is included in a library found here:

http://playground.arduino.cc/Main/SevenSegmentLibrary

The circuit functions ok but as the LSD changes (1/10 of a second) the segments of the other 3 digits fluctuate in brightness. Why does that happen? Here's the UNO sketch:



#include "SevSeg.h"

SevSeg sevseg; //Instantiate a seven segment controller object

void setup() {
  byte numDigits = 4;   
  byte digitPins[] = {2, 3, 4, 5};
  byte segmentPins[] = {6, 7, 8, 9, 10, 11, 12, 13};

  sevseg.begin(P_TRANSISTORS, numDigits, digitPins, segmentPins);
  sevseg.setBrightness(90);
}

void loop() {
  static unsigned long timer = millis();
  static int deciSeconds = 0;
 
  if (millis() >= timer) {
    deciSeconds++; // 100 milliSeconds is equal to 1 deciSecond
    timer += 100;
    if (deciSeconds == 10000) { // Reset to 0 after counting for 1000 seconds.
      deciSeconds=0;
    }
    sevseg.setNumber(deciSeconds, 1);
  }

  sevseg.refreshDisplay(); // Must run repeatedly
}

/// END ///
Title: Re: Multiplexing question
Post by: CrossRoads on Nov 21, 2016, 04:39 am
How are the LED segments wired up - are you using current limit resistors?
Title: Re: Multiplexing question
Post by: The_KOC on Nov 21, 2016, 06:18 pm
How are the LED segments wired up - are you using current limit resistors?
They have resistors on each segment and the commons are driven by transistors.
Title: Re: Multiplexing question
Post by: CrossRoads on Nov 21, 2016, 08:14 pm
I don't know that Library, so can't speak as to how it might be doing the multiplexing.
You could open it up & take a look.

If you have common cathode displays (or common anode with a little more software)  you could have MAX7219 do the multiplexing for you. It multiplexes at 800 Hz and keeps very even brightness.  Just 1 resistor needed for all 4 displays (up to 8 even) and provides 15 levels of brightness control also.
http://www.taydaelectronics.com/catalogsearch/result/?q=max7219 (http://www.taydaelectronics.com/catalogsearch/result/?q=max7219)
10K resistor, 0.1uF cap, 10uF cap and the chip and display are all that's needed.
Title: Re: Multiplexing question
Post by: CrossRoads on Nov 21, 2016, 08:16 pm
You say the code changes digits every 1/10 of a second? Try speeding it up, turning on each digit for 5 to 8 mS instead.
Title: Re: Multiplexing question
Post by: PaulRB on Nov 21, 2016, 11:46 pm
The dimming of the digits when the display is changed is caused by the way the code has been written in the SevenSeg library, or at least that version of the library you are using. It uses for loops and delay functions, what we call "blocking code". As long as the refreshDisplay() function is called continuously over and over, the display gets multiplexed and stays bright. But as soon as the code tries to do anything else, such as update the value displayed, the multiplexing has to stop for a moment, causing an apparent brief dimming.

It would be better if the library code was written using non-blocking functions, and used timer interrupts to allow the multiplexing to continue even when the sketch is performing other tasks.
Title: Re: Multiplexing question
Post by: The_KOC on Nov 23, 2016, 03:22 am
Thanks for the help gentlemen!