How on Earth am I going to make my PCB?

The illustration above shows a typical PCB that a Systems and Control student might design and make.

Study the PCB above closely and you will see that it consists of a load of resistors, a PIC chip, a strange blue thing, 6 LEDs, a speaker, an LDR and a microswitch.

This could be a circuit that, when the microswitch is pressed, uses the LDR to gauge the level of light and then displays the information by lighting up a certain number of LEDs – say, 1 for very light, 6 for dark and everything in between. This circuit might also give an audible ‘beep’ if the light level is too dark to record a reading.

It could also be a circuit that works as a night-light for young children. The LDR detects when it is dark and the microswitch (ingeniously fixed underneath the mattress) detects that there is a child present. The LEDs light up in a pattern to comfort the child and the speaker plays a soothing tune. Ahhhh!

Thing is, how this circuit works will depend on how you program the PIC chip and that depends on the flow diagram that you design (remember that from last year?). Designing the flow diagram is something else that you will have to work on in combination with this worksheet.The purpose of this worksheet is to talk you through how to design and make your PCB.

The first thing that you need to do is decide what your inputs are. Here are some of your options:

  • Switches – Digital (on/off)
  • Microswitch
  • Push-button switch
  • Reed switch
  • Tilt switch
  • Sensors – Analogue (range of states)
  1. Thermistor
  2. LDR
  3. Moisture sensor

Next you will have to decide what your outputs are. Here are some of your options:

  • LED
  • Speaker/Buzzer
  • Motor
  • LCD Display

We will be using 2 different types of PIC chip, 16F627 and 16F628.

  • 16F627 has 7 digital inputs and 8 outputs.
  • 16F628 has 5 digital inputs, 2 analogue inputs and 8 outputs.

The chips look identical (although they will have their number on the top) and they are connected the same way. The only difference is that 16F628 swaps two of its digital inputs for analogue inputs.

The pins (shiny metal legs of the chip) are numbered 1-18 as shown on the right.

So, if 7 of the pins are inputs and 8 are outputs, what do the other 3 pins do? Simple. One of them is a reset pin, so that you can start the flow diagram all over again, and the other two are for connecting to the power supply.

Notice how the makers of the PIC chip have started the numbering of their inputs and outputs at 0 and left out input 5 altogether for added confusion!

If you refer back to the example at the start of this booklet, you will hopefully recall that it showed a circuit with an LDR, a microswitch, 6 LEDs and a speaker.

Now if you’ve been reading this carefully, you will realise that an LDR is an analogue sensor (it has a range of different states, not just on or off). Therefore to construct this circuit we would need to use a 16F628 chip.

Of the 7 inputs available to be used we would only need 2. Of the 8 outputs that are available to be used we would only require 7. That’s okay! The PIC chip will not be offended if it hasn’t got anything connected to some of its inputs/outputs.

You will need to connect the PIC chip up to a power source (surprise, surprise) and on the left I have shown how this is done. I have also shown how the reset pin is connected, which it needs to be to stop the PIC chip continually resetting itself.

The top line is connected to +6v and the current splits to flow through a resistor to the reset pin (pin 4) and straight to the +6v pin (pin 14). Pin 14 is also connected to 0v through a capacitor (you don’t need to know why, it just is).

The current then flows from pin 5 to 0v which is the track at the base of the PCB.

Inputs

“What about my inputs?” Well, if I connect anLDR to analogue input 0 (pin 17) and amicroswitch to input 6 (pin 15) this is what I will need to do.

You can see that the current will flow from the top +6v line, through the LDR (the round thing), through a resistor (to limit the current) and into pin 17.

The current will also flow through the microswitch (strange rectangle thing) through a current limiting resistor into pin 15.

If you have understood everything so far then good, because it’s going to get a bit more tricky now.

If you have programmed a PIC chip such that it does something when it receives an input (say, in the above example, when the microswitch is pressed) you might think that the circuit we have created so far is sufficient. But you’d be wrong! Unfortunately even when the microswitch isn’t being pressed the PIC chip will think that the input is ‘high’ unless it is connected to 0volts.

The circuit on the right shows both analogue input 0 (pin 17) and input 6 (pin 15) connected to the 0volt track.

In the illustration below, I have shown what the whole circuit looks like when you combine the tracks supplying power to the chip, tracks to the inputs and tracks connecting the inputs to ground. If an input is not being used, remember, then nothing needs to be connected to it.

Outputs

“What about the outputs?” I hear you cry. Well, they are actually much easier to get your head around. For a start, if you look at how the outputs are numbered and the pins are arranged, it all pretty much makes sense. Pins 6-13 are outputs 0-7. Simple. The only slight inconvenience is that you will need a current limiting resistor if you are using LEDs as outputs.

The diagram to the left shows how you connect outputs to a PIC chip. In this example, and for no particular reason, I have connected output 0 (pin6) and output 5 (pin 11) each to a red LED via a current limiting resistor. The current returns back through the 0volt track at the bottom.

If you are using a speaker it is not necessary to use a resistor.

If an output is not being used then, again, nothing needs to be connected to it.

Making the PCB

This will be done using the Modela CNC milling machine. Luckily I have already created a drawing which has the holes drawn in the correct places. All you will need to do is stick down a piece of PCB onto the bed of the machine, check that the PCB drill is fitted, check that the machine is set up correctly and the Modela will drill the holes for you.

On the Curriculum server, under ‘Technology’, ‘Year 10’ and ‘Systems & Control’ you should see two drawings.One is imaginatively called PCB16F627 and the other PCB16F628. These are 2D Design drawings which are ready to be used with the Modela. You might want to modify them by deleting some of the input and/or output holes that you don’t intend to use but this isn’t absolutely necessary.

The whole drawing is back to front but that is deliberate. In the illustrations that I have shown so far for the tracks, they all appear to be drawn on the top surface of the PCB, in other words, on the same side as all of the components. In reality the tracks are on the underside of the PCB. The components are pushed through the top surface and soldered on the underside.

This illustration shows the PCB track on the top, this illustration shows them as they appear on the underside.

Once the PCB has been drilled, you will then need to mark out the tracks using an etch-resistant pen. The 2D Design drawings, PCB16F627 and PCB16F628, show you how to join the dots! Note that this shows you how to mark on all of the tracks to all 7 inputs and from all 8 outputs ~ you might not want all of these tracks.

Once you have marked on the tracks you will need to place the PCB in an etch tank. Your teacher will need to supervise this because nasty chemicals are involved. When the PCB has been etched you must clean the PCB in preparation for soldering on your components. It is also a good idea to use a multimeter to check for breaks in the track (known as the continuity).

Using Logicator Programs

Remember the example I gave you at the start of this booklet? About the circuit used to detect light levels and display a certain number of LEDs? Let me show you how this circuit might be produced.

I am going to assume that the PCB has been drilled out and the components soldered in place as shown below.

You can see that I am using an LDR connected to analogue input 0 (pin 17) and a microswitch connected to input 2 (pin 1).

For the outputs I am using just 4 LEDs connected to output 0-3 (pins 6-9).

This is how I would structure the Logicator flow diagram.

First of all, you need to go to ‘Options’ and select ‘PIC Type’. From the ‘Select PIC Type’ window choose either PIC16F627 or PIC16F628 and click ‘OK’.

On my finished product I would want to know that all the outputs were working, so, when the flow diagram first runs, I would ask it to turn on outputs0-3.

I would then use a ‘Wait’ command, select a pause of 2 seconds and then turn all of the outputs off again as shown on the left.

You are unlikely to want the light level measured all the time and this is why I have used the microswitch.

The next part of our flow diagram is going to be a ‘Decision’ box. If the input connected to the microswitch is ‘high’ (in other words the switch has been pressed) then we want it to go on and measure the light level. If the input is ‘low’ (switch not pressed) then we might be happy for the flow to go round and round in circles until the button is pressed.

There are two important things to note about this. The first is that I’ve used a ‘Digital’ decision box. A microswitch is either on or off ~ nothing in between ~ and therefore digital. Secondly, you need to double-click on the decision box and tell Logicator which input the microswitch is connected to by clicking the appropriate input port. In my example it is connected to input 2.

Now, suppose that the microswitch has been pressed, the next thing that you will want the PIC chip to do is measure the light level using the LDR. Before I create the next part of the flow diagram I need to explain how this can be done.

Yes, I know this looks horribly like a potential divider, but that is effectively what is happening when you look at the bit of the circuit that contains the LDR.

Just to refresh your memory, as the resistance of the LDR increases, it takes up a higher proportion of the 6 volts. That means that there are fewer volts ‘left’ at X, so the voltage into the analogue input will be lower.

As the resistance of the LDR decreases, it takes up a smaller proportion of the 6 volts so the voltage at X (and the voltage into the analogue input) will be higher.

Happy with that? Good, because as more light falls on the LDR, its resistance decreases. So, typically when it is very light, the voltage at X is close to 6volts. When it is very dark, the resistance increases and the voltage at X is almost 0volts.

The PIC chip converts the voltage to a number. It sees 0volts as a number with a value of 0 and it sees 6volts as a number with a value of 255. Any voltage from 0-6volts it will see as a number in the range from 0-255. This is the feature of the PIC chip that we are going to make use of.

For the next part of the flow diagram we still need to use a decision box, but this time it is the ‘Compare’ decision box.

Double click on it and in the ‘Cell Details’ window you can enter the formula. Because the LDR is connected to analogue input 0, we need to select ‘A0’ in the first box.

The second box allows us to select a mathematical symbol and the final box allows us to pick a value from 0-255.

Let’s say that this first compare box is going to look for a low level of light. If we enter in the formula A0 > 60 then if the answer is ‘no’, we can get the PIC chip to turn on all four of the LEDs.

If the answer is ‘yes’, then we can set up another compare box, this time asking if A0 > 120. If the answer is ‘no’, the PIC chip can turn on three LEDs and if the answer is ‘yes’ we can direct the flow to another compare box.

This goes on as shown on the flow diagram on the right. Please note that simply typing in ‘LED 1,2,3 & 4 ON’ isn’t sufficient to make it happen. You must double-click on the output box and click on the output ports that you want to come on.

The final part of the flow diagram is a ‘Wait’ box which will keep the LEDs on for 6 seconds before turning them all off and going back into the loop waiting for the microswitch to be pressed.

Once you have finished constructing your flow diagram you can test it on the computer.

Once you are satisfied that your program works as intended you can save your flow diagram and then ask a kindly teacher to program a PIC chip for you.

The great thing about Logicator is that it will allow you to re-program the chip repeatedly so if you have made a mistake, or it doesn’t work quite as intended, then it’s not the end of the world.

With the chip programmed, all that remains is for you to insert it into the chip holder that you should have soldered onto the PCB and connect up to the power supply.

Yes, but what happens when it doesn’t work?

Ahhh, I thought you might ask that!

The harsh reality is that, unless you are supremely skilled/lucky, the chances of your project working first time are slim.

Does anything happen at all?

Hopefully you will have programmed the chip to turn on all the outputs for a couple of seconds at the start of the flow diagram so that you can establish that power is getting through.

On the next page I have written a flow diagram for checking different parts of your circuit. You will need to do this with a multimeter.

Make sure that you set the multimeter up correctly. The dial should be set to ‘20’ on the voltage scale. The black probe should be placed in the 0v terminal of the power supply. The red probe can then be touched onto the pins as shown on the left.