This module takes over all analog functions of the firmware. This includes measuring track voltage and current, measuring temperature, and monitoring all of those measurements.
Initialization takes place in init(). This function performs the following operations:
Once started, the ADC task runs continuously. It measures voltages and currents at a frequency of 8kHz. A total of 160 samples are recorded within one conversion frame meaning one frame lasts exactly 20ms. All measurements are written to the corresponding voltages or currents queue.
If the measured currents indicate a short circuit, the bug LED is switched on, state is set to short circuit and a ROCO track short circuit message is broadcast.
Since the ADC task holds a mutex on the continuous mode driver, the only way to stop and start the ADC is to send a task notification. This is done using adc_task_notify_suspend() or adc_task_notify_resume(). The conversion frame then starts again from the beginning and this method can be used to synchronize the ADC.
Once started, the temperature task runs continuously. The internal temperature sensor is read once per second and the result is converted into degrees Celsius. The result is written to the corresponding queue.
The convert.hpp header provides some conversion functions to convert between raw ADC values and Si units. The following functions are defined: