TIDUFK2 September 2026
FreeRTOS separates protection-critical sample processing from calibration and wireless communication. The application uses the execution contexts listed in Table 3-1.
| Execution context | Priority | Period | Main responsibility |
|---|---|---|---|
| ADC interrupt | Hardware interrupt | 125µs | Read ADC sequence, evaluate window-comparator event, and buffer the sample pair |
| Protection task | 6 | 1ms | Process buffered samples, execute protection and Metrology calculations, control the relay, and service the watchdog |
| Optional calibration GUI task | 2 | 5ms | Service UART calibration commands during production or laboratory use |
| Zigbee task | 1 | Stack controlled | Synchronize Zigbee attributes, process commissioning requests, and execute ZBOSS |
The Protection task has the highest software priority and is activated periodically every 1ms using vTaskDelayUntil(). At an acquisition rate of 8kHz, approximately eight new current-and-voltage sample pairs are normally available during each task period. Temporary execution delays are absorbed by the 256-entry ring buffer, and all pending samples are processed in their original acquisition order.
At the beginning of every Protection-task execution, the current sample backlog and task start time are recorded for diagnostic purposes. The task then locks the shared Metrology data structure and drains the ring buffer. For each sample pair, the corrected ADC codes are converted into the fixed-point format expected by the Metrology library. The following operations are then executed:
After all pending samples have been processed, Breaker_service() handles pending local or Zigbee control commands and updates the relay-driver state machine. Metrology foreground calculations are executed only when the background processing indicates that a new measurement frame or mains cycle is available. These calculations produce RMS values, power, energy, frequency, phase, and the other reported quantities.
The resulting measurement and breaker state are copied into a coherent application snapshot. The short snapshot update is protected against interrupts so that the Zigbee task cannot observe a partially updated breaker or measurement state. Zigbee reads only this published snapshot and therefore does not need to lock the internal Metrology working data.
An optional lower-priority task services the UART calibration interface every 5ms. This interface is intended only for controlled production calibration and laboratory debugging and is not required during normal breaker operation. UART processing is bounded to 64 received bytes per service call and is skipped when the sample backlog exceeds 32 pairs. Access to the shared Metrology data is protected by a FreeRTOS mutex with priority inheritance, ensuring that calibration activity cannot indefinitely block the Protection task.
Because the Protection task has a higher priority, it can preempt Zigbee processing whenever its periodic execution becomes ready. Consequently, protection processing does not have to wait for a complete ZBOSS operation before it can continue.
After completing the protection-critical processing, the task services the watchdog. The watchdog is fed only if at least one sample pair was processed, no sample loss was detected, and the remaining backlog does not exceed 96 sample pairs. A sustained violation of these conditions prevents the watchdog from being fed and causes a system reset after the configured 50ms watchdog period.
The execution time and start interval of the Protection task are continuously monitored. A diagnostic deadline counter is incremented if either value exceeds 5ms. This threshold does not control task scheduling directly but provides a measurable indication that the protection timing budget has been violated. Task stack usage, maximum backlog, processed-sample count, and individual processing times are also retained as debugger-visible diagnostic values.
The hardware window-comparator path remains independent of this task scheduling. It can latch an over current-related trip directly from the ADC interrupt. Regular instantaneous-current and overload protection are executed by the Protection task using the buffered, gain-corrected current samples.