Cambridge AS & A Level · Part 1 · Chapter 7
Monitoring and Control Systems
Sensors that watch, actuators that act, and a program in the middle that never stops looping. This page has every figure, question and exam question from the chapter, with labs for feedback loops and bit flags.
Guru Jazzy🎯 Learning objectives
By the end of this chapter you should be able to:
- show that you understand monitoring and control systems
- show how bit manipulation can be used to monitor or control a device
📡 7.01 Monitoring systems
A monitoring system watches some physical property of a system. It can be used in two ways:
- to build up a record of the system's condition over a period of time
- more often, to detect the moment a property goes outside its safe or desired range: for example, a CPU that is running too hot
Some ideas to compare with yours
CPU temperature in a laptop · a patient's heart rate and blood oxygen in hospital · river levels for flood warnings · air quality (PM2.5) in a city · a smart-meter recording electricity use · weather stations · a burglar alarm · smoke and carbon monoxide alarms · tyre-pressure warnings in a car · a fitness tracker counting steps · earthquake seismometers.
Sensors
With a person in charge, you might read a temperature from a mercury thermometer. In this chapter, a computer or microprocessor is doing the job, so it needs a measuring device whose value can be sent to it. That device is a sensor. For temperature, a thermocouple is one example: its output voltage changes with temperature.
Kinds of sensor
| Named after what it measures | Named after how it works | Named generically |
|---|---|---|
| temperature, pressure, humidity, carbon monoxide, pH, sound, light | Infrared: a passive infrared (PIR) sensor just measures the infrared it receives; an active one sends out infrared and measures how much is reflected back | Motion sensor: different motion sensors actually measure different physical properties |
🎮 Pick the sensor
Which sensor would a computer need for this job?
Show some answers
- Passive infrared (PIR): detects the heat of a moving body (security lights, alarms).
- Active infrared beam: something breaking the beam is detected (lift doors, shop doors).
- Microwave / radar: measures reflected microwaves (Doppler effect), as in automatic doors.
- Ultrasonic: times reflected sound pulses (car parking sensors).
- Accelerometer and gyroscope: measure the device's own movement (phones, fitness trackers).
- Pressure mat: detects a person stepping on it.
- Camera / video motion detection: compares successive images.
🎛️ 7.02 Control systems
A control system does everything a monitoring system does, and it can change what is happening. To act on the system it needs an actuator: an electric motor connected to a controlling device. The actuator might switch something on or off, or adjust a setting.
A way to decide
Ask: does the system change the thing it is measuring? A laptop that speeds up its fan when the CPU gets hot is a control system. A river-level gauge that only sends warnings is monitoring. It would become control if it also opened flood gates (an actuator), and its next reading would show whether that worked.
🎮 Monitoring or control?
🔁 A computer-controlled environment Figure 7.01
Follow the loop round the diagram:
- The sensor in the controlled environment produces an analogue measured value.
- An ADC (analogue-to-digital converter) turns it into a digital value for the computer.
- The computer checks the value against the desired range.
- If action is needed, it sends a digital control signal to a DAC (digital-to-analogue converter).
- The DAC's analogue control signal drives the actuator and its controlling device (heater, fan, valve…).
The diagram shows the ADC and DAC as separate boxes. In real systems they are usually built into the sensor or actuator itself.
The process never stops. At regular, timed intervals the computer asks the sensor for a reading. If the value is out of range, the computer starts a control action. The next timed reading then shows the computer what effect that action had. This is feedback, and a control system cannot work without it.
♻️ Closed-loop feedback control Figure 7.02
A closed-loop feedback control system is a special case where the feedback directly drives what happens next:
- A microprocessor acts as the controller.
- It compares the actual output, read by the sensor, with the desired output.
- It sends the actuator a value that depends on the difference between the two.
🔬 Lab: the greenhouse controller
The controller reads the temperature sensor every sample, compares it with the target and switches the heater (the actuator) on or off. The night outside gets colder as time passes. Turn feedback off to see what happens to a heater on a fixed timer.
Show some answers
- Air conditioning or central heating with a thermostat.
- A car's cruise control, which holds a set speed up and down hills.
- An oven or a 3D printer's heated nozzle and bed.
- An aircraft autopilot, or a drone holding its height.
- A greenhouse controlling temperature, humidity and watering.
- Industrial processes: chemical reactors, pH dosing in water treatment.
🔢 7.03 Bit manipulation to control devices
The controlling computer runs a real-time program that loops forever. As the sensors report, the program sets Boolean flags. With two properties to monitor and control, it could use four flags:
IF SensorDifference1 > 0 THEN Sensor1HighFlag ← TRUE IF SensorDifference1 < 0 THEN Sensor1LowFlag ← TRUE IF SensorDifference2 > 0 THEN Sensor2HighFlag ← TRUE IF SensorDifference2 < 0 THEN Sensor2LowFlag ← TRUE
Another part of the program keeps checking whether any flag is set. In machine code, each flag can be a single bit of a byte. The fragments below use the three least significant bits (positions 0, 1 and 2) of the byte at address 0034 as flags.
| Goal | Code | How it works |
|---|---|---|
| Clear every bit (e.g. at switch-on) | LDD 0034 AND #B00000000 STO 0034 | AND with 0 always gives 0, so every bit becomes 0. |
| Toggle one bit (a problem has appeared, or been solved) | LDD 0034 XOR #B00000001 STO 0034 | XOR with 1 flips a bit; XOR with 0 leaves it alone. Only bit 0 changes. |
| Set one bit to 1, whatever its value (report a condition repeatedly) | LDD 0034 OR #B00000100 STO 0034 | OR with 1 forces a 1; OR with 0 changes nothing. Only bit 2 is set. |
| Test one bit | LDD 0034 AND #B00000010 STO 0034 | AND with 0 clears the other bits and keeps bit 1. Comparing the result with 2 (binary 00000010) shows whether bit 1 was set. |
In each case, LDD loads the byte into the accumulator, the logic instruction changes it, and STO stores it back at the same address.
🔬 Lab: the flag register
Tap bits of the register (address 0034) or the mask to change them, then apply an operation. Every bit position is processed at once.
Register (0034)
Mask (operand)
🎮 Choose the operation and mask
Pick the bitwise operation, set the 8-bit operand, and check. Your mask must work for any starting value of the register.
🌡️ Packing a reading into two bytes
Exam Question 3 below stores one greenhouse reading in two bytes. This drill practises the format:
- Byte 1: bits 7–1 show the location (location 4 sets bit 4). Bit 0 is a flag: 0 = not yet processed, 1 = processed.
- Byte 2: the temperature as an 8-bit two's complement integer, so readings below zero are allowed.
🎮 Encode the reading
🚨 Tracing the intruder alarm program
This is the program from exam Question 4. Four sensors are stored in bits 0–3 of SENSORS. The program counts how many sensors are triggered by testing one bit at a time: VALUE takes the values 1, 2, 4, 8 as its mask. Step through it, or pick other sensor values.
Sensors triggered (tap to change)
| Instruction | SENSORS | COUNT | VALUE | ACC |
|---|
📌 Summary
- A monitoring system needs sensors.
- A sensor measures a physical quantity: temperature, humidity, pH, infrared, pressure, sound, carbon monoxide and many more.
- A monitoring and control system needs sensors and actuators.
- Its program runs in real time, in an infinite loop that reads the sensors at timed intervals.
- If the sensor values show that action is needed, the program sends signals to the actuators.
- Bit manipulation in an assembly language program can be used to monitor or control devices.
🃏 Key-term flashcards
Tap a card to flip it.
✅ Quick quiz
📝 Exam-style questions
Write your answer first, then open the model answer. These are my mark-scheme-style points, not official mark schemes.
(i) A monitoring system.
(ii) Sensors.
(iii) Any two, about 3 marks each: name, what it measures, how the value is used.
- Temperature sensor: measures the air temperature in the barn. Its value goes through an ADC to the computer, which displays it and flashes the warning if it is outside the range the hens need.
- Light sensor: measures light level. Hours of light affect egg laying, so the computer warns if the barn is too dark or bright.
- Humidity sensor: measures moisture in the air. Too humid or too dry triggers the warning on screen.
- Gas sensor (e.g. ammonia or CO₂): measures air quality, so poor ventilation can be spotted.
(i) A (monitoring and) control system.
(ii) Actuators.
(iii) The computer reads the sensors at regular intervals and compares each value with the stored acceptable range. If a value is outside the range, it sends a signal (through a DAC) to the right actuator, e.g. to switch a heater, fan or lights on or off. The next reading gives feedback on whether the action worked.
| Part | Operation | Operand | Why |
|---|---|---|---|
| (a) | AND | 00000000 | Anything AND 0 is 0. |
| (b) | OR | 00000100 | OR 1 sets bit 2; OR 0 leaves the other bits unchanged. |
| (c) | XOR | 00110000 | XOR 1 flips bits 4 and 5 (1→0, 0→1); XOR 0 leaves the rest. |
(a) A monitoring system (data logging).
(b) Any three, each with a justification:
- Temperature sensor: to measure the temperature in the greenhouse.
- ADC: the sensor's output is analogue and the computer needs digital values.
- Computer / microprocessor or data logger: to request a reading every hour and process it.
- Storage (e.g. flash memory or a hard disk): to keep all the readings for the whole season.
(i) Bit 5 is set, so the reading came from location 5. Bit 0 is 1, so the reading has been processed. (Byte 2 = 00011000 = 24 degrees.)
(ii) Byte 1 = 01000000 (bit 6 set, flag 0). Byte 2 = 11111011: +5 = 00000101, flip the bits to 11111010, then add 1.
(i)
LDD 106 // byte 1 into ACC AND #B00010000 // keep only bit 4 CMP #B00010000 // was bit 4 set? (= denary 16) JPE LOCATION4 // jump if it came from location 4
(ii) OR #B00000001 sets bit 0 to 1 and leaves every other bit unchanged.
Cambridge International AS & A Level Computer Science 9608, Paper 31 Q5, June 2015
(a)(i) A monitoring system.
(ii) It only reports a condition by sounding an alarm. It does not change the environment, and there is no feedback controlling a process.
(b) Any two, each with a reason:
- Passive infrared (PIR) sensor: detects the body heat of a person moving in a room.
- Pressure sensor under a mat or floor: detects someone stepping on it.
- Magnetic contact switch on a door or window: detects it being opened.
- Sound sensor: detects breaking glass or noise in an empty house.
(i) Key values as the program runs:
| Pass | VALUE (mask) | SENSORS AND VALUE | COUNT after |
|---|---|---|---|
| 1 | 1 | 0 | 0 |
| 2 | 2 | 2 | 1 |
| 3 | 4 | 0 | 1 |
| 4 | 8 | 8 | 2 |
When VALUE = 8, CMP #8 is true and the program jumps to EXIT, which loads COUNT: ACC = 2.
(ii) #1. JGT ALARM jumps when COUNT > 1, i.e. two or more sensors.
(iii) The instruction CMP #8 (after ZERO: LDD VALUE) becomes CMP #128, so the mask goes on up to bit 7.
Cambridge International AS & A Level Computer Science 9608, Paper 31 Q6, June 2016
Guru Jazzy · Cambridge AS & A Level Computer Science · Chapter 7 Monitoring and Control Systems · Figures from the Cambridge coursebook (Langfield & Duddell)