TactivergeLite

Lite / Building Machines That Respond / Term 3 worksheet

Worksheet: Building Machines That Respond, term 3

Embedded Intelligence · Questions only. Check your answers in each Lite lesson, where they are graded on our server.

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?

2. Which peripheral turns a sensor voltage such as 1.2 V into a number the program can use?

3. Why does a TV remote use a microcontroller rather than a laptop processor?

4. What does the CPU do over and over while the program runs?

5. A microcontroller's clock runs at 160 MHz. How long is one clock period, in nanoseconds?

Answer: ns

Check these in the lesson

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?

Check these in the lesson

Week 19: Set up once, loop forever

1. Where should 'set pin 3 as an output' go?

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?

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?

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

Check these in the lesson

Week 20: Pins: high, low and in between

1. A pin is set as a plain input with nothing connected. What does it read?

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?

Check these in the lesson

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'?

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?

5. Why not use a 10 MΩ pull-up to save even more current?

Check these in the lesson

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?

4. You set a debouncer to need 20 readings every 5 ms. A quick 50 ms tap is ignored. Why?

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

Check these in the lesson

Week 21: Range, resolution, accuracy, precision

1. Every reading from a scale is exactly 200 g too heavy. What kind of problem is that?

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?

5. You need to measure a freezer at −18 °C. Which sensor range should you rule out?

Check these in the lesson

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?

5. Which formula has units that work out to °C?

Check these in the lesson

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?

5. A greenhouse must be held at 16–24 °C. Which pair of calibration points is best?

Check these in the lesson

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?

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?

Check these in the lesson

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?

Check these in the lesson

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?

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?

Check these in the lesson

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?

5. A vending machine has states idle, paid, vending, empty. No rule ever leaves 'empty'. What kind of problem is that?

Check these in the lesson

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?

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?

Check these in the lesson

Week 23: A state machine in twelve lines

1. state is CLOSING and the event is 'person'. Which value does `step` return?

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?

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?

Check these in the lesson

Week 24: DC motors, servos and steppers

1. Which actuator suits a desk fan best?

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?

5. A small robot arm's elbow must point at 30°, then 75°, and hold still against gravity. Which is the simplest choice?

Check these in the lesson

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?

5. You send a 2.6 ms pulse to a servo whose range is 1.0–2.0 ms. What is the risk?

Check these in the lesson

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?

5. A greenhouse vent must hold 0°, 45° or 90°, against gusts, and the budget is tight. Which actuator is the sensible first choice?

Check these in the lesson

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?

Check these in the lesson

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?

Check these in the lesson

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?

4. Why write `last += 500` instead of `last = now` when a task runs?

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

Check these in the lesson

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?

2. In a greenhouse heater loop, what is the 'error'?

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?

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: %

Check these in the lesson

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?

3. What do you trade when you widen the hysteresis band?

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?

Check these in the lesson

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?

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?

Check these in the lesson

Week 27: Project: design a greenhouse that responds

1. Which is the best requirement for the project?

2. Your thermometer could fail and read −40 °C. What should the controller do?

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?

Check these in the lesson

Week 27: Project: test it, show the evidence

1. Which plan tests whether the outside temperature affects energy use fairly?

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?

Check these in the lesson