Teaching pack · UAT 204

A 15-week teaching plan, 5 worksheets, a scoring rubric and a map from the course description to the lessons, for instructors to evaluate and adapt before teaching.

Last updated: · 3(2-2-5) · Per week: lecture 2 h, lab 2 h, self-study 5 h; 60 contact hours per term

Coverage of the course description

The lessons fully teach 10 of 10 description topics. Each topic lists the modules and lesson sections that teach it, and incomplete topics say what is missing.

Description topicModulesWhere it is taughtStatus
Microcontroller architectureM1Module 1: Inside a microcontroller (CPU, bus, peripherals) and MCUs in drone work (Pixhawk 6X, Pico 2, ESP32-S3)Covered
MemoryM1M2Module 1: Flash and SRAM in 'Inside a microcontroller' · Module 2: Memory and coding standardsCovered
Input/output portsM2M3Module 2: Manipulating register bits · Module 3: GPIO (pull-ups and reading a button)Covered
Analog-to-digital conversionM1Module 1: The ADC, from voltage to numbers, and Example 1 measuring a 6S battery with a 12-bit ADCCovered
PWMM3Module 3: Timers and PWM, pulse widths for servos and ESCsCovered
TimersM3Module 3: Timers and PWM and Example 1 finding PSC and ARRCovered
InterruptsM2M3Module 2: volatile · Module 3: Polling and interrupts and Example 2 debouncing a buttonCovered
Serial communicationsM4Module 4: UART · I2C and SPI · CAN and DroneCAN · Detecting corruption with a checksumCovered
Embedded programmingM2M5Module 2: Fixed-width data types, bit manipulation, volatile and BARR-C · Module 5: Tasks, priority and preemption and RTOSs in flight stacksCovered
Interfacing sensors and actuatorsM1M3M4Module 1: voltage divider into the ADC · Module 3: driving a servo with PWM · Module 4: an I2C sensor and a DroneCAN GPSCovered

Weekly teaching plan

WeekTopicPre-classLectureLabEvidence
1 M1Inside a microcontrollerRead module 1 'Why this matters' and 'Inside a microcontroller'CPU, Flash, SRAM, bus and peripherals; how an MCU differs from a general computerWorksheet 1 part A: read the Pico 2 pinout, install the tools and write an LED blink programPin map marking GPIO, ADC, 3.3 V and ground; working blink program
2 M1The ADC: from voltage to numbersRead the ADC section; run Example 112-bit resolution, reference voltage and a divider for a 6S batteryWorksheet 1 part B: build the divider, feed it from a supply, read the ADC at three voltages and find a calibration factorADC readings against the multimeter, with calibration factor
3 M1MCUs in drone workRead 'MCUs in drone work'; take the module 1 quizThe two processors in the Pixhawk 6X and the FMU/IO splitWorksheet 1 part C: use the PX4 documentation to map each Pixhawk 6X sensor and port to its processorWorksheet 1 report and quiz result
4 M2Fixed-width data types and overflowRead module 2 'Fixed-width data types'; run Example 1uint8_t to int32_t and an 8-bit counter wrapping roundWorksheet 2 part A: predict then run Example 1; write a uint8_t counter on the Pico 2 showing wrap-around over serialPredictions against results and the serial log
5 M2Manipulating register bitsRead 'Manipulating register bits'; run Example 2Setting, clearing, toggling and reading bits with bitwise operatorsWorksheet 2 part B: write C on the Pico 2 that sets and clears GPIO control bits with SDK functions, checked against hand calculationCalculated versus read bit values
6 M2volatile, memory and coding standardsRead 'volatile' and 'Memory and coding standards'; take the module 2 quizWhy optimisation loses an interrupt flag, and the relevant BARR-C rulesWorksheet 2 part C: test a flag with and without volatile; review the group's code against three BARR-C rulesWorksheet 2 report and quiz result
7 M3GPIO and reading a buttonRead module 3 'GPIO'Input and output pins, internal pull-ups and contact bounceWorksheet 3 part A: wire a button with pull-up, read by polling and count presses without debouncingCounted presses against actual presses
8 M3Timers and PWMRead 'Timers and PWM'; run Example 1PSC, ARR and CCR and servo/ESC pulse widthsWorksheet 3 part B: generate 1100, 1500 and 1900 µs pulses, measure them and drive a servoCaptures of the three pulses; PSC and ARR calculated for the Pico 2
9 M3Polling versus interrupts; midtermRead 'Polling and interrupts'; run Example 2; review modules 1–3 and take the module 3 quizMidterm examination (modules 1–3)Worksheet 3 part C: switch to an interrupt setting a volatile flag, debounce in the main loop and compare counts with pollingWorksheet 3 report and midterm score
10 M4UART and real throughputRead module 4 'UART'; run Example 1UART framing, start and stop bits, baud and real throughputWorksheet 4 part A: set a wrong baud rate on one side, observe the data and explainGarbled data sample with explanation
11 M4I2C, SPI and reading a sensorRead 'I2C and SPI'Addresses, ACK, signal lines and when to use SPIWorksheet 4 part B: connect an I2C sensor, scan addresses, read values and capture SDA/SCL with a logic analyzerBus capture labelled with start, address, ACK and data
12 M4Checksums, CAN and DroneCANRead 'CAN and DroneCAN' and 'Detecting corruption with a checksum'; run Example 2; take the module 4 quizFrame integrity checks and using DroneCAN devices on ArduPilotWorksheet 4 part C: send Example 2 frames over UART, write a receiver checking the checksum, and list the DroneCAN GPS parametersWorksheet 4 report and quiz result
13 M5Tasks, priority and preemptionRead module 5 'Tasks, priority and preemption'; run Example 1Rate-monotonic priorities and checking a task set meets its deadlinesWorksheet 5 part A: build a three-task FreeRTOS project (10, 100, 500 ms) and time it by toggling GPIO pinsTiming captures of each task
14 M5RTOSs in flight stacks and from MCU to AIRead 'RTOSs in flight stacks' and 'From MCU to AI'; take the module 5 quizRTOSs in PX4 and ArduPilot and the limits of MCUs for AI workloadsWorksheet 5 part B: add a heavy low-priority load, check sensor timing, enable the watchdog and simulate a hung taskMeasured timing against Example 1 and a record of the reset
15 M5Embedded mini-projectPrepare the mini-project code and report combining worksheets 1–5Course wrap-up and project criteriaMini-project demo: read a sensor (ADC or I2C), send checksummed UART frames and drive a servo under FreeRTOSDemo, code and mini-project report, scored with the rubric

Worksheets and instructor guide

One worksheet per module. Students open it on the web, print it or download the .docx. The instructor guide under each worksheet gives the class timing, expected results, discussion questions and notes for students with different backgrounds.

1Worksheet 1 Getting to know the Pico 2 and its ADC
Lab · About 6 h of class time · CLO1

Objective: Identify MCU pins and parts, write a first program, calibrate voltage measurement with the ADC and relate it to a real flight controller

Equipment

  • Raspberry Pi Pico 2 and USB cable
  • Computer with MicroPython or the C/C++ SDK
  • Breadboard, resistors and LEDs
  • Adjustable supply
  • Multimeter
  • Example code at /downloads/uat-204/

Safety

  • Never feed more than 3.3 V into an ADC pin; check the calculated value before powering
  • Use a supply instead of a real battery, with the current limit set
  • Unplug USB before rewiring

Steps

  1. Read the pinout and mark GPIO, ADC, 3.3 V and ground
  2. Install the tools as directed and write an LED blink program
  3. Build the divider and feed it from a supply no higher than the safe value
  4. Read the ADC at three voltages
  5. Compare with Example 1 and the multimeter; find a calibration factor
  6. Use the PX4 Pixhawk 6X page to map sensors and ports to processors

Deliverables

  • Annotated pin map
  • Blink and ADC code
  • ADC against multimeter table with calibration factor
  • Pixhawk 6X device-to-processor table

Checklist

  • The blink and ADC programs run, and the code actually used is attached (Correct programs and peripheral configuration)
  • Table 2 has all 3 voltages, every value has a unit, and every ADC pin voltage is at or below 3.3 V (Measurement and verification with instruments)
  • The calibration factor calculation (multimeter value divided by the value computed from the code) is shown for at least one row (Measurement and verification with instruments)
  • Table 1 marks the 3.3 V, ground, ADC and LED GPIO pins matching the pinout (Recording results and explaining system behaviour)
  • Table 3 names both the main processor and the IO processor, with the interface of each device (Recording results and explaining system behaviour)

Instructor guide

Class timing 360 min

  1. Objectives and safety briefing: the 3.3 V limit and setting the current limit30 min
  2. Read the pinout, install the tools and write the blink program90 min
  3. Build the divider, calculate the pin voltage before powering, read the ADC at three voltages90 min
  4. Compare with the multimeter and Example 1; find the calibration factor60 min
  5. Study the Pixhawk 6X page and fill in Table 360 min
  6. Wrap-up, questions and hand-in checklist30 min

Expected results

  1. Record: Table 1 Pico 2 pins used in this worksheetTable 1: at least the 3.3 V pin, a ground pin, one ADC pin and the GPIO pin driving the LED (through a current-limiting resistor). Pin numbers must match the real Pico 2 pinout, not just the pin names.
  2. Record: Table 2 ADC readings against the multimeterTable 2 (with R1 = 100 kΩ, R2 = 10 kΩ and a 3.3 V reference as in Example 1): ratio 0.0909, 1 LSB = 0.806 mV at the pin = 8.86 mV of input voltage. 12.0 V in gives 1.091 V at the pin and a code of about 1354; 9.0 V gives 0.818 V, about 1016; 5.0 V gives 0.455 V, about 564 (if the supply reaches 25.2, 22.2 and 19.8 V the codes are 2844, 2505 and 2234). The calibration factor should be between 0.97 and 1.03 with 1% resistors (about ±1.8% from the resistors); with 5% resistors it may be off by about ±9%. Example: multimeter 12.00 V, computed 12.18 V, factor 0.985.
  3. Record: Table 3 Pixhawk 6X devices and processorsTable 3 (from Figure 2 of the lesson): the main processor (FMU), an STM32H753 Cortex-M7 at 480 MHz, connects to the IMU, barometer and compass over SPI and I2C, to GPS and telemetry over UART, and to DroneCAN over CAN; the IO processor, an STM32F100 at 24 MHz, handles PWM outputs and RC input. A good reason given: outputs are offloaded so the main processor can spend its time on state estimation and attitude control.
  4. Question 1: From Table 2, by what percentage does the voltage computed from the code differ from the multimeter, and what is the most likely main cause (resistor tolerance, reference voltage or noise)?A typical difference is 1 to 3% with 1% resistors. A strong answer computes the percentage from its own table and notes that an error that stays the same proportion at every voltage comes from the resistor ratio or the reference voltage, so a calibration factor fixes it, while readings that jump between samples come from noise and need averaging.
  5. Question 2: With R1 = 100 kΩ and R2 = 10 kΩ, what is the highest input voltage that keeps the ADC pin at or below 3.3 V, and why should the supply still be set well below it?3.3 / 0.0909 = 36.3 V, but the supply must be set well below it because resistors have tolerance, the real reference may not be exactly 3.3 V, and a wiring mistake or a loose R2 puts the full voltage on the pin. That is why a current-limited supply is used and the pin voltage is calculated before every power-up.
  6. Question 3: How many mV of battery voltage does one step of the group's 12-bit ADC represent, and is that fine enough to warn of a low battery? Why?About 8.86 mV of battery voltage per step (0.806 mV at the pin). That is fine enough to warn of a low battery, because warning thresholds differ by hundreds of mV across the pack. The real limit is accuracy (resistors, reference, noise), not resolution, which is why calibration is needed.
  7. Question 4: Why does the Pixhawk 6X use two processors instead of letting the main processor do everything? Answer using Table 3.The main processor must estimate state and control attitude hundreds of times a second with many sensors. Moving PWM outputs and RC input to the IO processor reduces its load and separates output handling from computation. A strong answer cites the real devices in Table 3 rather than just saying it is faster.

Discussion questions

  • When choosing an MCU for a drone's add-on sensor module, what must you check besides CPU speed?
  • Why do SRAM variables vanish at power-off while the program in Flash stays, and what does that mean for the calibration factor found today?

Adapting to student background

Upper secondary (M.6)
Have them calculate the divider ratio, LSB and expected code by hand before wiring, then use the measurements to test the prediction; pair them with a peer confident on the breadboard and have the instructor check the circuit before power-up.
Vocational certificate
Let them wire from the diagram step by step and measure with the multimeter first, then use a fill-in table for the calculation (input voltage times 10/110 gives the pin voltage), with Example 1's code checking the numbers instead of long hand working.
Diploma
Extension: switch to another safe resistor pair, find the new calibration factor, and add 16-sample averaging to the program, comparing how steady the readings are before and after.

Common student mistakes: Common mistakes in the module 1 lesson

2Worksheet 2 Bits, counters and volatile on the board
Lab · About 6 h of class time · CLO2, CLO1

Objective: Use fixed-width types and bit manipulation correctly, understand the effect of volatile and review code against BARR-C

Equipment

  • Pico 2 with the C/C++ SDK
  • Computer with Python and a serial terminal
  • Module 2 example code
  • BARR-C coding standard

Safety

  • Low-voltage bench work over USB; no flying

Steps

  1. Run Examples 1 and 2, predicting results for new starting values
  2. Write C that sets and clears GPIO control bits with SDK functions
  3. Compare bit values with hand calculation
  4. Write a uint8_t counter and show wrap-around over serial
  5. Test an interrupt flag with and without volatile, optimisation on; record behaviour
  6. Read three BARR-C rules on types and variables and review the group's code

Deliverables

  • Predictions against results
  • Bit code and counter log
  • volatile experiment notes with explanation
  • List of BARR-C fixes

Checklist

  • Every row of Table 1 has a prediction written before running and the actual result (Recording results and explaining system behaviour)
  • The set and clear code changes only the target bit, never overwrites the whole register, and uses unsigned constants such as 1u << k (Correct programs and peripheral configuration)
  • The serial log showing the counter wrapping from 255 to 0 is attached (Correct programs and peripheral configuration)
  • The group's code uses fixed-width types from stdint.h, with a list of fixes against the three chosen BARR-C rules (Code quality against embedded standards)
  • Table 3 states the optimisation level and explains the behaviour of both versions (Recording results and explaining system behaviour)

Instructor guide

Class timing 360 min

  1. Review fixed-width types and bit operators; brief the task30 min
  2. Run Examples 1 and 2 with new values, predicting first60 min
  3. Write C to set and clear GPIO bits on the board and compare with hand calculation90 min
  4. The uint8_t counter over serial and the volatile experiment90 min
  5. Read three BARR-C rules and review the group's code60 min
  6. Wrap-up, questions and hand-in checklist30 min

Expected results

  1. Record: Table 1 Predictions against results (Examples 1 and 2 and the board counter)Table 1 (if the instructor uses these values): Example 1 starting at 253, counting 8 times gives 254 255 0 1 2 3 4 5, difference 8; Example 2 starting at 0b11000110, set bit 4 gives 11010110, clearing bit 0 changes nothing (it is already 0), clearing bit 1 gives 11010100, toggling bit 7 gives 01010100 (0x54), bit 2 = 1 and bits 5..4 = 1; the board counter starting at 0 after 300 increments shows 44. Predictions may be wrong, but the last column must explain why.
  2. Record: Table 2 GPIO control bits by hand against the boardTable 2: the mask for GPIO pin k is 1u << k, e.g. GPIO 15 gives 0x00008000 = 32768. Setting the bit turns that pin's LED on, clearing it turns it off, and the other pins do not change. If SDK functions are used, state which register bit each function sets or clears.
  3. Record: Table 3 The volatile experiment with optimisation onTable 3: with volatile, the main loop sees the flag every time the interrupt sets it (the LED or message responds every time). Without volatile and with optimisation on, it usually never responds or responds only once, because the compiler reads the flag once and reuses the remembered value. With optimisation off it may appear to work, which is why this bug is hard to find.
  4. Question 1: At what value did the group's uint8_t counter wrap, and if it read 250 and then 2, what is the difference computed as uint8_t? Why is that difference still correct across the wrap?It wraps from 255 to 0. The difference (2 − 250) as uint8_t is 8, which is correct because unsigned subtraction wraps modulo 256 in the same way, as long as fewer than 256 counts pass between the two readings. A strong answer links this to MCU timers that wrap periodically.
  5. Question 2: From Table 3, how did the code without volatile misbehave, and why only with optimisation on?The compiler sees that the main loop never writes the flag itself, so it reads it once and keeps it in a CPU register instead of reading memory again; the ISR's change is never seen. With optimisation off the compiler reads memory every time, so it seems to work. volatile forces a real read every time.
  6. Question 3: If you overwrite the whole GPIO register instead of setting one bit, what happens to the other pins the group is using? Explain with the results in Table 2.Overwriting sets every bit to the new value, so other pins already set (such as another LED) switch off or change mode unintentionally. That is why bits are set with OR and a mask, and cleared with AND and the complement of the mask.
  7. Question 4: Does volatile solve sharing a variable between two tasks? If not, what should be used instead?No. Per Arm's guide, volatile is for peripheral registers and variables modified by ISRs; it is not a way to share data between threads or tasks. Use atomics or the RTOS's own synchronisation tools instead.

Discussion questions

  • Why should embedded code avoid int when desktop code uses it everywhere?
  • Safety-critical systems often forbid dynamic allocation after start-up. What problem does that prevent on an MCU with little SRAM?
  • What does a bug that disappears when optimisation is off tell you about testing code before it flies?

Adapting to student background

Upper secondary (M.6)
Have them write each register value in binary on paper before running, explain wrap-around with number bases and modulo 256 from school maths, and give extra time for compiling and flashing the board.
Vocational certificate
Start from what the board shows (LEDs on and off, the serial counter), then explain the bits with an 8-box table where they shade the changed box; use Python to check answers instead of converting bases by hand.
Diploma
Extension: write functions that read and write a multi-bit field (such as bits 5..4) without touching other bits, and test them with three starting values.

Common student mistakes: Common mistakes in the module 2 lesson

3Worksheet 3 Driving a servo and reading a button with interrupts
Lab · About 6 h of class time · CLO2

Objective: Compare polling with interrupts, generate accurate PWM pulses with a timer and drive a servo safely

Equipment

  • Pico 2 board
  • Push button and breadboard
  • Servo and a separate servo power supply
  • Oscilloscope or logic analyzer
  • Documentation for the servo used

Safety

  • Power the servo from a separate supply, never the board's 3.3 V pin, with a common ground
  • Clamp the servo and keep fingers clear of the moving horn

Steps

  1. Wire a button with the internal pull-up; poll it and count presses without debouncing
  2. Switch to an interrupt setting a volatile flag; debounce in the main loop
  3. Compare the counts from both methods
  4. Generate 1100, 1500 and 1900 µs pulses at the servo's documented frequency and measure them
  5. Connect the servo and command all three pulses
  6. Calculate PSC and ARR for the Pico 2 clock as in Example 1
  7. Repeat Example 3 with a different stall time and queue size; record missed, overflow and age

Deliverables

  • Press counts for polling and interrupts
  • Captures of the three pulses
  • PSC and ARR calculation
  • Source code
  • Table of the repeated Example 3 results

Checklist

  • Table 1 has at least 3 runs, each with the real number of presses (Recording results and explaining system behaviour)
  • Captures of all 3 pulses from the scope or logic analyzer are attached, with width and period readable (Measurement and verification with instruments)
  • Box 3 shows f_TIM/((PSC+1)(ARR+1)) with every value substituted and checks ARR fits the counter (Correct programs and peripheral configuration)
  • The ISR only sets a volatile flag; heavy work and printing are in the main loop (Code quality against embedded standards)
  • The servo uses a separate supply with common ground, and the pulse frequency from its documentation is stated (Correct programs and peripheral configuration)

Instructor guide

Class timing 360 min

  1. Objectives, servo safety and separate power wiring30 min
  2. Wire the button, count by polling, then switch to interrupt with debouncing90 min
  3. Calculate PSC and ARR, generate the three pulses and measure them90 min
  4. Connect the servo and command the three pulses45 min
  5. Repeat Example 3 with a new stall time and queue size60 min
  6. Wrap-up, questions and hand-in checklist45 min

Expected results

  1. Record: Table 1 Press counts: polling against interrupt with debouncingTable 1: polling without debouncing usually counts as many or more presses than were made (some buttons several times more; in the lesson's Example 2 one press shows 5 falling edges) and can miss presses if the main loop is busy. Interrupt with debouncing must match the real count in every run; if it still overcounts, increase the debounce time.
  2. Record: Table 2 PWM pulses commanded against measuredTable 2 (if the servo documentation gives 50 Hz): CCR = 1100, 1500, 1900, duty 5.50%, 7.50%, 9.50%, measured period 20.0 ms. Measured widths should match within ±5 µs (depending on the instrument's resolution). The horn sits at one side, centre and the other side. If the servo uses another frequency, recalculate ARR; CCR still equals the pulse width in µs.
  3. Record: Box 3 PSC and ARR calculation for the Pico 2 clock (step by step)Box 3: the Pico 2 clock is 150 MHz and we count in 1 µs steps, so PSC = 150 − 1 = 149; a 20 ms period gives ARR = 20000 − 1 = 19999. Check: 150,000,000 / (150 × 20000) = 50.0 Hz, and ARR 19999 is below the 65,535 limit of a 16-bit counter, so it fits.
  4. Record: Table 4 Example 3 repeated with a new stall time and queue sizeTable 4 (suggested runs): main loop at 25, 95, 105 ms with an 8-slot queue gives missed = 7, overflow = 0, but the largest age is still 75 ms and 7 items remain queued; runs at 25, 55, 105 ms with a 4-slot queue give missed = 7, overflow = 4 and ages 15, 35, 75 ms; the lesson's case (25, 95, 105, 4 slots) gives missed = 7, overflow = 4, age 75 ms. Latest value gives age 5 ms in every case.
  5. Question 1: In Table 1, why does polling without debouncing count more presses than were made, and is the 5 ms debounce of Example 2 right for your button? What result shows it?The button contacts bounce briefly when pressed, so the signal goes up and down several times and fast polling sees several falling edges. 5 ms is right if the debounced count matches the real presses in every run; if it still overcounts, lengthen it; if it starts missing quick presses, it is too long. A strong answer quotes numbers from Table 1.
  6. Question 2: How far did the measured pulse widths in Table 2 differ from the commanded values, and with the timer counting in 1 µs steps, why does CCR equal the pulse width in microseconds?They should differ by no more than about ±5 µs; if more, check PSC and the clock used in the calculation. With the timer counting in 1 µs steps each CCR count is 1 µs, so the pin stays high for exactly CCR microseconds, which keeps the code readable.
  7. Question 3: Why must the servo have its own supply with a common ground? What would happen if it drew power from the board's 3.3 V pin?A servo draws high current when it moves. Powered from the board's 3.3 V pin the supply sags until the MCU resets or misbehaves, and the board's regulator may be damaged. A common ground is needed because the control pulse must share the same reference.
  8. Question 4: From Table 4, does a bigger queue fix a stalled main loop? Which policy suits a controller and which suits a data logger?No. A bigger queue reduces overflow, but the delivered data is still 75 ms old and more items pile up; the fix is a faster main loop. A controller should use the latest value with a maximum age, while a logger uses a queue and records the overflow count.

Discussion questions

  • When reading very short signals, such as pulses from a motor rpm sensor, why is polling riskier than an interrupt?
  • If an ISR passes two fields (tick number and time) to the main loop, why is volatile alone not enough, and how is it fixed?

Adapting to student background

Upper secondary (M.6)
Have them calculate PSC, ARR and duty by hand before coding, then sketch the expected waveform to compare with the capture; have the instructor check the servo power wiring before power-up.
Vocational certificate
Start by wiring the button and servo to see results first, then use a fill-in table (clock divided by 1,000,000 minus 1 gives PSC) and check with Example 1's code instead of doing all the arithmetic by hand.
Diploma
Extension: write a program that sweeps the pulse slowly from 1100 to 1900 µs in 10 µs steps, clamps it to that range, and measure whether each step is visible on the instrument.

Common student mistakes: Common mistakes in the module 3 lesson

4Worksheet 4 Connecting a sensor and sending serial data
Lab · About 6 h of class time · CLO3

Objective: Read a sensor over I2C, analyse bus signals, send checksummed frames over UART and identify DroneCAN device settings

Equipment

  • Pico 2 board
  • I2C sensor such as the training board's barometer or IMU
  • Logic analyzer
  • USB-UART adapter
  • Computer with Python
  • ArduPilot DroneCAN documentation

Safety

  • Low-voltage bench work; check the sensor's logic level matches 3.3 V before connecting
  • Share ground between the board and the USB-UART adapter

Steps

  1. Connect the I2C sensor, scan the bus for addresses and read values
  2. Capture SDA and SCL; identify start, address, ACK and data
  3. Send Example 2 frames over UART to the computer
  4. Write a receiver that checks the checksum
  5. Set a wrong baud rate on one side; observe and explain
  6. Study ArduPilot's DroneCAN page and list the parameters for a DroneCAN GPS

Deliverables

  • Sensor address and readings
  • Annotated I2C capture
  • Sender and receiver code with checksum results
  • Wrong-baud explanation and DroneCAN parameter list

Checklist

  • Table 1 gives the I2C address in hex matching the sensor datasheet, and readings have units (Correct programs and peripheral configuration)
  • The SDA and SCL capture is attached with start, address, ACK and data all marked (Measurement and verification with instruments)
  • The receiver checks the start byte, length and checksum, with results for both a good and a damaged frame (Correct programs and peripheral configuration)
  • Table 3 includes the wrong-baud case with an explanation of the cause (Recording results and explaining system behaviour)
  • A list of the DroneCAN parameters needed for a GPS is given, with values and the documentation page cited (Recording results and explaining system behaviour)

Instructor guide

Class timing 360 min

  1. Objectives; check the sensor logic level and common ground30 min
  2. Connect the I2C sensor, scan the bus and read values75 min
  3. Capture SDA and SCL with the logic analyzer and label each part60 min
  4. Send frames over UART, write the checksum receiver and try a wrong baud rate105 min
  5. Study ArduPilot's DroneCAN page and list the parameters45 min
  6. Wrap-up, questions and hand-in checklist45 min

Expected results

  1. Record: Table 1 I2C bus scan and sensor readingsTable 1: the 7-bit address must match the datasheet of the training board's sensor (Figure 2 of the lesson gives 0x68, 0x76 and 0x1E as examples). If nothing is found, check the pull-ups, swapped SDA and SCL, and power. Readings must be plausible, e.g. a barometer gives room air pressure and an IMU at rest measures about 9.8 m/s² on the vertical axis.
  2. Record: Table 2 Parts of the captured I2C signalTable 2: start (SDA falls while SCL is high), the address byte with the read or write bit, ACK (SDA low on the 9th clock), data bytes, and stop. Reading 6 bytes takes about 830 µs at 100 kHz or 208 µs at 400 kHz by Example 1's estimate; accept measured times within about ±30%, because the estimate counts bits roughly and there are gaps between bytes.
  3. Record: Table 3 UART frames sent and checksum resultsTable 3: the good frame aa 04 09 c4 01 2c e4 (7 bytes, values 2500 and 300) passes the checksum; a frame with one flipped bit (4th byte becomes d4) fails; mismatched baud (e.g. sending at 115200, receiving at 57600) gives garbled or missing bytes or framing errors, and nearly every frame fails the checksum.
  4. Question 1: How many bytes is the Example 2 frame, how long does one frame take at your baud rate in µs, and what share of the link does it use if sent every 100 ms?7 bytes; 8N1 uses 10 bits per byte, so at 115200 baud a frame takes about 608 µs (about 1215 µs at 57600, 304 µs at 230400). Every 100 ms is 70 bytes per second, 0.61% of the 11,520 bytes per second at 115200 baud (1.22% at 57600), leaving plenty of room for other data.
  5. Question 2: With mismatched baud rates, what did the received data look like, and why does the checksum let the receiver know the data is unusable?The receiver samples at the wrong moments because the bit lengths differ (by a factor of two for 115200 against 57600), so the bytes are meaningless. The checksum computed from them does not match the checksum byte, so the receiver discards the frame instead of using wrong numbers. A strong answer adds that the checksum does not tell you the cause; you still have to check the baud.
  6. Question 3: Does a passing XOR checksum always mean the data is correct and fit to control with? Give a case where the checksum passes but the data should not be used.Not always. XOR misses some damage, such as the same bit flipping in two bytes, which is why real protocols use CRCs. Even when it passes, the data may be too old after waiting in a buffer (lesson Example 3: age 30,296 µs is over the 20,000 µs limit, so it is discarded), or the field may be read with the wrong type, e.g. 0xFF9C is −100 signed but 65,436 unsigned.
  7. Question 4: From ArduPilot's DroneCAN page, why do larger drones put the GPS, ESCs and power module on a CAN bus instead of separate UART wires to each?CAN uses a differential CANH and CANL pair, so it resists noise and supports long runs; every device shares one pair with terminating resistors at both ends, which cuts wiring, and DroneCAN devices report their own status. A good parameter list enables a CAN driver on the port, sets that driver's protocol to DroneCAN, sets the bit rate (CAN_P1_BITRATE, default 1,000,000) and sets the GPS type to DroneCAN, with names checked against the documentation for the firmware version used.

Discussion questions

  • For an IMU read thousands of times a second and a compass read occasionally, would you use SPI or I2C for each, and why?
  • UART data can arrive as half a frame or several frames together. How must the receiver be designed so it does not cut frames wrongly?
  • What happens if two I2C devices on one bus have the same address, and how could it be solved?

Adapting to student background

Upper secondary (M.6)
Have them convert one frame's bytes to binary and compute the XOR by hand before writing the receiver, and explain the captured waveform to a peer before filling in the table; give extra practice wiring and using the logic analyzer.
Vocational certificate
Start by wiring and seeing data flow in the serial terminal, then use one capture the instructor has labelled as a model; start the receiver from Example 2's code and adapt it.
Diploma
Extension: add a sequence number to the frame and make the receiver count lost frames as in Example 3, testing it by deliberately skipping some frames on the sender.

Common student mistakes: Common mistakes in the module 4 lesson

5Worksheet 5 Tasks on FreeRTOS
Lab · About 6 h of class time · CLO2, CLO1

Objective: Build a multi-task RTOS system, assign rate-monotonic priorities, compare measured timing with calculation and test the watchdog

Equipment

  • Pico 2 with an SDK supporting FreeRTOS
  • Logic analyzer
  • LED and the sensor from worksheet 4
  • Computer with Python and the module 5 example code

Safety

  • Low-voltage bench work; no flying

Steps

  1. Create a FreeRTOS project with three tasks: sensor every 10 ms, frame every 100 ms, LED every 500 ms
  2. Assign rate-monotonic priorities
  3. Measure each task's real timing by toggling GPIO pins with a logic analyzer
  4. Add a simulated heavy load in a low-priority task; check the sensor task stays on time
  5. Enter measured values into Example 1 and compare calculation with measurement
  6. Enable the watchdog, simulate a hung task and observe the reset

Deliverables

  • FreeRTOS project code
  • Task timing captures before and after the load
  • Calculation against measurement table
  • Watchdog test record

Checklist

  • Table 1 has all 3 tasks and the load task, every value in ms (Measurement and verification with instruments)
  • Logic analyzer timing captures before and after the load are attached (Measurement and verification with instruments)
  • Priorities follow rate-monotonic order (shorter period, higher priority) and are stated in the code (Correct programs and peripheral configuration)
  • Tasks use RTOS delays, not busy-waiting, except the simulated load task (Code quality against embedded standards)
  • Box 3 states the watchdog timeout, how the task was hung and the evidence of the reset (Recording results and explaining system behaviour)

Instructor guide

Class timing 360 min

  1. Review tasks, priority, preemption and rate-monotonic order; brief the task30 min
  2. Build the three-task FreeRTOS project and set priorities90 min
  3. Measure real timing by toggling GPIO pins with the logic analyzer75 min
  4. Add the simulated load, measure again and enter values into Example 175 min
  5. Test the watchdog45 min
  6. Wrap-up, questions and hand-in checklist45 min

Expected results

  1. Record: Table 1 Measured timing of each task from the logic analyzerTable 1: measured periods should match 10, 100 and 500 ms within about one RTOS tick. Run times C depend on the group's code; values such as sensor 1.0 ms, frame 2.0 ms and LED 0.1 ms are reasonable. After the low-priority load is added, the sensor and frame tasks must stay on period, while the load task itself runs slower or gets less time.
  2. Record: Table 2 Example 1 calculation against measurementTable 2 (if measured C = 1.0, 2.0 and 0.1 ms): U = 1.0/10 + 2.0/100 + 0.1/500 = 0.1202, bound for 3 tasks 0.780, simulated missed = 0; adding a load of 300 ms every 1 s gives U = 0.4202, bound for 4 tasks 0.757, missed = 0; even a load of 870 ms per 1 s (U = 0.9902) misses nothing in the simulation. The board should agree: the sensor task never misses its period.
  3. Record: Box 3 Watchdog test record (timeout set, how the task was hung, how the reset showed)Box 3: when one task hangs (for example an endless loop that never feeds the watchdog), the system resets after the watchdog timeout. Evidence: the LED restarts its power-on pattern or the start-up message appears again on serial. The time before the reset should be close to the timeout set.
  4. Question 1: From Table 2, what is your task set's U, is it below the Liu and Layland bound, and do the board measurements agree with the calculation?With the values above U is about 0.12, far below the 0.780 bound, so every task is guaranteed to meet its deadline, and the board should show no missed periods. If results differ, a strong answer finds the cause, such as C measured without interrupt time, or an RTOS tick coarser than the period needed.
  5. Question 2: When the heavy load was added in a low-priority task, why did the sensor task stay on time? What would happen if the load had a higher priority than the sensor task?A preemptive scheduler lets a higher-priority task interrupt a lower one at once, so the load only gets leftover time. If the load had higher priority than the sensor task, the sensor task would wait until the load finished or blocked and would miss its 10 ms period, which in a flight controller means control degrades immediately.
  6. Question 3: If U exceeds the n(2^(1/n) − 1) bound but not 1, can you conclude the system will miss deadlines? Explain with the lesson's Example 1.No. The bound is only a sufficient condition. In Example 1, adding AI at 6 ms every 20 ms gives U = 0.95, above the 0.743 bound, yet the simulation misses nothing because the periods divide into each other almost exactly; it needs a closer check by simulation or measurement. If U exceeds 1 (AI at 8 ms gives U = 1.05), deadlines are certainly missed.
  7. Question 4: How does a watchdog help a drone in flight, and why must a hung task be unable to feed the watchdog?A watchdog resets the system when the program hangs and fails to check in on time, so the controller recovers instead of staying frozen in flight. If a hung task could still feed it (for example from a timer interrupt that keeps running), the watchdog would never notice, so it should be fed only when every important task has reported it completed its work.

Discussion questions

  • A flight controller must read the IMU and write logs at the same time. How should their priorities be set, and what happens to the flight if logging stalls?
  • Why should image object detection not run on the same MCU as control, even with TinyML?

Adapting to student background

Upper secondary (M.6)
Have them compute U and the bound by hand before running Example 1 and predict the measurements; pair them with a peer confident with the logic analyzer and flashing the board.
Vocational certificate
Start from an instructor-prepared one-task FreeRTOS project and add one task at a time, viewing the logic analyzer after each; use a fill-in table of C divided by T for each task, then add them up.
Diploma
Extension: raise the load step by step until the lowest-priority task starts missing its period, record U at that point, and compare it with Example 1's simulation.

Common student mistakes: Common mistakes in the module 5 lesson

Scoring rubric

For worksheets and the mini-project. Each criterion scores level (1–4) ÷ 4 × weight.

CriterionWeightExcellent (4)Good (3)Fair (2)Needs work (1)
Correct programs and peripheral configuration30%Programs work in every case; ADC, timer and baud settings correct; types and volatile used properlyNearly all correct with minor flawsPartly working or some settings wrongDoes not work
Measurement and verification with instruments25%Pulses, bus traffic and task timing confirmed with scope or analyzer and fully compared with calculationsAll measured, partly comparedIncomplete or misread measurementsNo measurement evidence
Code quality against embedded standards20%Readable, meets the chosen BARR-C rules, no heavy work in interruptsReadable with minor rule breachesHard to read or several breachesUnstructured
Recording results and explaining system behaviour25%Complete report explaining effects such as bounce, wrong baud and task contention correctlyComplete, mostly explainedParts missing or explanations off targetNo explanation

Assessment map: CLOs and how they are assessed Draft

The CLOs are a web-team draft; the course owner sets the final ones (curriculum book, part 4). This table is built from the worksheet and module-quiz data, so it follows any change to the CLOs.

CLOWorksheetsModule quizzes
CLO1 Explain microcontroller and embedded architectureW 1W 2W 5M1M2M5
CLO2 Program GPIO, timers and interruptsW 2W 3W 5M2M3M5
CLO3 Interface devices via UART, I2C, SPI and CANW 4M4