Multiplexed 7-Seg Display

hippy

Ex-Staff (retired)
I finally got round to playing multiplexed 7-segment display driving; 28X1, Port B ( normal output pins ) driving anodes, Port C sinking the common cathodes. Each Port B line has a 1K8 R in series, this limits current to below 3mA out of any Port B pin, and the most any Port C pin will sink is below 24mA with all eight anodes driven, below its limit.

Not the brightest of displays ( 3mA per segment on for one eighth of the time ) but usable if you have a high efficiency display or bright enough for application, otherwise it is a case of using transistors, FET's or a specialist LED multiplex chip.

The basic control is a loop of the following running at 8MHz -

pins = %???????? ' Set segments for digit
pinsc = %11111110 ' Sink cathode of digit 1
PauseUs 100
pinsc = %11111111 ' Don't sink anything

Repeated eight times, shifting the %11111110 to %11111101 etc for each digit in turn. Delays to about 2ms work without flicker. You'd get extra brightness by using an external 16MHz crystal and doubling that delay.

The 2ms on period can be used to sample ADC, check for SERIN, read and process data, and interrupts won't cause any over-current problems ( all are in-spec ) but digits will get brighter during those times. Alternatively, reads etc can be done at the end of the loop and the display will dim during processing. Flicker will start if processing takes too long, but it can perhaps be spread throughout the on periods.

Seems to be working well, the biggest job is wiring everything up ! Not finished that yet.


Phase II - Into the Unknown

This may be a question for Dr_Acula because I'm sure he's done similar, but anyone can chip in ...

By reducing the on time and increasing the off time it is possible to also decrease the R; the average current over the time period remaining the same. It is theoretically possible ( but not good engineering practice and puts a PICAXE / PICmicro out of spec ) to drive LED's with no R at all.

With no R's, all eight Port B anodes sinking into a single Port C pin, does anyone have any idea of what would be a workable on / off period without burning out the chip with undue haste ?

For the sake of eight R's it may not be worth the effort or risk but it's a question bugging me and I don't know the answer.
 

hippy

Ex-Staff (retired)
After some further experimenting the issue of no R's may be moot.

I calculated 1K8 based on a segment LED with a Vfwd of 0.5V, so V=IR, 4.5V / 3mA = 1K5, rounded up to 1K8 I had to hand.

With the multiplex giving approximately 80% on, 20% off on the sinks, 25mA can rise to around 30mA, divided by 8 ( per anode ) that's 3.75mA, and back to V=IR, 4.5V / 3.75mA = 1K2, which is a standard R and makes the display of entirely suitable brightness (YMMV).

I may also have greatly under-guessed the Vfwd of the LED which would allow the R to be reduced further.
 

MPep

Senior Member
Hi Hippy,

See this site: http://members.cox.net/berniekm/super.html.

In this example, you will see that there are 4 7-segment LED displays in one package, all being controlled without any resistors.
It is the power dissipation that you have to watch out for. For example: a brief 40mA pulse for only 10% of the time, calculates to an average of 4mA. At least that is what I have seen many times in literature.

I have actually built one of these SuperProbes, but it is not very bright. I suspect thought that that may have to do with the choice of LED display that I had,

Mark.
 

hippy

Ex-Staff (retired)
Thanks Mpep for the link and the confidence from knowing you've done it.

The prototype without R's is working fine on my desk, showing over 40,000 seconds ticked-by with no smoke or any other disasters. Maybe I'm lucky with my LED's as the display is certainly bright enough.

Refresh rate wasn't much of a problem as it's multiplexing a byte at a time so only 8 multiplexes per loop rather than 64 for a traditional 8x8 segment at a time scheme.

Biggest issue was, as expected, flicker as it leaves the refresh loop, reads new data and starts again. On top of that, being byte at a time, there seems to be some current limiting as all eight segments sink into a single port pin so length of time each is on for has to be proportional to the number of segments lit to balance digit brightness. That of course needs calculating for each digit which adds to the time outside of refresh.

I've mitigated that a lot by interleaving things through the refresh cycle and only doing one thing each time through the loop so now it dims rather than flickers off so badly. It's tolerable enough for me. Not so good for fast changing data, but okay for slow updates, clock displays, reporting fairly static sensor results etc.

A 'proper display multiplexer' is obviously better but given this works, used bits I had to hand, doesn't involve SMT, is single-chip, connects direct to a PC's serial port, does ASCII conversion and everything I need it to, I can live with its minor downsides.

I'll look at getting some photo's and source code sorted. Circuit digram in the next post as it's pretty simplistic.
 

hippy

Ex-Staff (retired)
Code:
PICAXE-28X / 28X1 - Crystal required for 28X operation

        .----------.
        | A0    B7 |---------------------------------.
        | A1     : |       :                         |
        | A2    B0 |-------------------.             |
        | A3       |                 __|_____________|__
        | A4    C7 |----------------|                   |
        |        : |       :        |  8 8 8 8 8 8 8 8  |
        | SO    C1 |----------------|___________________|
        |          |
    .---| SI    C0 |<--.             8-digit / 7-segment
0V _|_  `----------'   |
                       |      Note no drive resistors are used
                ___    |
RX >-----.-----|___|---'
        .|.     22K          The 22K and 10K can be omitted when
        | |                  driven directly from another PICAXE
        |_| 10K
     0V _|_                Decoupling capacitors and PSU not shown
 

dennis

Member
I have just acquired a 4 digit multiplexed LED display and your set up with a 28X1 looks ideal. You have obviously done a lot of work on this to minimise flicker , keep brightness constant etc and I wonder if you could publish the source code.
 

nbw

Senior Member
Hippy, this is a very timely thread for me. I just got hold of some tiny 12-digit red common cathode displays from Oatley Electronics. It struck me that one would need 20 output pins to drive it fully - a bit of a waste of a 28x2.

I started to think about using a 4511 IC, that would get the seven segments down to four. Then I wondering if there might be a similar IC, where I could feed in four inputs which would translate to one of 12 outputs for the displays?

That way I could get away with using 9 outputs - 4 for the digits, 4 for the segments, and one for the display.

I'm not clued up on if there is such a chip, but it would mean I could use an 18x (with no dps) or a 20X2 / old 28x1. Other option is a MAX7300 expander, but I'm thinking a couple of 4xxx series ICs might be the way to go.
 

nbw

Senior Member
p.s. red LEDs generally have around a 1.5 - 1.7V Vfwd drop from memory, although you prob know that by now.
 

nbw

Senior Member
also thinking about speed and flicker - 12 digits would be quite intensive. An 18X at 8Mhz might be quite slow. Maybe a 28X maxed out at 16Mhz or a 28X1 at 20Mhz would cut it.
 

nbw

Senior Member
Aha! Idea! How about a CD4051 multiplexer? That would take 3 lines from the picaxe and give a 0-7 number out of the other side of the IC.

A better one might be 74150 - 4 in pins needed, but will multiplex up to 16 lines. I could drive the 12 displays easily then.

So, maybe I could use 3 picaxe OUTs for the muxer, 4 for a 4511, 1 for a dec pt.... !

If I can't get a 74150, I could use a 4051 for the digits 0 - 7. I could then take a line from an active 7 digit to drive the first input line of a 4052, which takes 2 inputs to mux 4 values. That way I could get the 12 digits.

How does this sound to others out there with experience in muxing? Do you think the mux-BCD decoder 4511 will work?

Hopefully these 2 dedicated ICs can control the displays faster than the picaxe. There's still the issue as Hippy raised about current - I'd need to ensure the muxer can handle small currents and not overload it.

This little display uses about 1mA per segment, so could be up to 8mA for an '8.' Hopefully I can get away with not adding transistors all over the place.....................
 

westaust55

Moderator
Mulitplexing can result in flicking on the displays unless you can achieve a faster cycle time through all digits and unless you are using some more complex chips dedicated to multiplexing requires considerable portion of the PICAXE chips power to run the multiplexing.

You have mentioned simple chips such as the CD4051 and 74150 so seems you are happy to contemplate simpler hardware structures.

Accordingly, if you are trying to keep it very simple, happy to consider non-multiplexed methods and did not mind having say 12 separate 7-seg driver chips, one method that would:
- have no flicker
- not use a lot of PICAXE program/time resources to keep the display illuminated between changing numbers
- only needs 3 PICAXE outputs
- possibly be a little slow to initially get the new set of digit out to the displays

then consider a series of 12 cascaded humble 74HC595 shift registers.

I did a demo using 3 displays recently. Have a look at:
http://www.picaxeforum.co.uk/showthread.php?t=13687

From some tests I did, I could output 10 new sets of 3 digits per second with bit-bashing code that all PICAXE chips can use. From tests with an LCD module, if you have an X1 or X2 chip, then using the SHIFTOUT command can increase that speed by ~10.
So tentatively with 12 digits and doing nothing else, you could achieve 2.5 updates per second with any PICAXE or likely around 20 updates per second using the SHIFTOUT command with an X1/X2 type PICAXE.
 

moxhamj

New Member
I've been pondering 16 segment displays (like 7 seg but with extra leds to do M and W etc) and even 7x5 matrix displays. This came up in a discussion on the propeller forum regarding how you keep the brightness acceptable. The usual way to run a 7seg led is to send 7 bits to each segment, and then sequence the common cathodes (or anodes) in turn. It works fine for a few displays, but the brightness dims with more displays and it becomes impractical with 20 or 30 digits. You wouldn't need that many for numbers but you might for letters.

So - this is a concept I'm still trying to get my head around. Instead of multiplexing digit 1, then digit 2, then digit 3 etc, you apply current to segment A and turn on all the displays that have segment A on. Then repeat for segment B. This means that each led is on for 14% of the time, no matter how many digits you have.

I'll describe this for a common cathode 7 segment display. Consider 10 digits and 10mA per segment. Turn on a high side switch (standard 2 transistor NPN and PNP circuit). The current sets which transistor to use, and there are pretty standard selections <100mA, 100 to 800mA and 800mA plus. So, we turn on segment A with one of seven high current high side switches. That is the complicated bit. On the common cathode side, things are much simpler. There is one current limiting resistor on each common cathode. Each common cathode line only needs to drain 10mA. If you went for 5mA maybe no switching circuit at all - perhaps it could all go into a picaxe or a 74HC latch eg 374 or 574. At worst the common cathodes could be switched with BC547s.

So - the 'standard' way uses 7 lines for the segments and 10 lines for each display = 17. As you add more displays though it gets dimmer.

This way also uses 17 lines. You need a few more components on the high side switching. But you can add as many digits as you like and it never gets dimmer, and if you want to try 2 or 3mA (which many high brightness displays work fine with), then the common cathodes can go straight into a picaxe.

I'm still trying to get my head around the maths, but I think with less than 7 digits the standard way of doing it is better, with 7 digits both systems are equal and with more than 7 digits this method is better for flicker and brightness and component count.
 

hippy

Ex-Staff (retired)
This is the code I have for multiplexed 28X, 28X1 and 28X2 8 x 7-seg display ( no decimal point control ).

Comes entirely without any warranty, destroy or damage the display or PICAXE, or anything else, and that's your problem. This is my own code produced as an individual and there is no come-back on Rev-Ed whatsoever. Don't use the code if you don't agree with that any of that.

Note the comments about how to setup the pulse times. The reason I was ( am ) cautious about releasing the code is that if you get it wrong it can burn out the I/O lines. I'd recommend using with a current limited supply until happy with it.

As can be seen in the top comment I was looking at improving the code for 28X2 but didn't get round to it. It should however work as is.
 

Attachments

nbw

Senior Member
thanks for your thoughts all. I'm after a middle-of-the-road solution, I think, whereby I don't have to add too many extra ICs, and still have some picaxe outputs spare.

I could possibly do a 28X1, and maybe with 2 1-8 muxers drivings 2 x 4511 ICs, that would run my 12 digits ok at 20MHz. Given the small cost of the a 1-8 muxer (I have some 4511s kicking around) I might get one and have a play.
 

manuka

Senior Member
nbw: FWIW -NZ's infamous "Red Shed" chain have a massive LED Xmas light range at present, & these caught my eye for cheapness -NZ$19.95 for 100 LEDs c/w pattern controller & mains plug pack. That's < 20c a LED ! They're essentially of course wired in parallel, so snipping off a few for trials is near incidental to intended performance.

However its the MEGA brightness of the red LEDs that's been a bonus, as astoundingly even just 20 microAmps current thru' the reds made them visibly glow. As much as -quelle horreur ! - 1mA made them almost EVIL in brightness. Whoa -cooking LEDs normally draw 10mA just for boring status use, so these are at least an order of magnitude superior, yet cost me only ~a US dime (10¢). I've been playing with LEDS since the ~1mCd GaAsP days of the early 1970s, but have never previously seen such spectacular output at these low prices. Three cheers for Haitz's Law !

At such trivial currents you could run scores off a single PICAXE pin to suit static names, house numbers & cafe style "OPEN" messages etc. Such so called LED Art is apparently considered very leading edge (mmm-LEDing ?) by those in the know. Hands up who wants an Arts Council grant ? Stan
 

Attachments

Last edited:

westaust55

Moderator
Another low chip count option is using MCP23017 i2c IO expanders.

Using multiplexing, I drove 64 RGB LED’s which equates to 192 LED’s using two MCP23017 i2c IO expander chips a while back. The two MCP23017’s give a total of 32 IO lines which I set all as outputs.
All covered in this thread:
http://www.picaxeforum.co.uk/showthread.php?t=10836
Post 30 and 31 and later in that thread have photos code etc.

Would still be another task to work out how to do something similar with 12 x 7-seg digits but even with decimal points it would certainly be doable. May also need to operate the PICAXE at around 16MHz to avoid flicker.
Dr-A’s approach to control all segment “a” then all segment “b” , etc decreases the cycle time to 7 or 8 steps and should make a great improvement over driving digit 1, then digit 2 . . . which would take 12 steps before a repeat.
 

dennis

Member
Hippy,
many thanks for the code, looks very comprehensive. I am looking forward to trying it when I get home in a week or so.
 

manie

Senior Member
Funny how with very nice LCD's and easy multi-character displays, the 7-segment STILL surfaces as required. Must be something with some of us "oldies" not requiring spectacles to read the result off an LED display ???
 

Dippy

Moderator
Well I'm amazed how many discretes are still around.

LEDs have a valuable place though.
If you were a small/medium manufacturer and wanted simple inch high numeric displays then 7seg are cheaper (and overall smaller and, arguably, easier) than custom LCDs or a GLCD+driver.
And service/replacement parts.
And at lower temps LCDs become sluggish and eventually fail.
And LEDs don't suffer angle-of-view issues.
So LED 7seg/Starburst and similar will be around for a while I reckon.
 

nbw

Senior Member
Well, now that I'm 40 and officially an 'oldie', I actually prefer LEDs. LCDs are great for low current, and ease of displaying, but LEDs are... just cool. I still recall my calculator given to me when I was 8 by my gran - it had these cool ligit digits that glowed in the dark. I used to fall asleep at night thinking of words to spell when turning the calculator upside down e.g SHELLOIL from 71077345.

:)
 

westaust55

Moderator
And at lower temps LCDs become sluggish and eventually fail.
That a bit contrary to my experiences.

I had a Citizen brand watch with an LCD display that as the battery voltage started to drop near end of battery life,
the LCD dispay would fade out in higher daily temps - dull by around 10-15 degC and invisible by 30 degC
but each day in the early hours of the morning when the temp dropped to around -2 degC to 0 deg C the digits on the LCD display were dark and clearly visible.

As I was camped out in the desert country of central Aust , I had to put up with that for some time until I had the opportunity to go into a town and buy a new battery.

Same thing happened a number of time over the years - so dull display in warmer temps became an indicator that the battery was "on the way out"
 

Dippy

Moderator
Well, I am sure. I've seen it on many occasions.

And I knew there would be at least one that would be contrary :)

If you contacted LCD manufcaturers you would be aware that there are special LCD units which behave faster at lower temps - it is a known fact and these people don't make thesethings for fun... or do they?

"Instead of taking the usual two or three seconds to refresh at -20 degrees C, the addition of the clear screen heater will improve response time to two to three times per second"
- from Densitron.

"The fast-response OCB technology has also solved the problem of deteriorated response time at low temperatures inherent in the case of LCD panels."
- from Toshiba.

I'll email them and tell them they've been wasting their time ;)
 

moxhamj

New Member
I'm sitting here surrounded by LCD displays (8x2 up to 20x4) but like nbw (and being the same age!) I think leds look cool too.

I'd love to get a starburst display (or 10) running on a picaxe. I'm still musing what it would take - probably one of the newer X2 chips when you factor in the higher clock speeds and the need for some storage area for the ascii character set. And if that works, maybe a few 7x5 displays?

As an aside, like westaust, I've had LCDs not work at higher temps. I was using my multimeter just the other day in the field, 40C outside in the sun and the display went black. Had to go and sit under a tree for a while just to read a voltage!

But to be honest, the real reason for interest in led displays is... they look cool.
 

Dippy

Moderator
Temperature effects on LCDs are well known.

First check your Data Sheet, then just think of the poor old molecules.

It's well known that the driving voltage (the Vee thing you can twiddle with your pot.) may need to be changed over the temperature of operation to maintain contrast ratio.

I believe that some LCDs have auto adjustment of the driving voltage wrt temperature.
A feature that would be quite possible in a PICAXE project.

It's widely known that the liquid crystal material can be permanently damaged by very low temperatures. "very low" meaning very sub-Zero oC.

So, in summary, as well as looking "cool" LEDs are just more robust.
Horses for courses.
 

nbw

Senior Member
Hi West, just had a look at the 23017 ICs you mention. They look pretty good. Futurlec have them for $1.50 - much cheaper than MAX7300s. They also have an SPI version which runs 25x faster! only $1.69. Wow.

I might be able to get away with a 23017 to drive the 12 digits and a 4511 to drive the segments. Or another option might be to have a 23017 for the digits, and another for the segments. Both operating at 400kHz "fast" mode.

Now, do 18X go to a max of 8MHz? 16MHz would be an obvious easy way to ramp up speed. I have a 28x1 in the wings, but have a few of these "old" 18xs lying around, cute little guys with their 2K prog space... soon to be replaced by the new 18-pin picaxe, I expect :)
 

westaust55

Moderator
Now, do 18X go to a max of 8MHz? 16MHz would be an obvious easy way to ramp up speed. I have a 28x1 in the wings, but have a few of these "old" 18xs lying around, cute little guys with their 2K prog space... soon to be replaced by the new 18-pin picaxe, I expect :)
18X can only operate at 4MHz and 8MHz.

28X1 can go to 20MHx with external resonator though some commands like SEROUT only have “factors” for up to 16MHz. A few commands are also limited to 4MHz (see manuals)

See the SETFREQ command in PICAXE manual 2 page 185.
 

nbw

Senior Member
Just also noted there are some subtle (and some less so!) differences between the 23016 and 23017. Seems the 23016 - despite being 70c dearer - is easier to use, but the 23017 has a little more functionality.

Ah yes, the old fly like a rocket at a higher freq trick, then slam on the brakes for a DS18B20 readtemp12, then hit the gas again.......... ;-)
 

nbw

Senior Member
Also noticed just then that the 23017 can handle an absolute max of 25mA per pin. If I had the same segment on across all 12 digits, it would come to about 8 - 10mA, which isn't too bad. (A '7' and a '.' used 1.83mA)
 

westaust55

Moderator
MCP23017 dual 8-bit IO expander

IMHO use the 23017 over the 23016.

The 23017 has:
- all the pins for both ports in a sequential group for ease of PCB layout or connections.
- a mode whereby you can write two consecutive bytes of data in a single writei2c/hi2cout command to control all 16 pins across the two 8-bit ports.
 

lbenson

Senior Member
>Do Microchip still do samples?

$7US handling charge last time I checked, a couple of weeks ago. It could still be worth it, of course.
 

Dippy

Moderator
Last time I looked they (Microchip Direct) charged... unless you are a wonderful customer.
i.e. bought something as opposed to scrounged it ...
... which is probably the reason they introduced the charges - thank goodness.

Boriz, just get a friend/parent with a credit card to order a couple from Farnell. You should have them the following day. Don't be scared, they don't bite.
You wil have to wait 2 or 3 weeks this time of year if getting a sample from Microchip.
I've been waiting for 10 days so far for some items.
 

nbw

Senior Member
I just signed up at Microchip to scrounge, I mean, sample a couple of 23017s and 15 bit ADCs.... the $7 charge disappeared 1/2 way along the order process.
 
Top