Namespaces | |
namespace | anonymous_namespace{adc_task_function.cpp} |
namespace | anonymous_namespace{convert.cpp} |
namespace | anonymous_namespace{init.cpp} |
Classes | |
struct | CurrentsQueue |
struct | TemperatureQueue |
struct | VoltagesQueue |
Typedefs | |
using | VoltageMeasurement |
using | Voltage |
using | CurrentMeasurement |
using | Current |
Functions | |
TASK (adc_task, "drv::analog::adc", 4096uz, ESP_TASK_PRIO_MAX - 2u, APP_CPU_NUM, 200u) | |
TASK (temp_task, "drv::analog::temp", 2048uz, tskIDLE_PRIORITY, APP_CPU_NUM, 0u) | |
void | handle_suspend_resume_on_notify () |
Handles suspend/resume logic. | |
void | adc_task_notify_suspend () |
Suspend ADC task with task notification. | |
void | adc_task_notify_resume () |
Resume ADC task with task notification. | |
void | adc_task_function (void *) |
ADC task function. | |
Voltage | measurement2mV (VoltageMeasurement meas) |
Convert VoltageMeasurement to Voltage. | |
VoltageMeasurement | mV2measurement (Voltage mV) |
Convert Voltage to VoltageMeasurement. | |
Current | measurement2mA (CurrentMeasurement meas) |
Convert CurrentMeasurement to Current. | |
CurrentMeasurement | mA2measurement (Current mA) |
Convert Current to CurrentMeasurement. | |
esp_err_t | init () |
Initialize analog. | |
void | temp_task_function (void *) |
Temperature task function. |
Variables | |
constexpr auto | ol_on_gpio_num {GPIO_NUM_17} |
constexpr auto | voltage_upper_r {14300} |
Voltage divider upper resistor for voltage measurement. | |
constexpr auto | voltage_lower_r {470} |
Voltage divider lower resistor for voltage measurement. | |
constexpr auto | current_r {180} |
Current sense resistor. | |
constexpr auto | current_k {800} |
Current sense ratio. | |
constexpr auto | vref {1000} |
constexpr auto | max_measurement |
constexpr auto | voltage_channel {ADC_CHANNEL_2} |
constexpr auto | current_channel {ADC_CHANNEL_9} |
constexpr auto | attenuation {ADC_ATTEN_DB_0} |
constexpr std::array | channels {current_channel, voltage_channel} |
constexpr auto | sample_freq_hz {80'000u} |
Sample frequency [Hz] (sample takes 12.5us, conversion frame 20ms) | |
constexpr auto | conversion_frame_samples {1600uz} |
Number of samples per frame. | |
constexpr auto | conversion_frame_time |
Time per frame [ms]. | |
constexpr auto | conversion_frame_size |
constexpr auto | conversion_frame_samples_per_channel |
struct drv::analog::VoltagesQueue | voltages_queue |
struct drv::analog::CurrentsQueue | currents_queue |
struct drv::analog::TemperatureQueue | temperature_queue |
adc_cali_handle_t | cali_handle {} |
adc_continuous_handle_t | adc1_handle {} |
temperature_sensor_handle_t | temp_sensor {} |
using drv::analog::Current |
using drv::analog::Voltage |
void drv::analog::adc_task_function | ( | void * | ) |
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.
void drv::analog::adc_task_notify_resume | ( | ) |
void drv::analog::adc_task_notify_suspend | ( | ) |
void drv::analog::handle_suspend_resume_on_notify | ( | ) |
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.
esp_err_t drv::analog::init | ( | ) |
Initialization takes place in init(). This function performs the following operations:
CurrentMeasurement drv::analog::mA2measurement | ( | Current | mA | ) |
mA | Current in [mA] |
Current drv::analog::measurement2mA | ( | CurrentMeasurement | meas | ) |
Voltage drv::analog::measurement2mV | ( | VoltageMeasurement | meas | ) |
VoltageMeasurement drv::analog::mV2measurement | ( | Voltage | mV | ) |
mV | Voltage in [mV] |
|
inline |
|
inline |
void drv::analog::temp_task_function | ( | void * | ) |
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.
|
inline |
|
inlineconstexpr |
|
inline |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
struct drv::analog::CurrentsQueue drv::analog::currents_queue |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
This frequency was chosen explicitly to avoid any beats with the DCC signal (~58/100us).
|
inline |
struct drv::analog::TemperatureQueue drv::analog::temperature_queue |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
struct drv::analog::VoltagesQueue drv::analog::voltages_queue |
|
inlineconstexpr |