Clockwork

FreeRTOS Periodic Task Exercise

Task

Run the given sample() every 100 ms from FreeRTOS, for as long as the board runs. Call n starts n x 100 ms after the scheduler starts.

Circuit

Block diagram: U2, a sensor, puts a 4-bit level on PA0 to PA3 of U1 STM32F4; inside U1 the FreeRTOS kernel ticks every 1 ms and your code calls sample() every 100 ms, which reads the level, takes 5 to 35 ms and prints on USART1 TX, PA9, to a terminal

Pass condition

Each line sample() prints shows the tick its call started on, with the level read at that tick: t=100, t=200, t=300 and on.

Expected output for the ten readings case: the bench sets the level on PA0 to PA3 to 3, 9, 2, 15, 0, 6 and 1 between calls, sample() starts every 100 ms from 100 ms to 1000 ms however long each call takes, and the terminal shows ten lines, t=100 level=3 to t=1000 level=1

Notes

The level on PA0 to PA3 changes while your program runs. sample() takes 5 to 35 ms. Other tasks need the processor between calls. FreeRTOS V11.1.0 ticks at 1 ms. Leave the given code as is.

Related challenges

Loading the interactive arena.