Namespaces | |
| namespace | anonymous_namespace{adc_task_function.cpp} |
| namespace | anonymous_namespace{convert.cpp} |
| namespace | anonymous_namespace{init.cpp} |
Classes | |
| struct | VccVoltagesQueue |
| struct | SupplyVoltagesQueue |
| struct | CurrentsQueue |
| struct | FilteredCurrentQueue |
| struct | TemperatureQueue |
Typedefs | |
| using | VccVoltageMeasurement |
| using | VccVoltage |
| using | SupplyVoltageMeasurement |
| using | SupplyVoltage |
| using | CurrentMeasurement |
| using | Current |
| using | FilteredCurrent = ztl::moving_average<int32_t, smath::pow(2, 12)> |
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 | vcc_voltage_channel {ADC_CHANNEL_0} |
| constexpr auto | supply_voltage_channel {ADC_CHANNEL_2} |
| constexpr auto | current_channel {ADC_CHANNEL_9} |
| constexpr auto | attenuation {ADC_ATTEN_DB_0} |
| constexpr std::array | channels |
| constexpr auto | sample_freq_hz {SOC_ADC_SAMPLE_FREQ_THRES_HIGH} |
| Sample frequency [Hz] (sample takes 12us). | |
| constexpr auto | conversion_frame_samples {84uz} |
| Number of samples per frame (84 * 12us = 1008us). | |
| constexpr auto | conversion_frame_samples_per_channel |
| Number of samples per frame and channel. | |
| constexpr auto | conversion_frame_time |
| Time per frame [us]. | |
| constexpr auto | conversion_frame_size |
| Bytes per conversion frame. | |
| struct drv::anlg::VccVoltagesQueue | vcc_voltages_queue |
| struct drv::anlg::SupplyVoltagesQueue | supply_voltages_queue |
| struct drv::anlg::CurrentsQueue | currents_queue |
| struct drv::anlg::FilteredCurrentQueue | filtered_current_queue |
| struct drv::anlg::TemperatureQueue | temperature_queue |
| std::atomic< uint8_t > | nvs_short_circuit_time |
| Cached current short circuit time from NVS. | |
| uint8_t | short_circuit_time {} |
| Short circuit time. | |
| adc_cali_handle_t | cali_handle {} |
| adc_continuous_handle_t | adc1_handle {} |
| temperature_sensor_handle_t | temp_sensor {} |
| using drv::anlg::Current |
| using drv::anlg::FilteredCurrent = ztl::moving_average<int32_t, smath::pow(2, 12)> |
| using drv::anlg::SupplyVoltage |
| using drv::anlg::VccVoltage |
| void drv::anlg::adc_task_function | ( | void * | ) |
Once started, the ADC task runs continuously. It measures voltages and currents at a frequency of 83333Hz. A total of 84 samples are recorded within one conversion frame meaning one frame lasts approximately 1ms. All measurements are written to the corresponding VCC voltages, supply voltages, currents and filtered current 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::anlg::adc_task_notify_resume | ( | ) |
| void drv::anlg::adc_task_notify_suspend | ( | ) |
| void drv::anlg::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::anlg::init | ( | ) |
Initialization takes place in init(). This function performs the following operations:
| CurrentMeasurement drv::anlg::mA2measurement | ( | Current | mA | ) |
| mA | Current in [mA] |
| Current drv::anlg::measurement2mA | ( | CurrentMeasurement | meas | ) |
| SupplyVoltage drv::anlg::measurement2mV | ( | SupplyVoltageMeasurement | meas | ) |
| meas | Supply voltage measurement |
| VccVoltage drv::anlg::measurement2mV | ( | VccVoltageMeasurement | meas | ) |
| meas | Vcc voltage measurement |
| SupplyVoltageMeasurement drv::anlg::mV2measurement | ( | SupplyVoltage | mV | ) |
| mV | Supply voltage in [mV] |
| VccVoltageMeasurement drv::anlg::mV2measurement | ( | VccVoltage | mV | ) |
| mV | Vcc voltage in [mV] |
|
inline |
|
inline |
| void drv::anlg::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 temperature queue.
|
inline |
|
inlineconstexpr |
|
inline |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
| struct drv::anlg::CurrentsQueue drv::anlg::currents_queue |
| struct drv::anlg::FilteredCurrentQueue drv::anlg::filtered_current_queue |
|
inlineconstexpr |
| std::atomic< uint8_t > drv::anlg::nvs_short_circuit_time |
Ugly necessity because adc_task_function can't update directly from NVS due to timing constraints. Instead this value get's updated inside temp_task_function.
|
inlineconstexpr |
|
inlineconstexpr |
| uint8_t drv::anlg::short_circuit_time {} |
|
inlineconstexpr |
| struct drv::anlg::SupplyVoltagesQueue drv::anlg::supply_voltages_queue |
|
inline |
| struct drv::anlg::TemperatureQueue drv::anlg::temperature_queue |
|
inlineconstexpr |
| struct drv::anlg::VccVoltagesQueue drv::anlg::vcc_voltages_queue |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |