Lite / Building Machines That Respond / Term 3 worksheet
Worksheet: Building Machines That Respond, term 3
Name: Date:
Week 19: A whole computer on one chip
1. A variable counting button presses is lost every time the device is switched off. Which memory is it stored in?
- Flash
- RAM
- The clock
2. Which peripheral turns a sensor voltage such as 1.2 V into a number the program can use?
- A timer
- The ADC (analog-to-digital converter)
- A serial port
- Flash memory
3. Why does a TV remote use a microcontroller rather than a laptop processor?
- Microcontrollers are faster
- It needs one small, cheap, low-power computer running one program
- Laptop processors cannot read buttons
4. What does the CPU do over and over while the program runs?
- Fetch an instruction, decode it, execute it
- Download, install, restart
- Measure, sleep, forget
5. A microcontroller's clock runs at 160 MHz. How long is one clock period, in nanoseconds?
Answer: ns
Week 19: Counting in nanoseconds
1. A microcontroller's clock runs at 100 MHz. How long is one clock period, in nanoseconds?
Answer: ns
2. A 16 MHz microcontroller needs about 4 clock cycles per instruction on average. Roughly how many instructions can it run in 1 ms?
Answer: instructions
3. A 16 MHz chip at 1 cycle per instruction runs a loop of 4,000 instructions. How many times can the loop run each second?
Answer: loops per second
4. A loop needs 5,000 instructions at 1 cycle each and must finish within 0.1 ms. What is the slowest clock that just meets the deadline, in MHz?
Answer: MHz
5. Your loop uses 97% of its 1 ms deadline in testing. What should you conclude?
- Perfect: it fits
- Risky: real code meets slower paths and interrupts, so keep a margin
- It must be broken
Week 19: Set up once, loop forever
1. Where should 'set pin 3 as an output' go?
- In setup, once
- Inside the loop, every pass
- After the loop ends
2. In the heater loop (heater on if temp < 18, otherwise off), the readings on three passes are 17.5, 18.0 and 18.4. What does the heater do on each pass?
- on, on, off
- on, off, off
- off, off, on
3. A loop with no delay takes 2 ms per pass. How many times does it run each second?
Answer: passes
4. A learner writes the heater program without `while True:`. The heater works once at power-on, then never changes. Why?
- The sensor broke
- The program read, decided and acted once, then reached the end
- Python is too slow
5. A 100 MHz microcontroller needs about 2 clock cycles per instruction on average. Roughly how many instructions can it run in 1 ms?
Answer: instructions
Week 20: Pins: high, low and in between
1. A pin is set as a plain input with nothing connected. What does it read?
- Always 0
- Always 1
- Unpredictable values: it is floating
- The last value written
2. A 3.3 V output pin drives an LED that drops 2.2 V. What series resistor gives a current of 5 mA? Answer in ohms.
Answer: Ω
3. A 3.3 V output pin drives an LED that drops 2 V. What series resistor gives a current of 10 mA? Answer in ohms.
Answer: Ω
4. Pins GP5, GP4, GP3, GP2 are set to output, input, output, output (1 = output). Written as a 4-bit binary number in that order, what is the direction register in decimal?
Answer:
5. Why is it dangerous to set a button's pin as an output and write HIGH?
- The button gets bored
- Pressing the button connects a HIGH output straight to 0 V: a short circuit
- The LED will be too dim
Week 20: Pull-ups: giving a button a resting voltage
1. With a pull-up and a button to 0 V, which line of code means 'button pressed'?
- if read(pin) == 1:
- if read(pin) == 0:
- if read(pin) == 3.3:
2. A button connects a pin to 0 V. The pin has a 4.7 kΩ pull-up resistor to 5 V. While the button is held, how much current flows through the pull-up, in milliamps?
Answer: mA
3. A button connects a pin to 0 V. The pin has a 10 kΩ pull-up resistor to 5 V. While the button is held, how much current flows through the pull-up, in milliamps?
Answer: mA
4. A pull-down resistor connects the pin to 0 V and the button connects it to 3.3 V. What does a press read?
- 0
- 1
- It floats
5. Why not use a 10 MΩ pull-up to save even more current?
- It would short the supply
- It is so weak that noise and leakage can drag the pin away from 1
- Resistors that big do not exist
Week 20: Debouncing: one press, one count
1. A button can bounce for 30 ms after it is pressed. Your loop reads the pin once every 1 ms. How many readings fall inside that bounce window?
Answer: readings
2. A debouncer needs 5 identical readings taken every 2 ms. Roughly how long after the bouncing stops is the press accepted, in ms?
Answer: ms
3. Without debouncing, a lift-call button sometimes registers three presses. Why?
- The passenger pressed three times
- The contacts bounced and the fast loop saw each flicker as a press
- The lift motor is noisy
4. You set a debouncer to need 20 readings every 5 ms. A quick 50 ms tap is ignored. Why?
- 50 ms is shorter than the 100 ms of steady readings it demands
- The button is broken
- Debouncers ignore all short presses
5. A button can bounce for 40 ms after it is pressed. Your loop reads the pin once every 2 ms. How many readings fall inside that bounce window?
Answer: readings
Week 21: Range, resolution, accuracy, precision
1. Every reading from a scale is exactly 200 g too heavy. What kind of problem is that?
- Poor precision
- Poor accuracy (a consistent offset)
- Poor range
2. A sensor covers 0 to 50 °C with a resolution of 0.25 °C. How many distinct values can it report?
Answer:
3. A sensor with ±1.5 °C accuracy reads 18.0 °C. What is the lowest temperature the true value could be, in °C?
Answer: °C
4. Which problem does averaging many readings reduce?
- A constant offset
- Random scatter (noise)
- A sensor used outside its range
5. You need to measure a freezer at −18 °C. Which sensor range should you rule out?
- −40 to 125 °C
- 0 to 100 °C
- −55 to 150 °C
Week 21: Reading the datasheet line
1. A temperature sensor outputs 400 mV at 0 °C and rises by 19.5 mV for every 1 °C. It reads 205 mV. What temperature is it measuring, in °C?
Answer: °C
2. A temperature sensor outputs 500 mV at 0 °C and rises by 10 mV for every 1 °C. It reads 980 mV. What temperature is it measuring, in °C?
Answer: °C
3. A TMP36-style sensor (500 mV at 0 °C, +10 mV per °C) is at −15 °C. What does it output, in mV?
Answer: mV
4. Firmware computes `temp = mv / 10 - 500` for a 500 mV-offset, 10 mV/°C sensor. At 750 mV, what does it get, and what is wrong?
- 25: nothing is wrong
- −425: it divides before subtracting the offset
- 75: it ignores the offset
5. Which formula has units that work out to °C?
- (mV − mV) × (mV/°C)
- (mV − mV) ÷ (mV/°C)
- (mV/°C) ÷ (mV − mV)
Week 21: Two-point calibration
1. In ice water (0 °C) your sensor reads 118 counts; in boiling water (100 °C) it reads 820 counts. A new reading is 488 counts. Assuming a straight line, what temperature is that, in °C?
Answer: °C
2. In ice water (0 °C) your sensor reads 90 counts; in boiling water (100 °C) it reads 886 counts. A new reading is 256 counts. Assuming a straight line, what temperature is that, in °C?
Answer: °C
3. A sensor reads 100 counts at 0 °C and 900 counts at 100 °C. What raw reading means 18 °C?
Answer: counts
4. You calibrated at 0 °C and 100 °C. Which reading should you trust least?
- A reading meaning 40 °C
- A reading meaning 95 °C
- A reading meaning 160 °C
5. A greenhouse must be held at 16–24 °C. Which pair of calibration points is best?
- 0 °C and 100 °C
- 10 °C and 30 °C
- 50 °C and 60 °C
Week 22: Signals: smooth waves and stored numbers
1. One full cycle of a signal takes 1 ms. What is its frequency, in hertz?
Answer: Hz
2. A signal has a frequency of 440 Hz. What is its period, in milliseconds?
Answer: ms
3. A signal swings between 0.45 V and 2.85 V. What is its amplitude (half the peak-to-peak swing), in volts?
Answer: V
4. Which of these is a digital signal?
- The voltage from a microphone
- A list of temperatures recorded every minute as whole tenths of a degree
- The height of the sea against a harbour wall
5. A 3.3 V logic wire picks up 0.2 V of noise. Why does the receiving chip usually still read the right bits?
- Noise cannot reach digital wires
- It only has to decide 'near 3.3 V' or 'near 0 V', and 0.2 V is far too small to flip that decision
- Digital chips delete noise automatically from analog signals too
Week 22: Sampling: how often is often enough?
1. You sample a 1 Hz signal at 10 Hz. How many samples land in each cycle of the signal?
Answer: samples
2. A data logger samples at 1000 Hz for 2 s. How many samples does it record?
Answer: samples
3. A sensor is sampled at 200 Hz. How long is the gap between samples, in milliseconds?
Answer: ms
4. A 48 Hz vibration is sampled at 50 Hz. What frequency do the samples seem to show, in Hz?
Answer: Hz
5. A heart-rate signal contains rhythms up to 3 Hz. Which sample rate is the smallest that could work?
- 2 Hz
- 5 Hz
- 10 Hz
Week 22: ADC counts, quantisation and noise
1. What voltage does one step (1 LSB) of a 10-bit ADC with a 3.3 V reference represent, in millivolts?
Answer: mV
2. A 8-bit ADC with a 5 V reference reads 53. Using volts = count × Vref ÷ 2^n, what voltage is that, in volts?
Answer: V
3. A 10-bit ADC with a 5 V reference measures 2.94 V. What count does it report? (count = V ÷ Vref × 2^n, rounded down)
Answer: counts
4. A 10 mV per °C sensor feeds a 12-bit ADC with a 3.3 V reference. What temperature change is one ADC step worth, in °C?
Answer: °C
5. A sensor signal has about 15 mV of noise. You are choosing between a 10-bit (3.2 mV steps) and a 16-bit (0.05 mV steps) ADC. What happens with the 16-bit one?
- It measures the true value 64 times more accurately
- Its extra bits mostly record the noise; averaging or filtering would help more
- It removes the noise
6. A 10-bit ADC reads 512 and a 12-bit ADC reads 2,048, both with a 3.3 V reference. Are they measuring the same voltage?
- Yes, both about 1.65 V
- No: the 12-bit one sees four times the voltage
- Impossible to say
Week 23: States, events and transitions
1. An automatic door has states 0 = closed, 1 = opening, 2 = open, 3 = closing. Its events are 0 = person detected, 1 = fully open, 2 = timer ended, 3 = fully closed. Rules: closed + person → opening; opening + fully open → open; open + timer ended → closing; closing + fully closed → closed; closing + person → opening. Any other event leaves the state unchanged. The door is in state 2 and event 0 happens. What state number comes next?
Answer: state
2. An automatic door has states 0 = closed, 1 = opening, 2 = open, 3 = closing. Its events are 0 = person detected, 1 = fully open, 2 = timer ended, 3 = fully closed. Rules: closed + person → opening; opening + fully open → open; open + timer ended → closing; closing + fully closed → closed; closing + person → opening. Any other event leaves the state unchanged. The door is in state 0 and event 3 happens. What state number comes next?
Answer: state
3. Using the door rules (0 closed, 1 opening, 2 open, 3 closing), start in state 0 and apply the events: person detected, fully open, timer ended, fully closed, timer ended. Which state number do you end in?
Answer: state
4. Someone deletes the row 'closing + person → opening'. What is the danger?
- None: the door still closes
- A person walking up during closing is ignored and the door keeps closing on them
- The door will never open again
5. A vending machine has states idle, paid, vending, empty. No rule ever leaves 'empty'. What kind of problem is that?
- A stuck state: once empty it can never recover, even after refilling
- Nothing: empty machines should stop
- A noise problem
Week 23: Timed sequences: the traffic light
1. A traffic light cycles: state 0 red for 25 s, state 1 red-and-amber for 2 s, state 2 green for 15 s, state 3 amber for 3 s, then back to red. It enters red at t = 0 s. Which state number is showing at t = 47 s? (A state that starts at exactly t is already showing.)
Answer: state
2. A traffic light cycles: state 0 red for 20 s, state 1 red-and-amber for 2 s, state 2 green for 25 s, state 3 amber for 3 s, then back to red. It enters red at t = 0 s. Which state number is showing at t = 20 s? (A state that starts at exactly t is already showing.)
Answer: state
3. A junction cycle lasts 90 s. How many complete cycles happen in one hour?
Answer: cycles
4. Why do many junctions show all-red for 2 s between one road's amber and the other road's green?
- To save electricity
- To let a vehicle that entered on amber clear the junction before the crossing traffic moves
- Because lamps need to cool down
5. A controller counts loop passes to time its states ('1,000 passes = 1 s'). Someone adds more code to the loop. What goes wrong?
- Nothing
- Each pass now takes longer, so every state lasts longer than intended
- The lights change faster
Week 23: A state machine in twelve lines
1. state is CLOSING and the event is 'person'. Which value does `step` return?
- CLOSING
- OPENING
- CLOSED
2. An automatic door has states 0 = closed, 1 = opening, 2 = open, 3 = closing. Its events are 0 = person detected, 1 = fully open, 2 = timer ended, 3 = fully closed. Rules: closed + person → opening; opening + fully open → open; open + timer ended → closing; closing + fully closed → closed; closing + person → opening. Any other event leaves the state unchanged. The door is in state 0 and event 3 happens. What state number comes next?
Answer: state
3. What would happen if you deleted the final `return state` line?
- Nothing
- For unmatched events the function would return None, and the door would lose track of its state
- The door would open
4. The door has 4 states and 4 events. How many state–event pairs should a thorough test suite consider?
Answer: pairs
5. A learner uses `opening = True` and `closing = True` flags instead of one state variable. What new bug becomes possible?
- None
- Both flags could be true at once, driving the motor both ways
- The door runs faster
Week 24: DC motors, servos and steppers
1. Which actuator suits a desk fan best?
- A DC motor
- A hobby servo
- A stepper motor
2. A stepper with 48 steps per revolution must turn 90°. How many full steps is that?
Answer: steps
3. A stepper with 200 steps per revolution must turn 180°. How many full steps is that?
Answer: steps
4. A stepper-driven printer head is pushed too hard and skips 10 steps. What does the firmware believe?
- It notices and corrects
- It still thinks the head is where it counted, so every later move is offset
- The motor stops forever
5. A small robot arm's elbow must point at 30°, then 75°, and hold still against gravity. Which is the simplest choice?
- A plain DC motor with no sensor
- A hobby servo
- Any motor with a timer
Week 24: Talking to a servo in milliseconds
1. A hobby servo is told 1.0 ms means 0° and 2.0 ms means 180°, in a straight line between. How long a pulse sets it to 0°, in milliseconds?
Answer: ms
2. A hobby servo is told 1.0 ms means 0° and 2.0 ms means 180°, in a straight line between. It receives a pulse 1.85 ms long. What angle does it turn to, in degrees?
Answer: °
3. A servo signal has a 20 ms period and a 1.8 ms pulse. What is the duty cycle, in percent?
Answer: %
4. What carries the angle command in a hobby servo signal?
- The voltage of the pulse
- How long each pulse stays high
- How many wires are connected
5. You send a 2.6 ms pulse to a servo whose range is 1.0–2.0 ms. What is the risk?
- None
- It may try to turn past its mechanical stop, straining and heating
- It will spin forever
Week 24: Choosing an actuator, and why pins need help
1. A 9 V DC motor uses 1.5 W when running. How much current does it draw, in amps?
Answer: A
2. A 5 V DC motor uses 12 W when running. How much current does it draw, in amps?
Answer: A
3. A motor draws 0.6 A. A pin is limited to 0.012 A in this model. How many times the pin's limit is that?
Answer: times
4. Why does a motor connect through a driver with its own supply?
- Drivers make motors quieter
- Pins supply only milliamps, and motors need amps and produce voltage spikes
- Microcontrollers cannot make 0 and 1
5. A greenhouse vent must hold 0°, 45° or 90°, against gusts, and the budget is tight. Which actuator is the sensible first choice?
- A plain DC motor, no sensor
- A hobby-sized servo (or a geared servo for a larger vent)
- A 3D-printer stepper with no homing switch
Week 25: Timers: hardware that counts for you
1. A timer counts at 16 MHz divided by a prescaler of 1. How many ticks does it count in 20 ms?
Answer: ticks
2. A timer counts at 8 MHz divided by a prescaler of 1024. How many ticks does it count in 10 ms?
Answer: ticks
3. A 16-bit timer counts at 16 MHz ÷ 256. How long until it overflows, in seconds? (Give 3 decimal places.)
Answer: s
4. A timer counts at 8 MHz ÷ 8. How long is one tick, in microseconds?
Answer: µs
5. What do you gain and lose by increasing the prescaler?
- Gain finer timing, lose range
- Gain range before overflow, lose timing resolution
- Gain speed of the CPU
Week 25: PWM: dimming with an on/off switch
1. A PWM output switches between 0 V and 9 V with a duty cycle of 0%. What is the average voltage, in volts?
Answer: V
2. A PWM output switches between 0 V and 3.3 V with a duty cycle of 85%. What is the average voltage, in volts?
Answer: V
3. A PWM signal has a period of 2 ms and stays high for 1 ms each period. What is the duty cycle, as a percentage?
Answer: %
4. You want an average of 4.5 V from a 12 V supply. What duty cycle is needed, in percent?
Answer: %
5. An LED driven by PWM at 20 Hz visibly flickers. What is the fix?
- Lower the duty cycle
- Raise the PWM frequency well above what eyes notice
- Use a bigger resistor
Week 25: Doing several things at once (without waiting)
1. A non-blocking loop runs a task every 250 ms, the first time at t = 0 ms. Counting that first run, how many times has the task run by t = 25 ms (including a run exactly at 25 ms, if one is due)?
Answer: runs
2. A non-blocking loop runs a task every 20 ms, the first time at t = 0 ms. Counting that first run, how many times has the task run by t = 825 ms (including a run exactly at 825 ms, if one is due)?
Answer: runs
3. A loop calls `delay(1000)` once per pass. What is the main problem when you add a safety button?
- The button is only checked once a second, so a short press can be missed
- delay uses too much memory
- The LED gets brighter
4. Why write `last += 500` instead of `last = now` when a task runs?
- It is shorter
- It keeps the long-run timing exact even if a run happens a little late
- It makes the loop faster
5. One loop pass takes at most 3 ms. A task is due at t = 400 ms and the loop checks at 399 ms. At the latest, by how many ms is the task late?
Answer: ms
Week 26: Open loop or closed loop?
1. A toaster pops after a fixed time whatever the bread is like. What kind of control is that?
- Open loop
- Closed loop
2. In a greenhouse heater loop, what is the 'error'?
- The heater's power
- Setpoint minus measured temperature
- The thermometer
3. The setpoint is 18 °C and the thermometer reads 15.5 °C. What is the error, in °C?
Answer: °C
4. A closed-loop heater's thermometer falls off the wall and reads 0 °C. What does the controller do?
- Switches off safely
- Heats flat out, because it thinks it is freezing
- Nothing
5. A proportional heater controller uses effort = gain × error, where error = setpoint − temperature. The gain is 50% per °C and the effort is limited to the range 0 to 100%. The setpoint is 20 °C and the temperature is 14 °C. What heater effort does it command, in %?
Answer: %
Week 26: On/off control and hysteresis
1. A thermostat uses a setpoint of 20 °C and a total hysteresis band of 3 °C, centred on the setpoint. Below what temperature does the heater switch on, in °C?
Answer: °C
2. With 'on below 17, off above 19', the heater is ON and the temperature is 18.2 °C. What does the controller do?
- Switch off
- Keep the heater on
- Switch on
3. What do you trade when you widen the hysteresis band?
- Fewer switchings for a bigger temperature swing
- More switchings for a steadier temperature
- Nothing changes
4. A heater relay is rated for 100,000 switchings. A thermostat without hysteresis switches 350 times a night. With a 2 °C band it switches 60 times a night. How many more nights does the relay last with hysteresis? (Nights with band minus nights without, to the nearest night.)
Answer: nights
5. Your thermometer jitters by ±0.4 °C. Which band is most likely to chatter?
- 0.2 °C
- 1.5 °C
- 2.5 °C
Week 26: Proportional control: push harder when further away
1. A proportional heater controller uses effort = gain × error, where error = setpoint − temperature. The gain is 40% per °C and the effort is limited to the range 0 to 100%. The setpoint is 18 °C and the temperature is 16 °C. What heater effort does it command, in %?
Answer: %
2. A proportional heater controller uses effort = gain × error, where error = setpoint − temperature. The gain is 10% per °C and the effort is limited to the range 0 to 100%. The setpoint is 22 °C and the temperature is 17.5 °C. What heater effort does it command, in %?
Answer: %
3. Using T = (UA·T_out + Kp·r) ÷ (UA + Kp) with UA = 100 W per °C, T_out = 0 °C, Kp = 900 W per °C and r = 20 °C, where does the greenhouse settle, in °C?
Answer: °C
4. You double Kp. What happens to the leftover (steady-state) error?
- It doubles
- It gets smaller but does not reach zero
- It becomes exactly zero
5. At dusk the greenhouse is 8 °C below the setpoint and Kp × error is 300% of full power. What does the heater actually do?
- 300% power
- 100% power: the effort is saturated
- 0% power
Week 27: Project: design a greenhouse that responds
1. Which is the best requirement for the project?
- Keep it warm enough
- The air must stay between 16 and 24 °C for at least 99% of the night
- Use the best controller
2. Your thermometer could fail and read −40 °C. What should the controller do?
- Heat flat out
- Enter a FAULT state: heater off (or a safe fixed level) and raise an alarm
- Ignore it
3. A 10-bit ADC with a 5 V reference reads 602. Using volts = count × Vref ÷ 2^n, what voltage is that, in volts?
Answer: V
4. In ice water (0 °C) your sensor reads 104 counts; in boiling water (100 °C) it reads 874 counts. A new reading is 682 counts. Assuming a straight line, what temperature is that, in °C?
Answer: °C
5. A temperature sensor outputs 0 mV at 0 °C and rises by 10 mV for every 1 °C. It reads 280 mV. What temperature is it measuring, in °C?
Answer: °C
6. The thermometer jitters by ±0.3 °C. Which design choice most directly stops the heater chattering?
- A hysteresis band clearly wider than 0.6 °C
- A faster ADC
- A bigger heater
Week 27: Project: test it, show the evidence
1. Which plan tests whether the outside temperature affects energy use fairly?
- Change outside temperature only; keep the controller settings and noise the same
- Change outside temperature and the band together to save time
- Run once at −5 °C and guess
2. A PWM output switches between 0 V and 3.3 V with a duty cycle of 85%. What is the average voltage, in volts?
Answer: V
3. A traffic light cycles: state 0 red for 25 s, state 1 red-and-amber for 2 s, state 2 green for 20 s, state 3 amber for 3 s, then back to red. It enters red at t = 0 s. Which state number is showing at t = 58 s? (A state that starts at exactly t is already showing.)
Answer: state
4. A proportional heater controller uses effort = gain × error, where error = setpoint − temperature. The gain is 25% per °C and the effort is limited to the range 0 to 100%. The setpoint is 22 °C and the temperature is 22 °C. What heater effort does it command, in %?
Answer: %
5. You sample a 5 Hz signal at 20 Hz. How many samples land in each cycle of the signal?
Answer: samples
6. Switchings fell from 140 to 35 when you widened the band. By what percentage did they fall?
Answer: %
7. Your controller passed all three simulated nights. Which claim is honest?
- It will work in any real greenhouse
- It met the requirements in three runs of a simplified model; real conditions (sun, wind, uneven heating) are untested
- It is perfect