Here we go...it's PCB layout time! Here is the schematic re-drawn and ready for PCB layout. I have added a 5V fixed supply to the circuit because I would like to add a digital voltmeter to the circuit so we can monitor what the output voltage is set at. After investigating panel meters on-line I found that they require a separate supply in order to work correctly. Other than this the circuit is the same as in the previous post.
Now that we have designed the variable power supply it's time to make a printed circuit board to mount the components onto and route the connection tracks. For PCB layout I use Eagle Cad from Cadstar because it's free up to a point, has great component libraries and support via forums from thousands of people.
There are thousands of PCB layout tutorials for eagle available so I'm not going to go through the nuances of doing PCB layout unless requested. I don't consider myself very good at this particular aspect of electronics. I know the theory but I don't have much experience in the practical. Professionally I sub-contract PCB layout out to someone else but because this is for me personally and anyone reading this the following guidelines are always good:
Lay out the components on a suitably sized PCB first.
Set the grid size to something sensible. I used 1.27mm and 0.635mm for my grid size
One you have a general idea of the component location select a suitable track size. Thicker for more current carrying capability.
Try not to cross tracks.
Once you have all of the tracks routed perform an electrical rules check
Tear-drop the pads once you have completed all of the above tasks.
Finally resize the PCB if you can. Less board = cheaper manufacturing costs
I shy away from auto-routing functions in PCB layout tools as they always seem to do a poor job! I have heard of other people find these work well but I have had mixed results. I have always found for more simple circuits it is much better to route the tracks by hand. The PCB layout for this circuit is shown below:
I chose a thick track size on purpose as I wanted to be sure that there would be enough current carrying capacity in all of the tracks. This might be a bit overkill but it at least it saves on copper. I also didn't use a ground plane on this design as it isn't really necessary.
All that is left to do now is to actually make the PCB. When I do this I use the toner transfer method of making a PCB. That involves printing out the design in reverse (like in the above picture) on a laser printer. I then get a piece of blank PCB. I'm going to use a 160mm x 100mm blank PCB and cut it down to size. I'm then going to clean the PCB thoroughly and then placing the print out of the layout ink-side down (actual size) onto the copper, and using a clothes iron, transfer the pattern. The iron should be set to as high as possible - ENSURE there is no steam or water in the iron. Firmly press and iron the paper for about 5 minutes. Then switch off the iron and wait for the PCB to cool...it will be too hot to handle. Once cooled run the PCB under water to 'soak off the paper'. What should have occurred is that the design has transferred from the paper onto the copper of the PCB. If it hasn't worked clean the PCB off and repeat the process. Next etch the PCB in ferric chloride or Muriatic acid...whichever you prefer. I use ferric chloride because I find it gives me a better etch and because Muriatic acid (Swimming Pool Cleaner) is hard to get hold of in the UK.
That's about it for now. Next post will be the actual building and soldering of the supply with photographs! For those that might be interested here is a good tutorial on PCB layout:
Update: I found having constructed the above circuit that there was a mistake in both the schematic and the PCB. I have updated both to resolve the issue. I missed out a connection on the schematic which prevented the supply from going low. The variable resistor needs a link from the middle pin (wiper) to the top pin so that the voltage output of the LM317 can be reduced down to 1.25V
Here is the component placement in case someone needs it!
Still getting on with the job of designing a linear power supply!
Last post talked about smoothing and why large electrolytic capacitors are used to remove ripple. This post is going to talk about voltage regulators.
The voltage output from the previous circuit although now nice and smooth will not be constant. As soon as an electronic 'load' or impedance to use the proper term is placed across the positive and zero volt terminals the voltage will drop because there is not a constant current present to drive the load. The circuit that fixes this problem is called a voltage regulator. There are many different types of circuits for making voltage regulators and they all have their place. I don't intend going into all the different types of regulator here. If people are interested the web sites below maybe useful:
Essentially a voltage regulator is a special circuit that provides a constant voltage to a current controlled device which keeps the output to the load constant whether the load or the supply are changing. We know that the supply isn't constant as the transformer is supplied with an AC voltage which switches polarity every 10ms and the load attached to the output may not be constant either.
The constant voltage output is usually achieved by using a special diode called a Zener diode. These devices are a special kind of diode which allow current to flow in both directions once a certain voltage is applied to the anode. Zener diodes are used to provide a constant voltage reference. Check out all about circuits page in zener diodes for more information here:
The next part of the regulator would be made up of a series pass transistor. This is normally a high current transistor which is permanently switched on by the zener diode and a resistor and is used to keep the current output constant. So by implementing the circuit below we have a constant voltage regulator. To keep the theory simple I have selected a 12V zener diode and that is what decides our output voltage for the power supply.
If we were to implement the circuit above it would provide us with a constant 12V (all right 11.643V) output whatever load was attached. However there are better and easier ways of implementing the above circuit (Series voltage regulator) using an integrated circuit known as the three terminal voltage regulator.
There are literally hundreds of different types of three terminal linear voltage regulators - some of the more popular ones are the ubiquitous 78 series which are a fixed voltage output linear regulator. Another might be the LT38 series.
For my power supply though I wanted an adjustable voltage output and so I'm going to use an adjustable voltage regulator - the venerable but useful LM317. There are many manufacturers of this device but they all perform the same function. The datasheet and application note for this regulator from Texas Instruments are here:
The circuit will now look like this. This circuit is directly taken from the information provided in the datasheet. All the information needed to design the circuit is there. Datasheets are like rosetta stones to electronics design engineers. When they are well written they can make our lives so much simpler!
You may have noticed I have added some extra components to our circuit. R1 is what is known as a 'bleeder' resistor. This is so that when power is removed from the circuit the energy stored in the electrolytic capacitors is safely drained away. Otherwise the capacitors can remain charged for a very long time and store a lot of energy which will be released when someone (normally me) shorts the output by mistake. The diodes D4 and D3 are protection diodes for the regulator IC. They protect the regulator from short circuits and transients caused by capacitors discharging. The resistor R5 and the LED are for indication purposes. Its always good to have visual indication that the power supply is switched on! The variable resistor R3 is to allow the user to vary the output voltage from 1.25V to about 40V. R4 is part of the voltage divider which sets the output voltage. C4 and C6 are ripple smoothing capacitors for the output. Finally I added a voltmeter so that we can see what the output voltage is set at when using the circuit.
Well...thats it for now folks. More to come soon! Enjoy and take care - Alex
In the last post I wrote about some of the design considerations that are needed in designing a linear power supply and how mains ac voltage can be 'stepped down' and rectified into dc using diodes. The next thing that most people do when designing power supplies is called 'smoothing'. This is where the output waveform which is regular but not flat is made more flat and smooth.
The first question one might ask is why do we need to smooth the output? One answer is because the designer is trying to replicate the output of a chemical cell (battery). The output of a battery which is direct currrent (dc) is very smooth and flat. This is because batteries work on the principle of electrolysis and electrons travel from the negative terminal to the positive terminal through the circuit in a constant stream. The flow of electrons (current) is only slowed down (resisted) by the total circuit resistance which includes the internal resistance of the battery. There is no switching or quick changes of polarity like there is with an ac power source (no 50Hz power cycle here) and because there is no switching unless introduced in the circuit on purpose (oscillation) the output of the battery will be completely smooth and flat.
Another reason for smoothing the power supply output is to prevent the circuit from reacting strangely to the constant change of voltage coming from the not smoothed supply. Suppose we have a circuit that is using a change in voltage to detect something like a temperature sensing circuit. If we use a smoothed dc supply the circuit will measure the current temperature accurately because the supply voltage is in a constant steady state. If we use a not smoothed dc supply the sensor output will fluctuate with respect the changing voltage of the supply and the sensor output would be meaningless.
The upper circuit above shows a 12.3V battery supply connected to a simple voltage divider made up of a 10k resistor and a temperature sensor. For the simulation the temperature has been set to 27 degrees C. The output voltage and current is shown in the yellow box. The output is also connected to an oscilloscope.
The lower circuit shows a 14.8V 50Hz ac supply (the output from a linear transformer secondary winding) connected to a bridge rectifier made up of four diodes. It is then connected to the same voltage divider made up of a 10k resistor and a temperature sensor. The ambient temperature is also set to 27 degrees C.
The top circuit will accurately measure the temperature because the voltage supply to the voltage divider is constant and smooth. The lower circuit's measurement will fluctuate considerably because the voltage supply to the divider is not smooth. If only the average temperature measurement is required then there would be no problem using this power supply but if the user were logging the data regularly - lets say every 1ms then the bottom circuit's measurements would be incorrect and the temperature would look to be varying with the same frequency as the power supply input.
So that is the reason that smoothing is applied to the rectified output of a linear power supply. It is to make the output constant, regular and as similar to the output of a battery as possible. It prevents strange measurement errors and erroneous circuit behaviour occurring.
In order to smooth the output from the diode rectifier section capacitors are added to the circuit across the supply. To remove the low frequency 'ripple' large value electrolytic capacitors are required. For high frequencies medium value ceramic capacitors are normally used. The large electrolytic capacitor charges up from the applied voltage from the rectifier when the output rises the capacitor charges. When the output from the rectifier lowers the capacitor then discharges. Because there is not enough of time between the rectifier output fluctuating and the capacitor charging and discharging the dc voltage output remains more constant and therefore becomes smoother. The charging / discharging time for a capacitor can be found by two formulas. I will go into more detail on the charging and discharging of capacitors in another post. The formulae are:
Vc = Vs * (1-e^-t/C*R) - For a capacitor charging
Vc = Vs * (e^-t/C*R) - for a capacitor discharging
The updated circuit diagram for the linear power supply that we are designing is shown below:
It should be noted that almost any large value of electrolytic capacitor could be used and the higher the value the more low frequency 'ripple' will be removed from the power supply output. The capacitors selected must be rated to withstand the supply voltage - in our case this would be anything above 32 Volts dc. The 100nF capacitor can be of the ceramic type and should also be rated to work at voltages greater than 32V dc. The type of capacitor is related to it's dielectric material - another subject for another post.
There is a formula for selecting the smoothing capacitor to remove 10% of the ripple and it is as follows:
Smoothing capacitor for 10% ripple, C =
5 * Io
Vs * f
C = capacitance in farads (F) Io = output current from the supply in amps (A) - yet to be selected in our case! Vs = supply voltage in volts (V), this is the peak value of the unsmoothed from the rectifier output f = frequency of the AC supply in hertz (Hz)
Lets set the value of Io (current output) to 1A. If we plug in the values from our design we get:
C = 5 * 1
32 * 50
C = 0.003125 or 3125uF so the closest real value would be 3300uF which must be rated for 32V. To be on the safe side I would use a 50V rated 3300uF electrolytic capacitor. If a lower capacitance is used the ripple will be greater than 10%. The capacitor must be rated for the supply voltage!
The oscilloscope output for the smoothed and not smoothed circuit is shown below. It is pretty obvious that adding the capacitors makes the voltage output very smooth and flat which is what we were looking for. The red trace is the not smoothed rectifier output and the blue trace is the smoothed output after the capacitors.
The next post will discuss power supply regulators - what they are and how they work. That's all for now folks! Take Care - Langster!
Hi people...I know I have still to finish the chess clocks. For now though I though I would do a post on power supplies.
I recently donated my bench top power supply to my local Hackspace - HACMan at Madlab!....As usual I then needed it to do some prototyping work. One thing every budding electronics engineer or hardware hacker needs is a good power supply. Rather than trek to the Hackspace to get mine back I'm going to design and build another!
There are many tutorials out there for building a power supply but seeing as I need one I thought I would write my own after having to go through it for myself.
There are some design considerations to choose before making a power supply:
Type - Linear or Switch-mode
Variable voltage or fixed
Variable current or fixed
Over current protection
Short Circuit protection
Most of these things are dependent on the type of regulation that is chosen. I have decided to use a linear supply in my case. These are power supplies which use a linear transformer - a device used to convert the ac mains voltage from 230V UK Mains voltage down to a more useful and safer low voltage. In this case I would like a supply that has variable voltage and current control from around 3V up to 30V with at least 1A current. I also will need a way of displaying what the actual voltage and current setting is so we will be adding some panel meters.
How do these things work? Electricity comes out of the UK mains socket as 230V r.m.s. alternating current or ac at 50Hz. What exactly does that mean?? Well it means that the electricity has a maximum electrical pushing force of 230V and that the polarity changes direction every 10ms or 25Hz. For definitions on basic electrical theory and general physics here is an excellent website:
It covers everything in a lot more detail than I intend to go through in this post. So back to the subject.....
For those who don't know electricity is generated by rotating a permanent magnet in a coil of wire. The magnet turns in a circular motion. The more the magnet moves the more electricity is generated. The speed of the magnet turning is directly related to the frequency of the current. Every time the north and south of the magnet are reversed the current changes polarity. The circular motion causes the output to be sinusoidal and if we were to plot a graph of the output it would look like the picture below:
I have put several scales on the x axis so that it can be seen that the voltage changes polarity with respect to time and therefore frequency. Frequency is the inverse of time or frequency (Hz) = 1 / time (seconds). I also put degrees and radians on the graph as the change in polarity can also be related to angular motion (the magnet rotating in the coil). This is known as alternating current and it is the type of waveform that would be seen if you were to take an oscilloscope and measure the output of a mains outlook socket. (I don't recommend doing this unless you have a suitable high voltage ac scope probe!!!)
The ac waveform that comes out of the sockets will be 'stepped down' or transformed into a smaller voltage using a linear transformer. A linear transformed is an electronic component with the symbol shown below:
It is really two inductive coils placed next to each other with a laminated iron core running through each ring. For a step down transformer the first inductive coil known as the primary will have more turns than the second coil or secondary. The difference between the coils is known as the turns ratio and this can be used to calculate how much the voltage will be 'stepped down'. The formula - helpfully known as the turns ratio is as follows:
Np : Ns = Vp : Vs
Np = Number of turns on primary coil
Ns = Number of turns on secondary coil
Vp = Voltage at primary coil
Vs = Voltage at secondary coil
So lets use the formula to calculate the turns ratio of the transformer that I need for my 3-30V transformer. We know that the mains voltage is 230V and we know that we want at least greater than 30V at the output. To make things easy lets say 32V. Lets plug those values into the formula:
Np : Ns = 230V : 32V
Set Ns = 1 and therefore
Np = 230V / 32V
If we then calculate the ratio we find that:
230/32 = 7.1875
So from this we find that we need a transformer with a turns ratio 7:1. This will 'transform' the mains voltage from 230Vac to 32Vac.
If we were to draw a schematic diagram of what we have done so far it would look like this:
If we were to attach an oscilloscope to the circuit and measure the input and output we would see the waveforms below:
Note: The Y scale or volts / division setting on the oscilloscope is the same for both graph traces (200V/div). The red trace is the mains input or Vp and the blue trace is the 'stepped down' output or Vs.
Now that we have the voltage at a more manageable and safer lower level we need to convert it from alternating current (ac) to direct current (dc). There are several methods of doing this and most of them involve using semiconductor rectification or diodes.
The diode is an electronic component which acts like a kind of electrical gate. It only allows electrical current to flow through it in one direction. They are made up of something called a PN junction. What is a PN junction? Well this can get complicated but in its most basic form a diode or PN junction is a two pieces of silicon (or germanium) sandwiched together. Before the two pieces of silicon were joined together they were treated in a special way in order to make one side more positive (P-type material) and one side more negative (N-type material). The process is known as 'doping' and to make the semiconductor more positive the molecular structure of the silicon has had electrons removed to create 'holes'. The N-type semiconductor material does not need anything added to it to make it more negative. The silicon already has electrons present which make it negative.
The anode is the positive terminal and the cathode is the negative terminal. We are going to use diodes to turn the ac output of the transformer secondary into direct current (dc). The diodes will stop the current alternating and going negative. It should be noted that diodes will only do this once they have 0.7V present at the anode. It also means that our output circuit will lose 0.7V every time we add a diode. In the circuit below a diode has been added to one of the transformer secondary outputs. The resistor is purely a load for the electronic circuit (spice) simulator.
The oscilloscope output looks like this:
The output is now always positive in the positive portion of the sine wave or positive half cycle. The negative half cycle is not present. This is known as half-wave rectification Adding more diodes to the circuit causes the negative portion of the sine wave to be rectified. This is known as full-wave rectification. To get full wave rectification for our circuit we will need to make what is called a diode bridge or bridge rectifier. It is possible to buy bridge rectifiers as single parts but we are going to make one from four separate diodes:
The oscilloscope output will now look like this:
As can now be seen all of the output from the transformer is now positive. If we were making a rugged battery charging circuit or we needed a dc current supply for welding we could use a circuit similar to this. For most electronic applications the output will need to be smoother and more like the output of a battery.
Well....That's all for now folks. The next post will go through smoothing and regulation! The final post will go through realising the circuit and actually building the power supply. Have fun as much as possible but be careful!!!
Ok people...it has happened before and may happen again! I apologise for not writing more about what I have been up to! Its because I'm always busy!
I have still not finished the Chess clocks! I will I promise. I have made progress though! PCBS are built and tested just not in proper finished boxes. I will write up on the use of rotary encoders and some of the design decisions I had to make!
I recently made a PCR machine for the Manchester DIYBIO group. I will write about that on here and go through the project.
Lastly I was interviewed by EE Web. The link to the interview for those who are interested is here:
I apologise again for not posting more recently. I have been suffering from a really virulent chest infection which has held me back a bit!
I was in the middle of constructing one of the display sections of the Chess clock on matrix board. It is nearly complete but I have had terrible trouble making it. Matrix board is ok providing you have a simple layout. The circuit that we are trying to construct with separate seven segment displays and four separate shift registers is not a simple layout. Upon reflection I should have had PCBS professionally made and my problems would have been solved. I didn't and I have a three quarters complete mess of wires and chip holders on some matrix board! I will complete and get it working but I don't think I'll be making another in that fashion. It was a nightmare!!
So what do we do now? The faint hearted quit and go and do something else...hopefully something more profitable! The stubborn and courageous (thats me!!) find another solution.....Browsing the various websites available and looking at some of the other technical blogs online; various other people have done things slightly differently. Most people have used a combined 4x Seven Segment display which gets rid of a lot of the circuit layout issues.
So I bought two of these 4x Seven Segment displays and began working out how they tick. They come from China as do most electronic components these days and there is a datasheet available. As these parts are stocked by Sparkfun I will link to their page from here:
Helpfully sparkfun already also have an eagle footprint created so we can draw a schematic and once the circuit is complete and working layout another PCB! This time things should be much more simple to achieve....less wires equals less of a layout and construction headache...(I say this now...later I may change my mind!!)
So it was while I was looking at the device on sparkfun's website and reading some of the tutorial pages available when I noticed an issue....well not really an issue but a difference from the other displays we have been using. For starters these are common anode displays, meaning that the positive input to the diodes are connected together; our previous displays were common cathode. The other issue is that these displays have to have each segment driven separately. For those who are interested these displays are quite easy to get up and running....here is an excellent tutorial which I used at first myself just to ensure the displays were working:
The article goes through all of the important bits of information....and gets the general ideas and concepts across in order to get this display up and running. The issue is that in order to drive this display fully 14 control pins will be needed from our microcontroller of choice. I'm using an arduino development system but any micro will need 14 pins....This is a lot of pins to sacrifice just to drive one display and as I need two of these for my chess clocks this isn't an option. Ok...as in previous posts....I'll just use shift registers. I got the parts needed and set up the circuit as shown on Jon Boxall's blog.
Parts needed:
1x Microcontroller and development area - An arduino and breadboard
1x Serial cable for programming and powering the arduino
2x 74HC595 shift registers
4x BC548 transistors
4x 1k resistors
9x 220R resistors
Lots of connector wires
Lots of patience and a sense of humour!
As can be seen things are a little different. This is because in we are going to have to multiplex the display in order to get all four displays on at the same time. This uses a persistence of vision technique that I didn't use in the previous circuits. The seven segments are turned on as before by the appropriate binary code number being sent serially to the first shift register. The second shift register controls which segment is on and we will write the control software to multiplex the segments (flash the segments at a high refresh rate to make it look like they are all on at the same time.....in reality they aren't but this isn't visible to the naked eye so it isn't an issue.
Here is the circuit diagram. I am using a common anode display so my transistors are controlling the anodes of the display with the emitter pins unlike Jon's circuit where he had a common cathode display and was controlling the collectors. My transistors are controlling when the pins go HIGH and Jon's were controlling when the pins go LOW....
So....I connected up the circuit and commenced with the writing of the control software....I had already looked at Jon's code...assumed I understood it and figured it wouldn't be too difficult to make a fork of it to control mine. For some reason life is never simple and it took me ages to get this working....I must be losing my edge!! I found it very difficult to get each display on correctly and update properly. My biggest mistake was that I was trying to turn the display completely on and off when I updated the display with a new character. I now know and understand that it isn't possible to do this when using a persistence of vision multiplexed display!
Here is the code....As it is quite a big program I'm giving a link.
By the way Git hub - great idea but a massive pain to use for the neophyte.
I accept this code is horrible to look at for someone else....so I will break the program down into what it does in each section and that should make it easier to understand. Please feel free to comment or email me if there is something that is not clear.
I decided just for fun to make the circuit into a clock getting the current time from my computer via the serial programming cable.
The first section tells the compiler to include two libraries and set up some variables ready to store information. The comments provided give most of the detail of what is going on. Like in the previous posts I am using a couple of arrays to store the information which turns on the required LEDS to create the characters and I also am using a small array to store the information for which cell is currently active. The other variables are for counting and to tell the compiler which microprocessor pins are being used in this circuit.
//External libraries for getting the current PC Time
//over the serial connection
#include <Wire.h>
#include "RTClib.h"
//Function for getting the current system time
RTC_Millis RTC;
//Count variables
int i=0;
int j=0;
// Pin connected to ST_CP (pin 12) of 74HC595
int latchPin = 8;
// Pin connected to SH_CP (pin 11 of 74HC595
int clockPin = 12;
// Pin connected to DS (pin 14) of 74HC595
int dataPin = 11;
/* initialise a four element array which turns the transistors on
to control which segment is active */
int segmentSelect[4]= { 1,2,4,8 };
/* Initialise a One Dimensional integer array with
the values for 0 - 9 on the Seven Segment LED Display */
int seven_seg_digits[10]={ 192,249,164,176,153,146,130,248,128,152 };
/*
without decimal point(s)
{ dp,g,f,e,d,c,b,a },
{ 1,1,0,0,0,0,0,0 }, // = 192 in decimal - common anode
{ 1,1,1,1,1,0,0,1 }, // = 249 in decimal - common anode
{ 1,1,0,0,0,0,0,1 }, // = 164 in decimal - common anode
{ 1,0,1,1,0,0,0,0 }, // = 176 in decimal - common anode
{ 1,0,0,1,1,0,0,1 }, // = 153 in decimal - common anode
{ 1,0,0,1,0,0,1,0 }, // = 146 in decimal - common anode
{ 1,0,0,0,0,0,1,0 }, // = 130 in decimal - common anode
{ 1,1,1,1,1,0,0,0 }, // = 248 in decimal - common anode
{ 1,0,0,0,0,0,0,0 }, // = 128 in decimal - common anode
{ 0,1,1,0,0,0,0,1 }, // = 152 in decimal - common anode
// Just for further reference here are the
// separate segment connections
segment a = 14
segment b = 16
segment c = 13
segment d = 3
segment e = 5
segment f = 11
segment g = 15
d.p. = 7
*/
// constants won't change. Used here to
// set pin numbers:
// Arduino Pin 9 is connected to the colon LED pin on the Seven Segment
const int colonPin = 9;
// Variables will change:
int colonLedState = LOW; // colonLedState used to set the LED
long previousMillis = 0; // will store last time the Colon LED was updated
/*
The following variables is a long because the time, measured in miliseconds,
will quickly become a bigger number than can be stored in an int.
*/
long interval = 1000;
//Integer variables to store the value(s) of the character that we wish to display on the Seven Segment
The next section of code is a small function which clears the display completely by turning off the transistors which are controlling the cell anodes. It does this by loading the binary number 0000 0000 0000 into the shift registers which causes the anode pins to be low and therefore not powered.
void clearDisplay() {
/*
Take the latch pin of the shift register(s) low. shift zero serially into the shift register(s) which turns the transistors off
and then take the latch pin of the shift register high to re-latch with the new 'zero' data
The next section is the setup function. This part of the program tells the compiler which pins are being used as outputs and to start the serial listener. It also grabs the current PC system time over the serial link. We will use this as the display data for the seven segment so that we have something meaningful to display. I'm going to change this for the chess clocks as we want a count down timer in that situation...not a real time clock! The setup function is only called once, so whatever needs setting up in order for our device to correctly function needs to be done here...
void setup() {
// set the arduino pins to output so you
// can control the shift register(s)
// and the colon LED segment
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(colonPin, OUTPUT);
//Clear all the Display
clearDisplay;
//Turn on the serial Monitor - useful for debugging!
The next section is the main loop function. This is the part of the program that is constantly run. It calls the other functions which get the circuit to function as we designed...In this case it calls the next function which is the display function:
The code below is the main heart of the program and hopefully is explained by the text following it!
/*
Using an interrupt constantly display characters on the display which are taken from the system clock
Display these characters by rapidly sweeping from right to left to make it seem as though the characters are constantly on....Persistence of vision technique
*/
void displayNumber() {
#define DISPLAY_BRIGHTNESS 1500
long beginTime = millis();
for(int digit = 4 ; digit > 0 ; digit--) {
//Turn on a digit for a short amount of time
switch(digit) {
case 1:
displayDigitOne();
break;
case 2:
displayDigitTwo();
break;
case 3:
displayDigitThree();
break;
case 4:
displayDigitFour();
break;
}
//Display this digit for a fraction of a second (between 1us and 5ms)
delayMicroseconds(DISPLAY_BRIGHTNESS);
//Turn on all segments
updateDisplay();
}
//Wait for 20ms to pass before we paint the display again
while( (millis() - beginTime) < 10) ;
unsigned long currentMillis = millis();
if(currentMillis - previousMillis > interval) {
// save the last time you blinked the Colon LED
previousMillis = currentMillis;
if (colonLedState == LOW)
colonLedState = HIGH;
else
colonLedState = LOW;
// set the colon LED with the State of the variable:
This is the section of code that I found the hardest to write and after looking at other people's code and explanations at first I still didn't get it! So what is going on here:
the first line of code is a statement of definition - where the compiler sees DISPLAY_BRIGHTNESS written it will use the value 1500....what the program does here is set the refresh rate for the 4x Seven Segment Display. Just like your computer monitor or television's refresh rate our display will flicker on between each segment every 1500 micro-seconds.
The next line is a variable declaration that stores the amount of time the program has been running. We will use this information as a starting point to get the microcontroller to perform certain functions such as updating each display in turn....
After that we have a For to loop combined with a switch statement. What this section of code does is turn on each segment in turn from right to left from four to one calling a separate function which contains the information we wish to display. This information is written to the display for 20ms before it is then updated with a new a possibly different character to display.
The final section is a fork of the blink without delay example from the arduino forum. We are using it in this case to flash the colon on the display every second so that it looks like a clock! Again we are marking the point at which this section of code has been run and then after a second has passed we toggle the state of the colon led which is connected to pin 9 of the arduino.
The above code section is an example of using an interrupt. The code above constantly runs no matter what else is going on in the program. The reason we need to do this is because if we interrupt the display it will look flickery and dull...and as I found all the time while I was trying to get this working the last segment is wonderfully bright and all the others are barely on.....
The next function is quite a simple one...all it does is grab the current system time from the serial connection and then by using some simple maths tricks send the required number to each of the displays in turn. The time stamp is obtained in sections. The hour will be a two digit number from zero to 23. If we divide this number by ten we get a number and a remainder. If we drop the remainder (3) we have the first number we wish to display on the first segment. For segment two we display the remainder 3. The minute functions are obtained in the same way
Get the current time from the serial connection - DateTime now = RTC.now();
divide the hours value - for example 16 by ten and we have 1 remainder 6
store the value 1 for the first segment - firstDigit=now.hour()/10;
store the remainder value 6 to the second segment - secondDigit=now.hour()%10;
divide the minutes value for example 35 by ten and we have 3 remainder 5
store the value 3 for the third segment - thirdDigit=now.minute()/10;
store the remainder value 5 to the fourth segment - fourthDigit=(now.minute()%10);
/*
Using the current PC time as a data source, set the segments to display the time by passing the current time as variables to the segments
This next section of code deals with sending the required character to the required segment via the shift register serially. The latch pin of the shift register is taken low. The required character is shifted into the register serially from the position highlighted in the character array. The required segment is then selected and finally the data is then latched into the shift register by taking the latch pin high. Each of the segments are treated in the same way but they all have their own function.
void displayDigitOne() {
//take the latch pin of the shift register(s) low and shift in
//the data for the required character, then turn the correct //transistor
//for the first segment on which turns the segment on
//then latch the shift register by taking the latch pin HIGH
And now finally for the ubiquitous video showing that this all works and it isn't some great pretence! Enjoy people and happy holidays. Next up will be setting the time using a rotary enoder and then finally we will turn the clocks into fischer count down chess clocks. Then hopefully I will get all of it permanently constructed and into some sensible and reasonable looking housings and give them away! I might make two just in case....i'm growing quite attached to the idea!
My sincerest apologies to those that follow my blog....
I haven't had the time to do any posts or updates in some time. I have been thinking about the project and I have done some work on it.....
I am in the process of making up what I call the seven segment display modules which will be the 4x Seven Segment LEDS and the associated shift registers. I was intending to etch and make a PCB but as I currently don't have access to etching facilities I haven't gone down this route. I bought some matrix board off an excellent small electronic components distributor via their online shop:
They don't have as large a selection of components as RS or Farnell but they have most of what I need and they don't mind small orders. Their service is excellent! I order before 12am on a weekday and more often than not my stuff is delivered the next day....that kind of service seems hard to find for electronic components in the UK and this is at very reasonable prices. I wholeheartedly recommend them.
Here is the matrix PCB:
What I will have to do is solder in the components and then either use wire links to make the connections or make solder tracks. There are pitfalls in using matrix board and this will become apparent as I post more photographs of the construction.
A few tips when using matrix PCB:
Plan your layout carefully. Place the components on the PCB in a rough semblance of where you want them to go.
Ensure you have display components centred and placed in a logical fashion. Try and ensure you have enough room to wire the components together. It can be difficult to go back once you have started.
Once you are certain of where you want to place components begin soldering. I recomment soldering the corner pins first off. Then once you are comfortable with the component placement solder the rest of the pins. There is no rush when doing this....I would also avoid hangovers and coffee!
Use a sensible heat setting on your soldering iron. Soldering at too high a temperature can and DOES melt the glue that holds the pads onto the FR4 material. Wire up the circuit slowly testing each section as you go. Desoldering and moving components can be difficult. I write with experience in things not going according to plan!
For those that don't know most electronic circuits use a special material as the base surface called FR4. It is glass reinforced plastic which is an excellent insulator. Copper material is glued to the FR4 to allow conductance of electricity. The copper is then removed to create tracks or in my case a matrix.
As I write I am half way through completing the construction and test of the first display board. I hope it all comes together. Check out the mess of wires on the underside!!
I made a classic mistake in not considering how thick wire can cause issues when making connections and this will cost me dearly. I also didn't use a sensible wiring practice when making the connections and will have to work out which wires connect which resistors to the LED segments. I should have wired the shift registers first. Hindsight is a wonderful thing! I can still get this working but I think I will construct the other PCB with the same component placement but wire the shift registers first off.
Well that is about it for now. After I have both display boards constructed and testing and working I will be showing how we can use Rotary Encoders to set the count down time. I'm still hopeful to get this finished for Christmas!!