Go Down

Topic: Segment LEDs flicker with Digispark and step-up converter (Read 638 times) previous topic - next topic

Grrrmachine

I've thrown together a basic clock using an Arduino, a DS1307, two 74HC595s and some common anode segment LEDs. The circuit is based on this (minus the temp sensor):



And here's the digispark-specific code:

Code: [Select]

#include <Time.h>        //Time Library
#include <TinyRTClib.h> //Digispark version of RTC Library
#include <TinyWireM.h> //Digispark version of Wire library

RTC_DS1307 RTC;

int clockPin = 3; // connected in the pin 11 of 74HC595 (Clock)
int latchPin = 4; // connected in the pin 12 of 74HC595 (Latch)
int dataPin = 1; // connected in the pin 14 of 74HC595 (Data)

int hora, minuto;
int unidadeHora, unidadeMinuto, dezenaHora, dezenaMinuto;

//Digits Matrix - 0 a 9
byte num[] = {
  B01111110, // Zero
  B00110000, // One
  B01101101, // Two
  B01111001, // Three
  B00110011, // Four
  B01011011, // Five
  B01011111, // Six
  B01110000, // Seven
  B01111111, // Eight
  B01111011, // Nine
};

void setup() {

  pinMode(latchPin, OUTPUT); // Define the 3 digital pins as output
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);

  TinyWireM.begin();
  RTC.begin();
}


void loop() {

    DateTime now = RTC.now();           // Get the RTC info
    hora = now.hour();
    minuto = now.minute();
    unidadeHora = hora % 10;
    dezenaHora = hora / 10;
    unidadeMinuto = minuto % 10;
    dezenaMinuto = minuto / 10;

    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, LSBFIRST, 8);                  //Set DISPLAY 1 (top view from left to right)
    shiftOut(dataPin, clockPin, LSBFIRST, ~num[dezenaHora]);   //Set the Hour (ten)
    digitalWrite(latchPin, HIGH);

    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, LSBFIRST, 4);                  //Set DISPLAY 2
    shiftOut(dataPin, clockPin, LSBFIRST, ~num[unidadeHora]);  //Set the Hour (unit)
    digitalWrite(latchPin, HIGH);

    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, LSBFIRST, 2);                  //Set DISPLAY 3
    shiftOut(dataPin, clockPin, LSBFIRST, ~num[dezenaMinuto]); //Set the Minute (ten)
    digitalWrite(latchPin, HIGH);

    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, LSBFIRST, 1);                   //Set DISPLAY 4
    shiftOut(dataPin, clockPin, LSBFIRST, ~num[unidadeMinuto]); //Set the Minute (unit)
    digitalWrite(latchPin, HIGH);

    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, LSBFIRST, 8);                  //Set LED of dots
    shiftOut(dataPin, clockPin, LSBFIRST, ~B10000000);         //Set LEDs of double dots
    digitalWrite(latchPin, HIGH);

    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, LSBFIRST, 1);                  //Set DISPLAY 4
    shiftOut(dataPin, clockPin, LSBFIRST, 255);                //Reset the DISPLAY 4 (to avoid some flicking)
    digitalWrite(latchPin, HIGH);
  }


So far everything works, as long as I supply power through the digispark's USB port.

But I also want to use a step-up converter, taking power from a 18650 cell and bumping it to 5v. When I use this converter, two of the four segment LEDs flickers, as if the LEDs are grounding out somewhere (segments that should be blank glow dimly).

Of course, you'd think the step-up converter was at fault. But when I replace the Digispark with a Nano (and swap the required libraries), then everything works fine running on battery power - it's just the digispark that's not happy. So I tried a second digispark, in case there's a flaw in the board, and I have the same flickering symptoms.

Anyone got any ideas what's causing this?

Grumpy_Mike

Quote
The circuit is based on this
On what, all I see is a physical layout diagram, not a circuit at all.

If the layout is accurate than you have no decoupling capacitors, this will cause your problem. Put a 0.1uF ceramic between power and ground of every chip and put a 100uF capacitor across the power and ground on the supply to your circuit.

Grrrmachine

Thanks Mike. So if it's something with the power circuit, why would the Nano be unaffected?

For reference, this is the step-up converter (which has a capacitor across the outputs, but nothing as beefy as 100uF):


Grumpy_Mike

Quote
why would the Nano be unaffected?
Probably because it had more on board decoupling, so instead of failing it is just on the edge of failing. Not that does not equate to "unaffected", it is just that you have not tested it sufficiently under different conditions to see that it is.

Here is why you ALWAYS need decoupling capacitors on ALL circuits.
http://www.thebox.myzen.co.uk/Tutorial/De-coupling.html

Go Up