Arduino Forum

Using Arduino => LEDs and Multiplexing => Topic started by: ron190 on May 29, 2015, 02:22 pm

Title: Two shift registers and 7-segments slight flickering
Post by: ron190 on May 29, 2015, 02:22 pm
I made a chronometer with two 7-segments and two shift registers.

With only one call to shiftOut(..., rightNumber) the two 7-segments are displaying the same number (I thought it will display only one 7-segment but it's fine I guess), with the calls to shiftOut(..., rightNumber) and shiftOut(..., leftNumber) it works OK but apparently with a very slight flickering on the left most, as if it has to erase before displaying the number on the left.

Code: [Select]
const int latchPin = 8;
const int clockPin = 12;
const int dataPin = 11;

int count = 0;

const byte digit[10] = {
    B11111100, // 0
    B01100000, // 1
    B11011010, // 2
    B11110010, // 3
    B01100110, // 4
    B10110110, // 5
    B10111110, // 6
    B11100000, // 7
    B11111110, // 8
    B11110110, // 9
};

void setup() {
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
 
  Serial.begin(9600);
}

void loop() {
    count = (count + 1) % 100;          // count to 99

    float remainder = count % 10;       // find the remainder of dividing z by 10, this will be the right-hand digit
    int rightNumber = int(remainder);   // make it an integer, c is the right hand digit
    float dozen = count / 10;           // divide z by 10 - the whole number value will be the left-hand digit
    int leftNumber = int(dozen);        // e is the left hand digit
   
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, MSBFIRST, digit[rightNumber]);
    shiftOut(dataPin, clockPin, MSBFIRST, digit[leftNumber]);
    digitalWrite(latchPin, HIGH);
 
    delay(50);
}


Is this the right way to stack calls to shiftOut() in order to use multiple shift registers ?

Then is it possible to activate one 7-segment without activating the second one if I chain registers ?
Title: Re: Two shift registers and 7-segments slight flickering
Post by: Grumpy_Mike on May 29, 2015, 02:45 pm
Quote
Is this the right way to stack calls to shiftOut() in order to use multiple shift registers ?
Yes you have that bit right.

Quote
Then is it possible to activate one 7-segment without activating the second one if I chain registers ?
No because the clock and latch pins are common to the two shift registers.

Do you have decoupling capacitors on the two shift registers? And also no capacitor on the latch pin ( like some tutorials wrongly show )
Title: Re: Two shift registers and 7-segments slight flickering
Post by: CrossRoads on May 29, 2015, 02:56 pm
Show your wiring, perhaps something is off.
There should be no flickering, both displays should update at the same time, when the latchPin goes from LOW to HIGH.

This seems like an awkward  way to get two digits:
Code: [Select]

count = (count + 1) % 100;          // count to 99

    float remainder = count % 10;       // find the remainder of dividing z by 10, this will be the right-hand digit
    int rightNumber = int(remainder);   // make it an integer, c is the right hand digit
    float dozen = count / 10;           // divide z by 10 - the whole number value will be the left-hand digit
    int leftNumber = int(dozen);        // e is the left hand digit

I would do it like this, with data type byte for each:
Code: [Select]

rightNumber = rightNumber+1;
if (rightNumber == 10){
  rightNumber = 0;
  leftNumber = leftNumber +1;
  if (leftNumber == 10){
  leftNumber = 0;
  }
}
Title: Re: Two shift registers and 7-segments slight flickering
Post by: ron190 on May 29, 2015, 08:19 pm
This seems like an awkward  way to get two digits
Well I guess the magic of coding is that everybody can do the same thing in different ways :) ; so it's possible to count to 10 then reset each dozen, then reset each hundred, with a bunch of ifs.

The functionality here appears to me firstly to count to 99, then get the first digit and then the second one ; in fact my code should have been simpler without the float to int conversion :

Code: [Select]



[...]

    count = (count + 1) % 100; // count from 00 to 99
    rightNumber = count % 10;  // get right part :  X[X]
    leftNumber = count / 10;   // get left part  : [X]X

[...]

Btw, it seems that the subtle flickering does not exist the first minutes the sketch is running, but after some hours their is subtle blinking of segments that should have been switched off.

I've made a fritzing, maybe it's the lack of capacitors.
Title: Re: Two shift registers and 7-segments slight flickering
Post by: CrossRoads on May 29, 2015, 08:29 pm
1. Need 0.1uF cap  from pin 16 to Gnd on each HC595.

2. Need current limit resistors from EACH HC595 output to the LED segments.  EACH ONE.
Otherwise, the HC595 or the segments will fail, just a matter of time.

(5V - (Vf of LED)/current = resistor

Say you had Red LEDs, Vf usually around 2.2V, max continuous on current of 20mA (.02A).
(5V - 2.2V)/.02 = 140 ohm, use standard 150 ohm, 180, 220, 270, something in that range.
20mA is really overstressing the HC595; VCC pin is only rated for 70mA Absolute MAX, so
all 8 segments on means 8-9mA per output max.
(5-2.2)/.009 = 311 ohm, so standard 330 would make for a happier circuit.  300, 270 at the lowest.
Title: Re: Two shift registers and 7-segments slight flickering
Post by: ron190 on May 31, 2015, 03:13 am
Thank you for your comprehensive explanation, I will add the two capacitors and the resistors for each LEDs.