Embedded Systems & Real-Time Software
Level: 4 — Application (novel problems, no hints) Time limit: 60 minutes Total marks: 60
Answer all questions. Show all working. State assumptions clearly.
Question 1 — Sensor Sampling Chain (12 marks)
A vibration monitoring node on an aircraft engine must digitise a signal whose highest useful frequency component is 8.5 kHz. Noise energy exists up to 30 kHz. The design uses an ARM Cortex-M4 with a 12-bit SAR ADC referenced to 3.3 V.
(a) State the minimum theoretical sampling rate and explain why the engineers chose an actual rate of 48 kHz rather than the theoretical minimum. (3)
(b) Compute the ADC's quantisation step (LSB voltage) and the maximum quantisation error for a single sample. (3)
(c) The 30 kHz noise is not removed by any analog filter. If sampling at 48 kHz, at what apparent (aliased) frequency will this noise appear in the digitised data? Show the calculation. (3)
(d) The ADC feeds samples into RAM. Justify whether DMA or polling in an ISR is the better transfer mechanism here, and name the DMA transfer type used. (3)
Question 2 — CAN Bus Arbitration & Timing (14 marks)
Three ECUs share a 500 kbit/s CAN bus. They simultaneously start transmitting standard (11-bit identifier) frames with the following identifiers (binary, MSB first):
- Node A:
100 1100 0011 - Node B:
100 1010 1111 - Node C:
100 1100 0001
(a) Determine which node wins arbitration. Show the bit-by-bit comparison and state at which bit position the losers drop out. Recall CAN uses dominant = 0, recessive = 1. (5)
(b) After the winning frame's 11-bit ID, the remaining fields for a data frame of 3 data bytes total approximately: RTR+control(6) + data(24) + CRC(15) + delimiter/ACK/EOF/IFS(≈13) bits. Ignoring bit-stuffing, estimate the total frame length in bits and the time to transmit at 500 kbit/s. (4)
(c) Explain how CAN's arbitration mechanism guarantees that the highest-priority message is never delayed by lower-priority traffic beyond one frame time, and why this property matters for aerospace. (3)
(d) Name one CAN error-detection mechanism and describe what a node does when its transmit error counter exceeds 255. (2)
Question 3 — RTOS Scheduling & Priority Inversion (14 marks)
A FreeRTOS system on a Cortex-M7 runs three tasks under preemptive priority scheduling (higher number = higher priority):
| Task | Priority | Behaviour |
|---|---|---|
| H | 5 | Needs shared resource R briefly |
| M | 3 | CPU-bound, no resource use |
| L | 1 | Holds resource R via a mutex |
(a) Task L takes the mutex, then H becomes ready and preempts L. H tries to take the mutex and blocks. M then becomes ready. Describe the sequence of events that leads to unbounded priority inversion, and identify what makes it "unbounded". (5)
(b) Explain precisely how priority inheritance fixes this, including what priority L is temporarily raised to and when it reverts. (4)
(c) In FreeRTOS, which IPC primitive should be used for this mutual exclusion to get priority inheritance, and which primitive would you deliberately not use because it lacks inheritance? (2)
(d) Give the xTaskCreate priority argument you would pass for task H if configMAX_PRIORITIES is 6, and explain the idle task's priority. (3)
Question 4 — Timer / PWM Configuration (10 marks)
A motor driver requires a PWM signal at 20 kHz with 10-bit duty resolution. The timer clock is 80 MHz.
(a) Choosing a period (ARR) value that gives full 10-bit duty resolution, compute the required prescaler and show your working. Comment on whether an exact 20 kHz is achievable. (5)
(b) To command 35 % duty cycle, compute the compare (CCR) value to load. (2)
(c) The same timer is later reconfigured for input capture to measure the period of an incoming tachometer signal. Explain in one or two sentences how input capture recovers the frequency, and one source of measurement error. (3)
Question 5 — Safety-Critical Architecture (10 marks)
You are architecting the flight-control computer software for a UAV, targeting DO-178C.
(a) A single processing lane produces a control output. Describe a Triple Modular Redundancy (TMR) scheme with voting, and state what happens when one lane disagrees. (3)
(b) Contrast fail-safe and fail-operational behaviour, and state which is appropriate for the primary flight-control loop of a UAV with no manual backup. (3)
(c) Give two distinct roles a watchdog timer plays and explain what "feeding" the watchdog means and where in the software it should (and should not) be done. (2)
(d) State one reason MISRA C forbids dynamic memory allocation (malloc) in this class of software. (2)
Answer keyMark scheme & solutions
Question 1 (12 marks)
(a) Nyquist rate = minimum (1). Real ADCs need a transition band for the anti-alias filter; sampling well above Nyquist (oversampling to 48 kHz) relaxes the analog filter's roll-off requirement and pushes aliasing away from the signal band (2).
(b) LSB V mV (2). Max quantisation error LSB mV (1).
(c) Folding about kHz. kHz kHz, so alias kHz (2). Since 18 kHz signal band (8.5 kHz), it corrupts nothing in-band here but confirms aliasing occurs; the alias appears at 18 kHz (1).
(d) DMA is better: continuous, periodic samples at 48 kHz would generate 48 000 interrupts/s, imposing high ISR overhead/latency (2). DMA moves each converted sample peripheral-to-memory without CPU intervention, interrupting only on buffer-full (1).
Question 2 (14 marks)
(a) Compare bit-by-bit; lowest binary value (most dominant/0 bits early) wins.
bit#: 1 2 3 4 5 6 7 8 9 10 11
A : 1 0 0 1 1 0 0 0 0 1 1
B : 1 0 0 1 0 1 0 1 1 1 1
C : 1 0 0 1 1 0 0 0 0 0 1
Bits 1–4 identical (1). At bit 5: A=1, B=0, C=1. B sends dominant 0, so A and C would lose — but wait, A and C both send recessive 1 while B sends 0 (dominant). Bus reads dominant. A and C see mismatch and drop out at bit 5 (2). B continues alone and wins arbitration (2).
(Full credit: winner = Node B, losers A & C drop out at bit position 5.)
(b) Total bits bits (2). Time (2).
(c) Arbitration is non-destructive: a node transmitting recessive that reads dominant yields immediately without losing data; the highest-priority (lowest ID) frame always proceeds bit-uninterrupted (2). A lower-priority frame can delay a pending high-priority frame by at most the currently-in-progress frame time — bounded latency, essential for deterministic aerospace timing (1).
(d) Any of: bit monitoring, bit-stuffing check, CRC check, form check, ACK check (1). When the Transmit Error Counter exceeds 255, the node enters the bus-off state and removes itself from the bus (stops transmitting) (1).
Question 3 (14 marks)
(a) L holds mutex → H preempts L → H blocks on mutex (waiting for L). M (priority 3) becomes ready; since M > L and H is blocked, scheduler runs M, not L (2). M keeps running (CPU-bound), so L never gets CPU to finish and release the mutex, so H stays blocked (2). It is unbounded because any number of medium-priority tasks can keep running indefinitely, so the delay to H has no bound related to L's critical section length (1).
(b) With priority inheritance, when H blocks on the mutex held by L, L's priority is temporarily raised to H's priority (5) (2). Now L outranks M, so M cannot preempt L; L runs, finishes its critical section, releases the mutex (1). On release, L reverts to its original priority (1), and H immediately acquires the mutex and runs. Inversion is bounded by L's critical-section length.
(c) Use a mutex (xSemaphoreCreateMutex) which supports priority inheritance (1). Do not use a binary semaphore for mutual exclusion — it has no inheritance and no ownership (1).
(d) Pass priority 5 for H (valid range 0…configMAX_PRIORITIES-1 = 0…5) (2). The idle task runs at priority 0, the lowest, so it only runs when no other task is ready (1).
Question 4 (10 marks)
(a) 10-bit resolution needs 1024 counts, so ARR (period = 1024 counts) (1). Timer tick freq needed MHz (1). Prescaler divides 80 MHz: (1). Not an integer → exact 20 kHz with full 10-bit resolution is not achievable simultaneously (1). Choosing PSC=3 (divide-by-4) → tick = 20 MHz, with ARR=999 gives exactly 20 kHz but only ~10-bit (1000 steps). Comment: trade resolution vs exactness; PSC=0, ARR=3999 gives exact 20 kHz with 4000 steps (>10 bit). Accept any correct reasoned choice (1).
(b) With ARR=1023 (1024 steps), 35% → CCR (2). (If using ARR=3999: CCR = 1400.)
(c) Input capture latches the timer count on each signal edge; period = difference between successive captured counts, frequency = timer_clock/(count difference) (2). Error source: timer resolution/quantisation, or jitter/prescaler granularity, or missed edges at high frequency (1).
Question 5 (10 marks)
(a) Three identical lanes compute the same output from the same inputs; a majority voter outputs the value agreed by ≥2 lanes (2). If one lane disagrees, the voter masks it (outputs the majority) and the faulty lane can be flagged/isolated, system continues correctly (1).
(b) Fail-safe: on fault, transition to a safe (often inactive/de-energised) state — acceptable when a safe state exists (1.5). Fail-operational: continue delivering full function despite a fault (1). For a UAV primary flight loop with no manual backup, dropping to a safe passive state = crash, so fail-operational is required (0.5).
(c) Roles: (i) detect software hang/deadlock and reset the MCU; (ii) detect a task overrunning/missing its deadline (1). "Feeding" = periodically resetting the watchdog counter before it expires; it must be done from a healthy point that proves the whole system is alive (e.g. after a supervisor confirms all critical tasks ran) and not blindly from a timer ISR or tight loop that could keep running while the app is dead (1).
(d) Any one: dynamic allocation risks non-deterministic timing, heap fragmentation, allocation failure/out-of-memory at runtime, and unpredictable WCET — all unacceptable in safety-critical code (2).
[
{"claim":"ADC LSB voltage = 3.3/4096 ≈ 0.806 mV","code":"lsb = Rational(33,10)/4096; result = abs(float(lsb) - 0.0008057) < 1e-6"},
{"claim":"Alias of 30kHz at fs=48kHz is 18kHz","code":"fs=48; f=30; alias=abs(fs-f); result = alias==18"},
{"claim":"CAN frame ~69 bits at 500kbit/s = 138us","code":"bits=11+6+24+15+13; t=bits/500000; result = bits==69 and abs(t-138e-6)<1e-9"},
{"claim":"PWM: 80MHz/(20kHz*1024) not integer","code":"ratio = 80e6/(20000*1024); result = abs(ratio-3.90625)<1e-6 and ratio != int(ratio)"},
{"claim":"35% of 1024 steps = 358","code":"ccr = int(0.35*1024); result = ccr==358"}
]