3 Digit Display
P1
to P2
|
A 3-Digit Display with
lots of features and many applications
- Counts to 999,999 - see text
- Measures voltages from 0.1v to 150v
- Auto shut-down
-
| |
|
This project is designed to
teach three aspects of electronics:
-
surface-mount assembly
- microcontroller programming
- microcontroller interfacing.
It guides you into PIC16F628 programming. The PIC16F628 is
the same as the PIC16F84 in size and programming features (EEPROM
programming up to 1,000 times) but has some additional features and
improvements:
- 2 extra in/out lines, an internal RC
network for clock, extra files???, extra space for a program???
and an inbuilt comparator. And it costs less than a PIC16F84!!
If you are familiar with the 'F84, you will be able to move up to
the 'F628 and take advantage of the additional features.
| |
This article
describes a general-purpose 3-digit LED display, with 2 inputs.
It's a self-contained unit with self-testing features: a push-button for
counting and a pot to indicate voltage.
Input-1 accepts pulses up to about 10 per second, for counting objects,
such as on a conveyor-belt or customers entering a shop etc.
Input-2 accepts a voltage-level and allows the display to show a
voltage readout.
The program in the microcontroller does all the work. It multiplexes the
displays and constantly checks input-1 for a HIGH and input-2 for a voltage.
When an input is detected, the program runs the code applicable to the
input so
that no switch on the inputs is necessary. Once a particular section of the program is running, the
power must be removed and the project turned on again for the other section of
the program to be
initiated.
If you want to create another application for the display, the chip will
need to be
re-programmed and the article covers this in detail.
The program for the voltage-detect also provides auto-ranging and has a
feature to detect a voltage as low as 0.1v.
The display is designed to be fitted into a case with the 3-digits showing
through a window.
A filter can be used to cover the LEDs to increase the intensity of the ON
LEDs.
Two single-sided PC boards have been used to keep costs low. They are joined
at one edge with fine tinned copper wires and folded behind
each other to
produce a compact unit.
LET'S START
We will cover three aspects of electronics design:
- surface-mount assembly
- microcontroller programming
- microcontroller interfacing.
Recently, a number of LCD displays have come on the market with 2
and 3 digits. They include a counting unit, a frequency counter and a voltage readout unit.
They are very nicely packaged and presented and the power consumption is very low.
But they are a consumer item. We are not consumers. We are design-engineers
or
experimenters and
need something that can be experimented-with and modified.
The unit described in this article covers a 3-digit display using
surface-mount LEDs and can be modified to suit almost any
application.
You will learn the principles behind the design of a microcontroller-based
display and be able to design something to suit a
particular application.
The cost of our project is comparable with the LCD version, while ours has 2 inputs
and an auto-range feature.
It's very easy to build, connect to an input and get operational.
Our projects take you further.
The theory covers how to modify the design to suit other applications.
That's why the article is longer
than normal.
In the process of modifying the design, you are learning valuable theory. The multiplexing
concept gives the impression that the micro is carrying out
two things at the same time.
The secret behind this "effect" is to carry out the second task during the
time when a value is being displayed on the screen.
The theory also introduces interfacing items to a micro. The secret behind a
simple program is the interfacing circuitry. A few
components in an interfacing circuit can change a noisy waveform into a clean
high-amplitude waveform suitable for acceptance by the input of a micro.
APPLICATIONS
There are many uses for this project.
It can be used to count objects on a production-line, customers entering a
shop, coil winding, parts-counting or anywhere things need to be counted. It
has been programmed to count to 99,999 so don't think it will run out of
numbers at 1,000!
The A to D input will detect DC voltages from 0.1v to 150v and this is
sufficient for most applications.
An immediate use for the display is in our DIGITAL BENCH SUPPLY.
The DIGITAL BENCH SUPPLY is a low-cost project that converts a plug-pack into
an adjustable power supply, suitable for your work-bench. It uses a heat-sinked
adjustable regulator to produce an output voltage from 1.2v to 14v. If the
plug-pack you are using has a higher output voltage, you will be able to
deliver this higher voltage.
SIX DIGIT COUNTER
One of the hidden features of this design is the count-feature. As soon as the
counter reaches 999, the 6-digit feature comes in.
Every 5 seconds, the count above 1,000 is displayed, then the three lower
digits.
This means the module turns into a 6-digit display.
CONSTRUCTION
The display is created with surface-mount LEDs and if you have never soldered
any type of surface-mount component before you are going to get a shock.
Surface-mount is the way of the future and there is no better time to start
than now.
If you don't have a small temperature-controlled soldering iron, now
is the time to invest in one.
The standard type of iron is really out of the question. It gets too hot
and is too big and bulky to carry out the delicate work you are about to
perform. You will also need to purchase very fine solder.
Fine solder is included in the kit but you will need more when the short
length runs out.
Using the right tools is going to make the job 10 times easier and when you
complete this project you are going to say the same as all our staff: "Surface-Mount
is 10 times easier to work with than through-hole components."
They all prefer surface-mount. It is quicker, easier and neater.
Before starting the assembly process, you need to read the article:
It will help you understand the processes involved in placing a component and
soldering it. The operation is really quite straight-forward, but you need to
read the article to re-inforce the concept.
The one thing that may be new is the use of a dob of blu-tack or other sticky
substance to allow the component to be picked up with a piece of wire such as a
paper clip and taken to the correct position on the PC board.
The component must then be held down with a clean piece of wire as the glue
will melt during the soldering process and contaminate the connection.
You don't need special glue, expensive tweezers, solder paste, or any other
device. They are just a waste of money.
Don't start soldering the display until you are fully equipped. It is very easy to
overheat a LED and reduce its brightness. A temperature-controlled iron
will allow the temperature to be adjusted until the solder is just at the
point of melting and this will give you 10 times longer to make the connection
and the LEDs will not be damaged. Collect up all the tools and you are ready
to start.
The soldering operation is simple.
One of the pads is tinned with a very small amount of fresh solder and the
iron is drawn off the pad so that no bump is created where the component will
be placed.
A LED is brought onto the board with the sticky end of a paper clip (that has
been opened out as a piece of wire) and
moved into position with the clean end of the wire.
It is then held in position with the understanding that it will not be moved
again.
This is very important.
You cannot be moving the item during or after soldering. You have to make the
decision before-hand. The leads on a surface-mount component are very delicate
and any movement may damage the component itself.
The tinned land is then heated with the soldering iron for less than 1 second
and the iron removed.
The component is now in position. This is called "tacking the component in
place."
Remove the paper clip.
Go to one of the other lands and solder the lead very quickly.
Solder the third lead with fresh solder.
Finally go back to the first connection and re-solder the lead to make a
perfect connection.
The LED is now soldered in position.
The secret to keeping the LED cool is to wait a short period of time between
each connection so it has time to cool down.
Don't keep "running around" each lead, "fixing it up" as this will gradually
heat up the LED and destroy its emission capability.
All you have to do is repeat the sequence for all the other LEDs.
You will find surface-mount soldering is quicker than through-hole componentry
as you don't have to turn the board over.
TESTING
Each individual LED on the display should be tested before the display-board is
connected to the microcontroller-board.
You will need a 3v to 6v supply and a dropper resistor. For a 3v supply, use a
220R resistor and for a 6v supply, use a 470R resistor.
Solder thick tinned copper wire to short lengths of flex to form probes and
connect the flex to the battery.
Probe each LED on the board until it illuminates. The LEDs forming the side
segments are connected in parallel and two will come on at the same time.
Make sure the brightness of each is approx the same, to create an even
display.
Any faulty LEDs will have to be replaced.
Once all the LEDs have been tested, the other board containing the
microcontroller can be assembled.
Fit the IC socket and the components to the places identified on the overlay.
The two boards are now ready to be connected.
This is done with fine tinned copper wire.
xmxmxmxm
The wires are fitted so they form a hinge. This allows the two boards to be
opened-out for testing and modification.
HOW THE CIRCUIT WORKS
The basis to the project is a microcontroller.
All the counting, displaying of digits and de-bouncing is carried out by a program in the
microcontroller.
The only thing we can cover at the moment is the connection of the LEDs.
To create an effective display, each segment needs two LEDs. They are
connected in parallel so that a 5v supply can be used.
Connecting LEDs in parallel is not an ideal way to illuminate them as one LED
will always take slightly more current than the other. If the LEDs come from
the same manufacturer, the difference between the illumination of each
pair will not
be noticeable.
If the LEDs come from different batches or are a different colour, a major
problem can arise. Each colour creates a characteristic voltage across
it and if this voltage is not delivered, the LED will not illuminate AT ALL.
For instance, some red LEDs drop a characteristic voltage of 1.7v while
super-bright red LEDs drop 2.1v. Green LEDs drop 2.1v to 2.3v and the other
colours are somewhere in this range. If a red LED is paralleled with a green
LED, the red LED will turn on at 1.7v and prevent the voltage across it rising
above 1.7v. This will prevent the green LED illuminating and you will think it
is faulty. This situation cannot be rectified. That's why it is not advisable
to connect LEDs in parallel.
But in our case, it is the only solution.
If the LEDs were connected in series, a 5v supply would not be sufficient to
active the display.
Some LEDs drop 2.1v across them and this would add up to 4.2v plus 0.4v across
the driver transistor, making a total of 4.6v. A current limiting resistor is
also needed in series with each segment to limit the current to 20mA and the 0.4v available for the resistor is too small.
The reason is simple, but the explanation is complex.
This is a very important concept to understand.
If you want a dropper resistor to work for a wide range of voltages, it must
have a high percent of the supply across it, in the initial instance.
Basically, the dropper resistors works like this: As the voltage across the
dropper resistor increases to twice the original value, the current through
the circuit increases to double. If the original value is 0.4v, and the
voltage increases to 5.4v, the current through the LEDs will increase to 40mA.
This is in excess of the allowable current and they will be damaged.
To allow a greater margin for the supply voltage, we need to have a larger
voltage-drop across the dropper resistor. The way to do this is to have the
two LEDs in each segment in parallel.
The voltage across the dropper resistor is now: 6v - 1.7v - 0.4v = 3.9v
The voltage can now fall to about 4.5v and the circuit will still operate.
DRIVER TRANSISTORS
Each line to the display has been buffered with a driver transistor. This has
been necessary to give the display full brightness. Each output of the
microcontroller is capable of delivering 20 - 25mA and while this may be
sufficient to drive a LED, we are driving two LEDs in parallel. At 10mA, the
output of a LED is starting to go dull. But the main reason for the driver
transistors is due to the display being multiplexed.
Each segment is being turned on for about 30% of the time and to create a
bright display we can do another amazing thing.
We can increase the current though the LED for a short period of time to
produce "over-brightness" without causing damage. Damage is caused by the
crystal over-heating but if we deliver a high current for a short time, the
crystal is not over-heated.
The result is a bright display in multiplex-mode.
To deliver this high current we need a driver transistor. These transistors
and associated dropper resistors are mounted on the microcontroller board,
leaving the display board clear of any components.
MULTIPLEXING
Multiplexing is a "trick." It is the art of appearing to do two or more things
at the same time.
As we know, a computer can only do one thing at a time and in our case,
the microcontroller has only enough output lines to display one digit at a
time.
For the 3-Digit Display, we need to show one digit for a short period of
time, turn it OFF, display the next digit, turn it off and display the third
digit. If this is carried out in quick succession, two or more digits can be
illuminated and our eye will assume they are all energized at the same time.
The reason for this is due to a characteristic of the eye. Each time the
display is turned off, the eye holds a mental picture of the object and
"extends" your vision. This is called Persistence Of Vision or POV. Any
flicking above about 30 cycles per second is converted into a constant image,
so that if the digits on the display are activated at a frequency above this,
they will appear to be illuminated constantly.
In our case, the digits are activated at a rate above 500 times per second and
the display appears fully lit. This is called the SCAN RATE and if the program
is slowed down, the amazing effect of scanning the display can be seen.
In computer terms, each digit is turned on for approx 600 microseconds and
this represents a delay period consisting of 600 instructions where the
computer can "go away" and carry out some other operation.
This gives us plenty of time to carry out other things during the scanning of
the display.
In this way we can carry out counting "in the background" or "looking at an
input line" or produce a sound or tone.
In other words, the multiplexing of the display is the primary concern of the
program and we fit the other operations into the "display periods."
MAKING YOUR OWN DISPLAY
One of the advantages of creating a display with individual LEDs is the
ability to make it to suit an individual requirement. You may need to
display a special character such as a dollar-sign, small digits, a logo or
special colours. All this can be done with separate LEDs and accessed as a
fourth digit or you can replace one of the existing digits.
Once you understand the "techniques of programming," anything is possible.
THE PROGRAM
The program
in the microcontroller consists of two separate paths. The path taken by the
processor depends on which input detects a signal.
The micro sits in a pre-routine called "look" where it waits for activity on one of the inputs and jumps to the section in
memory that caters for the input.
One section of memory caters for COUNTING while the other caters for VOLTAGE.
Each section is entirely separate and this has been done so you can use the
routines separately for your own use.
Within each section are a number of interesting features.
In the voltage section, an auto-ranging sub-routine detects the voltage and
selects between the low range: 0.1v to 25.1v and the high range:
25v to 150v.
In the low range, the voltage is displayed in 100mV increments. Above 25v, the
increments are 1v.
In the counting section, the program changes from a 3-digit readout to a 6-digit readout
when the count reaches 999.
ADDITIONAL FEATURES
There are many additional features that can be added to the 3-Digit Display.
The display can be turned off after a short period of time to conserve
current.
The display can be converted to low-brightness to conserve current
SELF-TEST FEATURE
The project is completely self-contained and has a press-button to check the count feature and a pot to
check the voltage feature.
THE COUNT FEATURE
The press-button has been fitted between the input and ground (via a 1k
protection resistor) so that a "sense line" and "0v line" is need for any
external push-button.
The "sense line" is the line that goes to the input of the microcontroller.
This means the display increments when a low is detected.
If you want the count to increment on a HIGH, the external push-switch must
have access to a voltage-rail or "voltage line."
 |
|
Connecting a switch LOW or HIGH |
|
Increments
on a LOW |
Increments
on a HIGH |
There is no difference between incrementing on a HIGH or LOW. Either method
can be used. Only two things have to be remembered:
1. The "sense line" has to be held HIGH or LOW via a resistor so that the
switch can alter the state of this line.
2. The program must detect when the input goes HIGH or LOW. If the
program has been designed for "active LOW" the press-button must be connected
between the sense line and 0v rail. The instruction in the program will be
BTFSC 04,3. This instruction will send the micro to a sub-routine
when the input is LOW. The input line will be held HIGH via a pull-up
resistor and when the press-button is pushed, the line will go LOW.
The opposite applies for an "active HIGH" input.
THE VOLTAGE FEATURE
A jumper is needed on the microcontroller board to activate the voltage feature. By inserting the jumper
near input-2,
the program will go to the Voltage section of the program and deliver a
readout according to the voltage picked off the supply rail by the pot. Turn
the pot and the display will display the voltage at the wiper of the pot.
A regulator has been included on the board to allow the project to be
connected to any voltage up to about 25v. The regulator will need to be heat-sinked
if the supply is above 12v as the wattage lost by the regulator will cause it
to over-heat.
The supply voltage is delivered to the pot so that you can read the value of the
supply by simply turning the pot to the maximum value.
Remove the jumper link when an unknown voltage is to be read by the module.
The module is now ready to be connected to a remote push button or unknown
voltage source.
WRITING A PROGRAM
This project covers two programs for the 3-Digit Display. There are many other
applications for this module and some of the programming concepts have been
covered in our other projects, including the 5x7 Display and PIC LAB-1.
Many constructors will want to create a program for their own application.
That's one of the main features of this project. It shows how to adapt the
display to a range of applications.
The 3-Digit Display is virtually an empty book with 3 Digits on the front
cover. All you have to do is write the program and the display will respond.
There are lots of programming concepts where you write a few lines and
the "high level language" writes the instructions for you. This approach does
not allow you see or modify the instructions being delivered to the
microcontroller and everything will be fine until something does not work.
Unless you are working at the "grass-roots-level," you will not be able to
modify things to suit your exact requirements.
That's why we have opted for the "hands-on" approach of preparing the
instructions by hand and creating everything at the MACHINE CODE LEVEL.
If any other method gave the same flexibility, we would present it. There are less
the 40 instructions to remember and instead of creating a program from
scratch, we have an entirely new method of building a program with the use of
sections of code from a LIBRARY OF ROUTINES.
This Library of Routines is covered in POPTRONICS Interactive website
in the subscription section.
Nearly everything you want to do can be given a name, and by simply looking up
the Library of Routines, you will find the code necessary to carry out the
operation.
In this way you can build up a program very quickly.
By viewing the code that will be read by the microcontroller, you know exactly
what it will be doing and you can adjust any of the operations minutely - to
the extent of one microsecond alterations.
Naturally you can go to higher level languages when a project becomes
complex, but the microcontrollers we are covering are ideally suited to being
programmed at machine-code level.
THE PIC16F628
This project is designed around the PIC16F628. It's an upgrade of the PIC16F84
and this project is part of an on-going course that uses microcontrollers for interesting projects.
If you are new to micros, you will be well advised to read our PIC
Programming Course.
There are a number of pages in the course that cover the
similarities and differences between the two chips and show how to
convert a program from a PIC16F84 to a PIC16F628.
There are also a number of projects in the FREE Projects section of
POPTRONICS Interactive the have been designed to teach the
concepts of microcontrollers.
These include the 5x7 Display and PIC LAB-1. They contain lots
of experiments to teach programming and interfacing chips to the outside
world.
Once you are acquainted with the PIC16F84, it is a small step to advance to
the PIC16F628. Once you write a few programs for the PIC16F628, you will be
able to learn about some of the additional (advanced) features such as
comparator, timers, sleep, interrupts, Capture, Compare, PWM and USART/SCI.
But in the simplest terms, the PIC16F628 is exactly like the PIC16F84 with 3
extra lines.
Some of the content of the PIC Programming Course has been reproduced below, to help you get
started. Full explanations are in the course.
The pin-out of the PIC16F84 and PIC16F628 is shown below:

The PIC16F628 can be considered as a chip with 2 ports - Port A and
Port B. All lines can be programmed as inputs or outputs and can be
changed at any time during the running of a program. Note: RA5 is an input-only
line.

The files in a microcontroller hold the "numbers" or "values"
you are working with during the running of a program. They are also called
"RESISTERS." They can also be used as
"temporary storage."

The
PIC16F628 has 96 files between 20h and 7F plus files from A0 to EFh and
120h to 14Fh, making a total of 224 files.

Memory is sometimes described as "pages of memory." Each page is equal to FF
bytes or "locations." The diagram above shows the number of pages of memory in
each chip.