Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
8 years, 6 months ago.
how to multiplex displays using 74hc595
Hi,
I created follwong program: https://developer.mbed.org/users/hainjedaf/code/SPI_4x7LED/
Function 4 common anode 7-segment displays are wired to 2 shift registers 74hc595. The first register drives all segments and decimal point. The second register does digit selection which allows for 8 digits max.
This all runs off the pin5,6,7 SPI bus of my LPC1768.
I manage to make each of the digits to count from 0x0 to 0xF, one after the other
I want a counter to count from 0 to 9999 and display these values on the 4 digits. (or print and update the time from a RTC) Somehow I can' t get my head around how to achieve a routine that quickly updates the displays as to make them appear all luminescant at the same time to the human eye, yet still make it possible to update the values in between.
So far I only managed to make a counter that goes so fast, it appears as 8888. Or, it counts, but displays a value as
1----, -2--, --3-, ---4
where - is a blank.
Can someone point me?
2 Answers
8 years, 6 months ago.
Take a look at my example code for a multiplexed display. The code uses a Ticker to update an LED display with 595 drivers. See here and in the notebook page.
8 years, 6 months ago.
It looks as if you have your loops mixed up. You seem to be trying to count value v inside the digit scanning loop. Try displaying a fixed integer first, it'll make the process more obvious. Actually you could start by just outputting the digits 0,1,2,3 as a test.
I would suggest displaying each digit for 1ms, that should give a 62Hz update rate for 8 digits which should be enough to avoid flicker.
If you fill an array with the values 1000,100,10,1 you could use that to extract individual digits of a number. Take the number you want to display, divide by the value for the digit you want then calculate the result mod 10 to get an individual digit.
Well, I have different approaches: one does a 0-F count on digit 1, proceeds to digit 2 and does the same etc until digit 4 and then digit 1 again. The other does all digits at the same time 0-F and then repeats process.
I am however still in the dark as to how I make ap program that does it's thing _while_ maintaining a legible output on LED displays. In my mind's eye I see a continuous loop of (print digit, check value change, print digit......) while the rest of my program runs. And every time a value on the display changes, a global variable is used to transport the value to the 'print digit loop'.
Maybe I'm talking nonsense here, but I'm trying to grasp how to implement a quick enough way of printing digits to make them humanly legible while still running the program that caters for the display value.
kind regards marout
posted by 10 May 2016Well remember that the shift registers will hold their outputs while other things are going on, and 1ms is a LONG time for a microprocessor, you can get a lot done in that time. Wim is right that you can potentially put the display in a Ticker, and it can be a neat solution as it makes the display handler run all by itself but there are some downsides too, one downside is that it is impractical to share the SPI with anything else as you don't know when the ticker will go off. This may not matter to you though.
Anyway I'm going to assume you have a program with a main loop that runs all the time and carries out tasks in a "round robbin" fashon with no "blocking" code. Now lets say your loop time is between 100us and 1ms...
Have a digit select variable "digit_select" that's been initialised to 0. and an array "digits[]" with the patterns to display.
Select the digit corresponding to "digit_select" and output the bit pattern for that digit "digits[digit_select]", then increment the variable "digit_select" and leave the display lit while the program continues.
When the variable gets to the last digit it must be reset to zero instead of incremented so it counts 0,1,2,3,0,1...
If you do it right after 4 cycles of the program's main loop all 4 digits will have been displayed each for 1/4 of the time, and if it loops fast enough then instead of flashing visibly it smears out to a steady image.
If you do it too fast you might start to see ghosting, this mostly happens when using transistors to drive the digit "commons" if the transistor is noticably slower than the segment driver. If it becomes a problem it can be cured by using output enable to hide the transition.
posted by 10 May 2016