MultiPlexing 7 Segment With Arduino (fast way) - DevBhoomi Robots

Home Top Ad

Responsive Ads Here

Post Top Ad

Your Ad Spot

Tuesday, September 18, 2018

MultiPlexing 7 Segment With Arduino (fast way)


The proper operation of a multiplexed displays relies on a feature of human visual perception known as flicker fusion – if a light is flashed quickly enough, individual flashes become imperceptible and the illusion of a steady light is created.
But how slow can you go before you can detect that flicker?

Some research uncovered suggests that any light flashing faster than 50Hz (50 times per second) will appear to be steady. But I wanted to verify this number myself.

Multiplexed Displays

Multiplexed displays only show one digit at a time, but by cycling through all digits repetitively and cycling very fast, a multi-digit display is perceived. To drive a particular digit, its common anode/cathode is connected to the appropriate supply voltage and the segments are driven as needed for the desired display. These segments are numbered a through g  in the figure below.

7seg-segments-pinout
In a display with multiple digits, all like segments of the digits are connected together. To decide which display to turn on, we can switch a common anode/cathode terminal of our display. The cycling through the digits must be done quickly enough for flicker fusion to occur and this is accomplished through the application software. So, no matter how many digits are in the display, we only need a common set of LED wires plus a selection/enable wire for each digit.

7-seg_Multi_Digits

The experiment

7seg-test_setupRather than drive multiple digits, I simplified by multiplexing each individual segment of a single LED digit. The setup is shown in the photo on the right (click to enlarge).
The individual LED segments are connected to digital outputs on the Arduino. A single current limiting resistor in series with the common anode limits the LED current to 10mA. The pot is used to set/change the digit scan time, which is displayed on the serial monitor when it changes. The code to drive the experiment is shown at the end of this text.
As the pot varies between 0 and its maximum, the scan time is mapped between 0 and 400 milliseconds. Each LED in the display is then scanned at scan time ÷ number of segments, in this case 1/8 the scan time.
Subjectively, the flickering display stopped flickering when the digit scan time was around 25ms (ie, scanned at 40Hz). This is pretty close the the 50Hz ‘rule of thumb’ mentioned above, but is actually a slower scan rate.
I also noticed that, as the scan frequency increased, the LED display dimmed considerably. At a scan rate of 4ms (ie, 250Hz), it appears that, all other things being equal, the display LEDs were not able to turn on fast enough to create a bright display. Increasing the LED current increased the brightness somewhat, but never to the same level as the peak.
All in all, this was an interesting exercise. Although the result was ‘as expected’, this brief experiment did teach me that I also need to pay attention to multiplexing too quickly as this could result in a suboptimal display.
Code Listing
#define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
const uint8_t pinLED[] = { 7, 6, 3, 4, 5, 8, 9, 2 };
const uint8_t pinPot = A0;

void setup(void) 
{
  Serial.begin(57600);
  Serial.print("\n[Multiplexer Test]");

  // initialise the hardware pins
  for (uint8_t i=0; i<ARRAY_SIZE(pinLED); i++)
  {
    pinMode(pinLED[i], OUTPUT);
    digitalWrite(pinLED[i], HIGH);
  }
  pinMode(pinPot, INPUT);
}

void loop(void) 
{
  static uint16_t dOld = 0;
  uint16_t d = analogRead(pinPot);

  d = map(d, 0, 1023, 0, 400); 
  if (d != dOld) // only update monitor if it has changed
  {
    Serial.print("\n"); Serial.print(d);
    dOld = d;
  }

  // scan all the LED segments with the current delay setting
  for (uint8_t i=0; i<ARRAY_SIZE(pinLED); i++)
  {
    digitalWrite(pinLED[i], LOW);
    delay(d/sizeof(pinLED)); // whole digit update in this time
    digitalWrite(pinLED[i], HIGH);
  }
}

Post Top Ad

Your Ad Spot