GCSE Electronics - Application of Electronics PDF
Document Details
Uploaded by PeerlessAgate5370
2017
WJEC
Tags
Summary
This document is a chapter from a GCSE-level electronics textbook. It covers control circuits, microcontrollers, flowchart programs, and their applications. The chapters include examples of programs for traffic lights, and other applications.
Full Transcript
4 – Control Circuits Chapter GCSE Electronics – Component 2: Application of Electronics Control Circuits Learners should be able to: (a) define a microcontroller as a programmable integrated circuit into which software can be loaded to carry out a ra...
4 – Control Circuits Chapter GCSE Electronics – Component 2: Application of Electronics Control Circuits Learners should be able to: (a) define a microcontroller as a programmable integrated circuit into which software can be loaded to carry out a range of different tasks. (b) interface sensing circuits and output devices with microcontrollers. (c) design and analyse flowchart programs to enable microcontrollers to perform tasks. (d) describe applications of microcontrollers and the reasons for their adoption as standard technology in the vehicle and domestic appliance industry. (e) use the following operations in flowcharts: input/output, counting, branching, testing, time delay and simple arithmetic operations. (f) describe the use of a servo motor for positional control in a microcontroller system. 98 © WJEC 2017 Chapter 4 – Control Circuits GCSE Electronics – Component 2: Application of Electronics Introduction We have already covered two types of control system: 1. On - Off Control: The output is switched either on or off depending on the signal produced by the input sensing sub system which monitors the environmental condition being controlled. A temperature controlled room heater is a typical example of such a control system. Temperature Transistor Room Sensing Relay Switch Heater Sub-system If the temperature in a room falls below a predetermined value the heater will be switched on. The heater remains on until the temperature rises above the predetermined value and the heater will switch off, and so on. The temperature in the room is continually monitored and adjusted automatically. 2. Sequential control based on counters and logic circuits A traffic light sequence is a typical example of such a system. Logic Clock Counter Lamps System The system spends the same amount of time in each of four output states and the sequence continually repeats itself. In these control systems, the function of the system depended on what components are used and how the components are interconnected. They are said to be hard wired. Changing the connections and/or the components used is the only way to change the function of the system. In this chapter, we will consider software control systems using a microcontroller. 99 © WJEC 2017 4 – Control Circuits Chapter GCSE Electronics – Component 2: Application of Electronics Microcontrollers A microcontroller is a programmable integrated circuit into which software can be loaded to carry out a range of different tasks. Microcontrollers are totally self-contained. A microcontroller contains its own program memory, data storage memory, bidirectional (input/output) ports and a clock oscillator all in a single IC. Microcontrollers are widely used in everyday products. In the home, they are used in microwave ovens, refrigerators, dishwashers, washing machines, cameras, telephones, toys and TVs etc. Modern cars contain several microcontrollers: The engine is controlled by a microcontroller, as are the anti- lock brakes, cruise control, intelligent lights and windscreen wipers. Other applications include traffic light controllers, industrial robots, security systems, health monitors, automatic livestock feeding etc. Advantages of using a microcontroller: The circuit is more compact as one microcontroller can replace several logic gates/counters/ timers. More flexible than a hard-wired circuit since a microcontroller can be repeatedly reprogrammed to perform a different function. Disadvantage of using a microcontroller: They are more expensive than other ICs. Access to a computer and programming software required. Programming a microcontroller Different microcontrollers have different amounts of memory to hold the program that controls them. They read the program in a form called machine code which looks like a long sequence of numbers and letters. Machine code is very difficult to understand, so programs are usually written in other programming languages and converted into machine code using a software program. There are several control program languages available to program a microcontroller. Once the control program is written on a computer, it is converted into machine code and can then be transferred from the computer to the microcontroller via a cable. The program area within a microcontroller can store a program even if the power is switched off. A program can be written using a flowcharting program and then downloaded to the microcontroller. It can then be disconnected from the programmer and the microcontroller runs the program independently. 100 © WJEC 2017 Chapter 4 – Control Circuits GCSE Electronics – Component 2: Application of Electronics Interfacing to a microcontroller The number of inputs and outputs that can be connected to a microcontroller depends upon its size. For example, a microcontroller packaged in an 18 pin IC would typically have 15 or 16 pins available as inputs and/or outputs. Some of the pins on a microcontroller IC may only be used with digital inputs whilst others are dual purpose and can be re-designated or configured either as analogue or digital inputs. In addition, some pins may be configured as either inputs or outputs. Once you have a design specification for a problem you can choose the most appropriate microcontroller to match the number of inputs and outputs identified in the specification. Data sheets are available for each type of microcontroller giving the possible pin configuration combinations. All the input sub-systems studied in Component 1 can be connected directly to a microcontroller input pin. LEDs can be connected directly to a microcontroller output pin. Other outputs can be interfaced to a microcontroller with a transistor or MOSFET, so even high-powered output devices can be accommodated easily. A program can be downloaded and tested using the actual input and output devices. It can then be modified until the system performs exactly as required. Flowcharts A flowchart is a set of statement boxes linked by arrows used to arrange the different steps in the sequence in a logical order. Flow charts can be used to sort any set of complex instructions, not only in the writing of computer programs. A flowchart is particularly useful in determining the structure of a computer program. Program commands are written inside boxes of different shapes. The boxes are interconnected by arrowed lines called flow lines. 101 © WJEC 2017 4 – Control Circuits Chapter GCSE Electronics – Component 2: Application of Electronics Some of the more common flowchart boxes are given below. Start A start symbol is used at the beginning of each flowchart. Stop A flowchart may contain one, none or many stop boxes. Let a = 0 A process box is used if a calculation or a delay is required. Is a > 10 A decision box is used to ask a question which can be answered with either YES or NO. If the answer is YES, the sequence follows one route. If the answer is no, it follows a different one. Y N Turn An output box is used to send data to a particular output. on output 1 Flowchart based programming Converting a flowchart line by line into a control program can be both difficult and time consuming. For this reason, control programs that use a graphics interface have been developed. Flowchart symbols are chosen from a menu and ‘dragged’ onto the computer screen. An editing window allows the contents to be translated into a program avoiding typing or syntax errors. Then the flowchart can be tested and edited. There are several flowchart control programs available. These include programs systems such as: ‘FLOWAL’, ‘GENIE’, ‘LOGICATOR’, ‘PICAXE’ and ‘FLOWCODE’. All five allow you to simulate a flowchart program on a computer and download it via a cable to a microcontroller situated on either a dedicated interface circuit board or a breadboard circuit. Note: The flowchart programs in this chapter are written in a generic format as individual flowchart program have their own way of writing commands and setting up the inputs and outputs. Your teacher will show you the specific differences relevant to the flowchart program you will be using. 102 © WJEC 2017 Chapter 4 – Control Circuits GCSE Electronics – Component 2: Application of Electronics Example 1: Design specification A control program is required for a child’s toy that: switches on a red LED for 5 seconds turns the red LED off for 2 seconds turns the red LED and a blue LED on for 3 seconds. Solution 1 Red LED connected to output B0 Blue LED connected to output B1 The following flowchart shows the program. There are two issues with this solution: The program runs through the sequence once then stops. Outputs are switched on and off, one at a time, which would be tedious if several outputs needed to be activated simultaneously. 103 © WJEC 2017 4 – Control Circuits Chapter GCSE Electronics – Component 2: Application of Electronics Solution 2 Study the modified solution below: You should notice that when both LEDs have been turned off the program loops back to the first flowchart command so the program runs continuously. Also at the two points in the program where both LEDs are turned on or off this has been achieved with a single command in each case. Note: Some flowchart programs: Use Wait rather than Delay to represent a time delay. Use High or Low to turn a single output on or off and Outputs to turn multiple outputs on and off, whilst others use Outputs for both situations. In example 1 above the design specification stated that a red and a blue LED was required. The solution stated that the red LED was connected to output B0 and the blue LED to output B1of the microcontroller. The flowchart showed for how long B0 and B1 was switched on and off but did not mention what device was connected to them. Sometimes a flowchart will provide information about the actual output device being switched on or off and not mention the microcontroller output pins. 104 © WJEC 2017 Chapter 4 – Control Circuits GCSE Electronics – Component 2: Application of Electronics Investigation 4.1 1 (a) Construct the flowchart program shown in Example 1, solution 2 using your flowchart program and test it. (b) Show the output pins used for each output of your chosen microcontroller: Microcontroller Red LED connected to output Blue LED connected to output (c) Does the program perform the correct sequence? 2. The flowchart shows a traffic light sequence for a single set of traffic lights. Start Turn on Red Light Wait 10s Wait 10s Turn on Turn off Red and Green, Amber Turn on Amber Wait 2s Wait 2s Turn off Red and Amber, Turn off Turn on Amber Green 105 © WJEC 2017 4 – Control Circuits Chapter GCSE Electronics – Component 2: Application of Electronics (a) Show the output pins used for each output of your chosen microcontroller: Microcontroller Red LED connected to output Amber LED connected to output Green LED connected to output (b) Construct the flowchart program and test it. (c) Does the program perform the correct sequence? (d) Either print your solution or copy it into the space below. 106 © WJEC 2017 Chapter 4 – Control Circuits GCSE Electronics – Component 2: Application of Electronics Exercise 4.1 1. Design a control program for the traffic light sequence at a busy crossroad junction. There will be two sets of lights, one in a North-South and one in an East-West. The timing sequence should be as follows. Step North-South Lights East-West Lights 1 Red On (20sec) Green On (20sec) 2 Red & Amber (3 sec) Amber (3 sec) 3 Green On (20 sec) Red On (20 sec) 4 Amber On (3 sec) Red & Amber On (3 sec) Repeat Sequence from Step 1 (a) Show the output pins used for each output of your chosen microcontroller: Microcontroller North-South Lights Red LED connected to output Amber LED connected to output Green LED connected to output East-West Lights Red LED connected to output Amber LED connected to output Green LED connected to output 107 © WJEC 2017 4 – Control Circuits Chapter GCSE Electronics – Component 2: Application of Electronics (b) Complete the flowchart in the space below. Start Turn on N-S Red E-W Green 108 © WJEC 2017 Chapter 4 – Control Circuits GCSE Electronics – Component 2: Application of Electronics Using decision boxes to monitor inputs All the programs so far have involved only outputs. Now we look at a program where decisions are made based on the state of the inputs. Decision boxes ask questions which have only two possible outcomes, referred to as Yes and No routes. In programming language decision boxes cause branches in a program. The program flow is directed one way or another depending on the result of the question. Digital Inputs A decision box can be used to cause a program to ‘wait’ and repeatedly test until an input comes on or goes off. This is shown opposite: Here the ‘NO’ path loops back on itself repeating the question “Is Input C5 on?” until Input C5 is actually on. Then the program leaves this decision box and continues through the rest of the program. A second use of a decision box is to branch to a different part of the program depending on the state of an input, as shown below: The question is the same - “Is Input C5 on?” but the outcome depends on the answer. If input C5 is on, the program will turn output B0 on. If input C5 is off, the program will turn output B3 off. The program will enter the decision box only once. The route it takes depends on the state of Input C5. 109 © WJEC 2017 4 – Control Circuits Chapter GCSE Electronics – Component 2: Application of Electronics Example 2: Design specification A control program is required to provide a flashing lamp that can be used on a rubbish skip at night to warn drivers to avoid the rubbish skip. The light should be switched on when a switch is pressed. A lamp should be switched on for 2 seconds then off for 1 second. This should repeat until a second switch turns the system off. Solution Lamp connected to output B0 Start switch connected to input C5 Stop switch connected to input C1 In this example, we have used a decision box to check if the start switch has been pressed. If the switch is not pressed then it is continuously tested until it is. Only when the start switch is pressed will the program continue past the first decision box. The second decision box changes the flow of the program. If the stop switch is not pressed then the program repeats the lighting sequence before checking the switch again. Once the stop switch is pressed the program changes direction and stops. 110 © WJEC 2017 Chapter 4 – Control Circuits GCSE Electronics – Component 2: Application of Electronics Analogue Inputs The last two examples used a digital, on/off decision box. It is also possible to have an analogue decision box where a value can be tested. An example might be to test an analogue input for the temperature in a bakery. In the example above, if the Value of the analogue input that’s connected to input B5 goes above 35 °C then some cooling fans connected to Output B0 are switched on. When the value of input B5 falls below 35 °C then the cooling fans are switched off. 111 © WJEC 2017 4 – Control Circuits Chapter GCSE Electronics – Component 2: Application of Electronics Example 3: Design specification An intelligent door bell is required for a family with a young baby. If it is light then when a switch is pressed a buzzer should come on for 5 seconds. If it is dark, then an LED should come on for 5 seconds. Solution LED connected to output B1 Buzzer connected to output B2 LDR connected to analogue input B6 (Value >75 when Dark) Stop switch connected to input C1 In this example, we have used a decision box to check if the doorbell switch has been pressed. If the switch is not pressed then it is continuously tested until it is. Only when the doorbell switch is pressed will the program continue past the first decision box. Then, if it is dark (B6>75) then LED is switched on, but if light (B6