DT11-07 Design and Technology Watch
Programming a microcontroller: counters, timers and decisions
In this lesson
Programming a microcontroller for GCSE Design & Tech, with worked examples and the mistakes examiners report. AQA 8552, Edexcel 1DT0 and Eduqas C600QS GCSE. Electronic systems 6 of 6. More at https://scholafly.com
By the end: Explain how a microcontroller is programmed to act as a counter, as a timer and to make decisions, recognise each in a product, describe the steps of a simple program in plain words, and explain how each gives the product a function the user can rely on.
What it covers
- 0:00 Intro: programming a microcontroller
- 0:32 Programming a microcontroller: programmed jobs
- 2:17 Programming a microcontroller: deciding
- 3:56 Programs as plain steps
Key words
About this video
Programming a microcontroller: counters, timers and decisions | GCSE Design & Tech | DT11-07
Programming a microcontroller for GCSE Design & Tech, with worked examples and the mistakes examiners report.
AQA 8552, Edexcel 1DT0 and Eduqas C600QS GCSE. Electronic systems 6 of 6.
More at https://scholafly.com
Watch first: DT11-06 - https://youtu.be/oAZTkR39RoY
Video code: DT11-07 (search "ScholaFly DT11-07")
#GCSEDesignTech #ElectronicSystems
For teachers
This GCSE Design & Tech lesson teaches programming a microcontroller: counters, timers and decisions. By the end, students should be able to explain how a microcontroller is programmed to act as a counter, as a timer and to make decisions, recognise each in a product, describe the steps of a simple program in plain words, and explain how each gives the product a function the user can rely on. It works through three worked examples and the mistakes examiners report.
Exam board specification references:
AQA 8552
- 3.1.4:Processes
Edexcel 1DT0
- 1.7.2
- 1.7.4
Eduqas C600QS
- 2.1 core.5
- 2.1 core.6
Read the transcript
The sign at the entrance to a multi-storey car park says three spaces. A car goes in, and the sign says two. One comes out, and it's three again. When it reaches nought, the sign says full, and the barrier stays down. There's nobody in the booth. How do a barrier and a sign know how many cars are inside? Before the end, you'll be writing that car park's program yourself.
A microcontroller does nothing until it's programmed. The program tells it what to do with its inputs, and it can be programmed for three jobs: to count, to time, and to decide. A counter counts events from an input: each press, each car, each coin, each turn. When the count reaches a set number, it acts. It can count upwards, or downwards. A full answer says what it counts, and what happens at the set number. A vending machine counts each coin put in, and when the price is reached, it releases the drink. A timer measures time from the microcontroller's own clock, and switches an output on or off after a set time. A hand dryer that runs for thirty seconds, then stops, is timed. So is a microwave's cooking time, and a security light that stays on for a minute. The difference between them is where the numbers come from. A counter counts things that happen at an input. A timer counts time on its own clock, with nothing coming in. Now try a pair. A step counter on a phone, and an electric toothbrush that pauses every thirty seconds: which is counting, and which is timing? The step counter is counting, because it adds one for every step taken. The toothbrush is timing, because thirty seconds pass and it pauses the brush, whatever you do.
The third job is deciding. The microcontroller compares an input with a value set in its program, and chooses what to do. A greenhouse vent works this way. The program says: if the temperature is above twenty-six degrees Celsius, then open the vent, otherwise keep it shut. The sensor only reports the temperature. The program does the deciding, by comparing that reading with twenty-six. Now a security light that stays on for sixty seconds after someone walks past. Which jobs is its microcontroller doing: counting, timing or deciding? Make your call before the reveal. Deciding and timing, both. It decides someone has passed, from the P I R's signal, then times sixty seconds before it switches the lamp off. Most products use more than one job. A microwave decides whether the door is shut, then times the cooking, then switches the buzzer on. To tell the three apart, counting needs events coming in, timing needs only the clock, and a decision always has an if. On a system diagram, the process block can name the job as well as the part. 'A microcontroller programmed as a timer' says far more than 'circuit', or 'it does it'.
A program can be written as plain numbered steps, with each decision as a yes or no question. That's enough to explain how a product works. A turnstile lets people onto a theme-park ride, and each turn of it presses a micro switch. When twenty-four people have gone through, the turnstile locks and a red lamp comes on. Three minutes later the next ride is ready, so the lamp turns green and the turnstile unlocks. Step one sets things up: the count is set to nought, the green lamp comes on, and the turnstile unlocks. Step two waits for the micro switch to be pressed. Step three adds one to the count, and that's the counting. Now step four, the decision. What question does the program ask here, and what happens for each answer? Is the count twenty-four? If no, go back to step two and wait for the next person. If yes, carry on. Step five locks the turnstile and turns the red lamp on. Step six waits three minutes, and that's the timing. Step seven goes back to step one. Next year the park fits a bigger ride, for thirty people. Only the number in step four changes, with no new parts, and that's what customising a product means. A fridge should beep if it is left unshut for more than a minute. Its input is a micro switch in the frame, pressed whenever the fridge is shut, and its output is a buzzer. How would you write the fridge's program as plain steps, with each decision a yes or no question? Write your steps down, then check them against mine. Step one: is the door open? If no, keep checking. If yes, start timing. Step two: is the door still open? If no, go back to step one. Step three: has a minute passed? If no, go back to step two. If yes, switch on the buzzer until the door shuts. Why is the timer in the fridge's program at all, when it could beep the moment the door opens? Without it, the fridge would beep every time someone took out the milk. The minute's wait means it only beeps when the door has been forgotten. Now the car park from the start, with most of its program already written. A pressure pad in the road at the entrance feels each car coming in, and another at the exit feels each car going out. Counting in: when the entrance pad feels a car, the program takes one away from the spaces. Counting out: when the exit pad feels a car, it adds one back. Timing: when a car is let in, the barrier lifts, stays up for five seconds, and lowers again. That leaves the decision, and it's yours to write. What yes or no question does the program ask when a car arrives at the barrier, and what happens to the sign and the barrier for each answer? Are the spaces at nought? If yes, the sign shows full and the barrier is kept down. If no, the sign shows the spaces left, and the barrier rises for the car. That's how a barrier and a sign keep count with nobody in the booth. The program counts, times and decides, and the sensors only report.
To finish, counting, timing and deciding come back to you as questions.
What's the difference between a counter and a timer? A counter counts events coming in at an input. A timer counts time on its own clock.
Now a different one. In a greenhouse, does the temperature sensor decide when to open the vent? No. The sensor passes on its reading, and the program compares that reading with the set value to make the decision.
Now a fresh product. A hand-gel dispenser gives one squirt when a hand is under it, then won't give another for two seconds. Which jobs is its program doing? Deciding, because it checks whether a hand is there, and timing, because it waits two seconds before it allows another squirt.
And the car-park sign keeps count because its program counts cars in and out, decides whether the car park is full, and times the barrier.
If you can write a product's program as plain steps and say which step counts, times or decides, give this a thumbs-up, because this one's yours. Say the steps out loud once, and they stick.
That wraps up electronic systems. The next chapter is Mechanisms: motion, levers and linkages. Hopefully that's next in your feed, but if not, search for ScholaFly D T twelve, oh oh.
Every other video is on scholafly.com too, easy to search by video code or by keyword. Whatever you're revising, go there and have a look, or, watch the next video.
Related terms
For: AQA GCSE 8552, Edexcel GCSE 1DT0, Eduqas GCSE C600QS
On the specification
| Board | Spec | Statement |
|---|---|---|
| AQA GCSE 8552 | 3.1.4:Processes | Process: programming microcontrollers as counters, timers and for decision making |
| Edexcel GCSE 1DT0 | 1.7.1 | Using flowcharts |
| Edexcel GCSE 1DT0 | 1.7.2 | Switching outputs on and off from inputs and decisions |
| Edexcel GCSE 1DT0 | 1.7.3 | Processing and responding to analogue inputs |
| Edexcel GCSE 1DT0 | 1.7.4 | Simple routines: delays, loops and counts |
| Eduqas GCSE C600QS | 2.1 core.5 | Circuit diagrams, block diagrams and flowcharts |
| Eduqas GCSE C600QS | 2.1 core.6 | Sub routines and macros in control systems |
For teachers
This GCSE Design & Tech lesson teaches programming a microcontroller: counters, timers and decisions. By the end, students should be able to explain how a microcontroller is programmed to act as a counter, as a timer and to make decisions, recognise each in a product, describe the steps of a simple program in plain words, and explain how each gives the product a function the user can rely on. It works through three worked examples and the mistakes examiners report.