Firmware  0.8.0
Loading...
Searching...
No Matches
drv::anlg Namespace Reference

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)>

Functions

 TASK (adc_task, "drv::anlg::adc", 3072uz, ESP_TASK_PRIO_MAX - 2u, APP_CPU_NUM, 100u)
 TASK (temp_task, "drv::anlg::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.
VccVoltage measurement2mV (VccVoltageMeasurement meas)
 Convert VccVoltageMeasurement to VccVoltage.
VccVoltageMeasurement mV2measurement (VccVoltage mV)
 Convert VccVoltage to VccVoltageMeasurement.
SupplyVoltage measurement2mV (SupplyVoltageMeasurement meas)
 Convert SupplyVoltageMeasurement to SupplyVoltage.
SupplyVoltageMeasurement mV2measurement (SupplyVoltage mV)
 Convert SupplyVoltage to SupplyVoltageMeasurement.
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 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 {}

Typedef Documentation

◆ Current

Initial value:
ztl::implicit_wrapper<CurrentMeasurement::value_type, struct CurrentTag>

◆ CurrentMeasurement

Initial value:
ztl::implicit_wrapper<ztl::smallest_signed_t<0, max_measurement>,
struct CurrentMeasurementTag>

◆ FilteredCurrent

using drv::anlg::FilteredCurrent = ztl::moving_average<int32_t, smath::pow(2, 12)>

◆ SupplyVoltage

Initial value:
ztl::implicit_wrapper<SupplyVoltageMeasurement::value_type,
struct SupplyVoltageTag>

◆ SupplyVoltageMeasurement

Initial value:
ztl::implicit_wrapper<ztl::smallest_signed_t<0, max_measurement>,
struct SupplyVoltageMeasurementTag>

◆ VccVoltage

Initial value:
ztl::implicit_wrapper<VccVoltageMeasurement::value_type,
struct VccVoltageTag>

◆ VccVoltageMeasurement

Initial value:
ztl::implicit_wrapper<ztl::smallest_signed_t<0, max_measurement>,
struct VccVoltageMeasurementTag>

Function Documentation

◆ adc_task_function()

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.

◆ adc_task_notify_resume()

void drv::anlg::adc_task_notify_resume ( )

◆ adc_task_notify_suspend()

void drv::anlg::adc_task_notify_suspend ( )

◆ handle_suspend_resume_on_notify()

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.

◆ init()

esp_err_t drv::anlg::init ( )

Initialization takes place in init(). This function performs the following operations:

◆ mA2measurement()

CurrentMeasurement drv::anlg::mA2measurement ( Current mA)
Parameters
mACurrent in [mA]
Returns
CurrentMeasurement

◆ measurement2mA()

Current drv::anlg::measurement2mA ( CurrentMeasurement meas)
Parameters
measCurrent measurement
Returns
Current

◆ measurement2mV() [1/2]

SupplyVoltage drv::anlg::measurement2mV ( SupplyVoltageMeasurement meas)
Parameters
measSupply voltage measurement
Returns
SupplyVoltage

◆ measurement2mV() [2/2]

VccVoltage drv::anlg::measurement2mV ( VccVoltageMeasurement meas)
Parameters
measVcc voltage measurement
Returns
VccVoltage

◆ mV2measurement() [1/2]

SupplyVoltageMeasurement drv::anlg::mV2measurement ( SupplyVoltage mV)
Parameters
mVSupply voltage in [mV]
Returns
SupplyVoltageMeasurement

◆ mV2measurement() [2/2]

VccVoltageMeasurement drv::anlg::mV2measurement ( VccVoltage mV)
Parameters
mVVcc voltage in [mV]
Returns
VccVoltageMeasurement

◆ TASK() [1/2]

drv::anlg::TASK ( adc_task ,
"drv::anlg::adc" ,
3072uz ,
ESP_TASK_PRIO_MAX - 2u,
APP_CPU_NUM ,
100u  )
inline

◆ TASK() [2/2]

drv::anlg::TASK ( temp_task ,
"drv::anlg::temp" ,
2048uz ,
tskIDLE_PRIORITY ,
APP_CPU_NUM ,
0u  )
inline

◆ temp_task_function()

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.

Variable Documentation

◆ adc1_handle

adc_continuous_handle_t drv::anlg::adc1_handle {}
inline

◆ attenuation

auto drv::anlg::attenuation {ADC_ATTEN_DB_0}
inlineconstexpr

◆ cali_handle

adc_cali_handle_t drv::anlg::cali_handle {}
inline

◆ channels

std::array drv::anlg::channels
inlineconstexpr
Initial value:
{
constexpr auto current_channel
Definition config.hpp:208
constexpr auto supply_voltage_channel
Definition config.hpp:207
constexpr auto vcc_voltage_channel
Definition config.hpp:206

◆ conversion_frame_samples

auto drv::anlg::conversion_frame_samples {84uz}
inlineconstexpr

◆ conversion_frame_samples_per_channel

auto drv::anlg::conversion_frame_samples_per_channel
inlineconstexpr
Initial value:
{
constexpr std::array channels
Definition config.hpp:210
constexpr auto conversion_frame_samples
Number of samples per frame (84 * 12us = 1008us).
Definition config.hpp:218

◆ conversion_frame_size

auto drv::anlg::conversion_frame_size
inlineconstexpr
Initial value:
SOC_ADC_DIGI_DATA_BYTES_PER_CONV}

◆ conversion_frame_time

auto drv::anlg::conversion_frame_time
inlineconstexpr
Initial value:
{
constexpr auto sample_freq_hz
Sample frequency [Hz] (sample takes 12us).
Definition config.hpp:214

◆ current_channel

auto drv::anlg::current_channel {ADC_CHANNEL_9}
inlineconstexpr

◆ current_k

auto drv::anlg::current_k {800}
inlineconstexpr

◆ current_r

auto drv::anlg::current_r {180}
inlineconstexpr

◆ currents_queue

struct drv::anlg::CurrentsQueue drv::anlg::currents_queue

◆ filtered_current_queue

struct drv::anlg::FilteredCurrentQueue drv::anlg::filtered_current_queue

◆ max_measurement

auto drv::anlg::max_measurement
inlineconstexpr
Initial value:
{smath::pow(2, SOC_ADC_DIGI_MAX_BITWIDTH) -
1}

◆ nvs_short_circuit_time

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.

◆ ol_on_gpio_num

auto drv::anlg::ol_on_gpio_num {GPIO_NUM_17}
inlineconstexpr

◆ sample_freq_hz

auto drv::anlg::sample_freq_hz {SOC_ADC_SAMPLE_FREQ_THRES_HIGH}
inlineconstexpr

◆ short_circuit_time

uint8_t drv::anlg::short_circuit_time {}

◆ supply_voltage_channel

auto drv::anlg::supply_voltage_channel {ADC_CHANNEL_2}
inlineconstexpr

◆ supply_voltages_queue

struct drv::anlg::SupplyVoltagesQueue drv::anlg::supply_voltages_queue

◆ temp_sensor

temperature_sensor_handle_t drv::anlg::temp_sensor {}
inline

◆ temperature_queue

struct drv::anlg::TemperatureQueue drv::anlg::temperature_queue

◆ vcc_voltage_channel

auto drv::anlg::vcc_voltage_channel {ADC_CHANNEL_0}
inlineconstexpr

◆ vcc_voltages_queue

struct drv::anlg::VccVoltagesQueue drv::anlg::vcc_voltages_queue

◆ voltage_lower_r

auto drv::anlg::voltage_lower_r {470}
inlineconstexpr

◆ voltage_upper_r

auto drv::anlg::voltage_upper_r {14300}
inlineconstexpr

◆ vref

auto drv::anlg::vref {1000}
inlineconstexpr