Go Down

Topic: Multiplexing question (Read 453 times) previous topic - next topic

The_KOC

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 ///

CrossRoads

How are the LED segments wired up - are you using current limit resistors?
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

The_KOC

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.

CrossRoads

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
10K resistor, 0.1uF cap, 10uF cap and the chip and display are all that's needed.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

CrossRoads

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.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

PaulRB

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.

The_KOC

Thanks for the help gentlemen!

Go Up