Pages: [1] 2   Go Down
Author Topic: 4-digit display made from minimal parts  (Read 2257 times)
0 Members and 1 Guest are viewing this topic.
Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

After the recent discussions about doing LED displays with a minimal number of pins (and parts) I experimented with this:



By arranging the shift registers adjacent to the LED it was possible to keep wiring to a minimum. So you only need 3 wires (MOSI, SS, SCK) from the Arduino to the board (plus 5V and Gnd).

The actual displaying is done by a timer interrupt routine, so you can be doing other things in your sketch while the display is updated automatically. The whole thing is quite cheap, the registers are under a $1 each, and the LED was about $3.

Schematic:



More details including example program code here:

http://www.gammon.com.au/forum/?id=11524

It would be possible to add another LED with another two shift registers (I've put a dot on the board where pin 1 would go) so as to extend the number of digits to 8.

(edit) As discussed further down this thread, current limiting resistors would be advisable for the health of the LEDs and ICs. (April 2012).
« Last Edit: April 29, 2012, 04:08:12 pm by Nick Gammon » Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 126
Posts: 8472
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

So you got it done, did you use a resistor safety net until the code worked or go for broke?

How about a video, there's something quite therapeutic about watching LEDs count smiley

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I decided not to use resistors in the end, "live recklessly", I thought. smiley

If it looked too bright I was going to unplug it quickly. A quick check with the logic analyzer seemed to show that the SPI data was being clocked out at about the right rate. In fact, it was far too slow, with the segments lighting up briefly and then with a lengthy pause between them.

I did some tweaking "by eye" to get the segments to look "not too bright" but not flicker either.

This is what it looks like:



There is a slight flicker, you can eliminate that by increasing the interrupt fire rate. ie. change:

Code:
 OCR2A  = 124;            // count up to 125  (zero relative!!!!)

to something like:

Code:
 OCR2A  = 59;            // count up to 60  (zero relative!!!!)
« Last Edit: November 25, 2013, 06:41:23 pm by Nick Gammon » Logged

Manchester, New Hampshire
Offline Offline
Edison Member
*
Karma: 4
Posts: 1359
Propmaker
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So how does this work?  Not using resistors for the LEDs I mean.  What's limiting the current that the Arduino is putting out? 
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Well the theory is that you are delivering higher current than it should get, for less time. So the average is OK. The Lots Of Leds shield, for example, doesn't have resistors.

Measurement appears to indicate that a particular segment is on for 4 mS and off for 17 mS (depending on what you are displaying of course) so that is 4/23 "on" duty cycle, or 17%.

There is a limit to how much the chip can deliver (say, 40 mA) so we are on average supplying 17% of 40 mA, namely 6.8 mA.

I can't find a definitive proof of this, maybe the electronics engineers here might like to comment?

I think the problem place is really the "sink" pins, because they would have a duty cycle of 25% (as they rotate from digit to digit). However I built in a "blanking" period of 8 cycles (8 mS) when all the pins are held low, and thus won't conduct anything. So they, too, should get a rest.

If you greatly increase the blanking time, eg.

Code:
const byte TIME_BETWEEN_DIGITS = 100;  // blanking period between digits in loop iterations

... and then make the timer fire faster to remove flicker:

Code:
  OCR2A  = 9;            // count up to 10  (zero relative!!!!)

... then the LEDs are noticeably dimmer (but still readable) and there is no noticeable flicker (although I do notice a slight flicker every 10th of a second which is when interrupts are turned off to update the counter).
Logged

Manchester, New Hampshire
Offline Offline
Edison Member
*
Karma: 4
Posts: 1359
Propmaker
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
There is a limit to how much the chip can deliver (say, 40 mA) so we are on average supplying 17% of 40 mA, namely 6.8 mA.

I can't find a definitive proof of this, maybe the electronics engineers here might like to comment?


See, that's what I want to know.  As far as I'm aware, the 74HC595 has an absolute maximum rating of 35mA per output pin.  But that doesn't mean it will stop when it hits 35mA.  That just means if you try to draw more than that you'll fry it.  I think the actual amount of current it will output would be limited only by whatever resistance there is in the chips, wire, and battery, and that would be fairly small.

Have you tried connecting a multimeter up to see how much current it says is flowing through any particular pin or led?  Maybe measure the sink side that is at a 25% duty cycle to get the most accurate measurement?

I guess if the leds aren't really bright then the amount of current must be being limited somehow.  The question is whether it is below the maximum ratings of the chip per output and for the whole chip.  Even a 17% duty cycle would explode the leds if the chip was drawing 500mA.

Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Right, well it's a bit hard to measure because the output pins are soldered directly to the tracks on the PCB.

But to try to get an idea, I broke the wire leading to the entire 74HC595 chip's Vcc pin, and measured the current on that. Presumably no output pin will source more current than the chip itself consumes. smiley

On the original sketch I measured:

Code:
Peak current:      38.6 mA
Average current:   14.5 mA

With the modified sketch I mentioned (where the LEDs were dimmer because of a lower duty cycle) I got:

Code:
Peak current:      38.6 mA
Average current:    2.5 mA

So we seem to be in the reasonably safe ballpark. Even the peak current seems to be acceptable (assuming you can average it over a few pins), and that would only be at that level for a couple of milliseconds before the blanking period cut in.
Logged

Newport, Wales
Offline Offline
Newbie
*
Karma: 0
Posts: 29
Please let the magic smoke stay inside the chip today
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Nick,

I have been playing with a similiar subject... and I too have found this a nice neat solution, with an added bonus... the led display becomes a sort of indicator.. as long as you can see more than one digit, the code is running :-) as a result, i dont bother with heartbeat leds when I use this solution.

Quote
I decided not to use resistors in the end, "live recklessly", I thought. smiley
I am using common anode leds so i went with resistors, but with common cathode why not? :-)

Thank you for sharing this post - nicely done.
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks!

The exact same circuit should work for common anode if you change:

Code:
// send to shift registers
  digitalWrite (LATCH, LOW);
  SPI.transfer (highByte (output));
  SPI.transfer (lowByte (output));
  digitalWrite (LATCH, HIGH);

to:


Code:
// send to shift registers
  digitalWrite (LATCH, LOW);
  SPI.transfer (highByte (output) ^ 0xFF);
  SPI.transfer (lowByte (output) ^ 0xFF);
  digitalWrite (LATCH, HIGH);

That inverts the sense of all the voltages and therefore should work "the other way around". Untested though.
Logged

Newport, Wales
Offline Offline
Newbie
*
Karma: 0
Posts: 29
Please let the magic smoke stay inside the chip today
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Surely for common anode, resistors are a bit more important?
I only ask as my understanding is, that the current will see path of least resistance and may accelerate degredation of the segments, or uneven illumination as each digit only has one source.

with common cathode, you dont have this problem as each segment is sourced individually.

Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Huh? I'll let my electronics experts friends respond to that, but as far as I am aware, it's just like turning an LED around. Providing you also turn the current around "the other way" it should be the same.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 38
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you for this  smiley-grin

I'm basically follwwing your wiring diagram on a breadboard for my first 7Seg LED project. Here's my display: http://www.mouser.com/ProductDetail/Avago-Technologies/HDSP-B47G/?qs=pQfy5%252bKCabKXVtjwmOMFxg%3d%3d

I have it wired up (not exactly like your diagram) and segments displaying OK (at least I can see them working - of course all 4 digits show the same thing right now), although I haven't figured out the common cathode pins yet.

I have a newbie question which I have not seen asked - how do you manage to show the individual digits without using transistors? Bear with me - I've been reading all I can for a week in this subject, and everything else I see uses a transistor hooked up the each of the common cath pins to display each digit in multiplexing.

Thank you!
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The shift register can source and sink a bit of current (something like 20 mA) and by multiplexing it is only doing a segment at a time (or thereabouts).

So basically rather than using a transistor to boost the current output, and then a resistor to limit it again (because the LEDs don't need that much) the simpler system is just to briefly send a bit of current to each LED.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 38
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks sir! Here is my (drum roll) implementation of your circuity on a breadboard! Thanks for your inspiration and help! I used your coding with some minor modifications. This is my first 7Seg LED, and first usage of shift registers. BTW - I did have 220 ohm resistors hooked up in series from the shift registers to each segment in the display to begin with, but I removed all of them to try out your method.




* SevenSeg1.jpg (107.12 KB, 640x480 - viewed 19 times.)

* SevenSeg2.jpg (142.11 KB, 800x600 - viewed 18 times.)
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 602
Posts: 33374
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Well the theory is that you are delivering higher current than it should get, for less time. So the average is OK.
Nick, no, no no.
It is the peak current that is important not the average current when considering component ratings. Have you not read my page:-
http://www.thebox.myzen.co.uk/Tutorial/LEDs.html

Quote
The Lots Of Leds shield, for example, doesn't have resistors.
So that makes it OK then? Or does it make it yet another circuit designed to destroy components?
Logged

Pages: [1] 2   Go Up
Jump to: