Firmware  0.0.0
Loading...
Searching...
No Matches
analog Namespace Reference

Namespaces

namespace  anonymous_namespace{adc_task_function.cpp}
 
namespace  anonymous_namespace{convert.cpp}
 
namespace  anonymous_namespace{init.cpp}
 

Classes

struct  AdcTask
 
struct  CurrentsQueue
 
struct  TemperatureQueue
 
struct  TempTask
 
struct  VoltagesQueue
 

Typedefs

using VoltageMeasurement
 
using Voltage
 
using CurrentMeasurement
 
using Current
 

Functions

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 (BaseType_t xCoreID)
 Initialize analog.
 
void temp_task_function (void *)
 Temperature task function.
 

Variables

adc_cali_handle_t cali_handle {}
 
adc_continuous_handle_t adc1_handle {}
 
temperature_sensor_handle_t temp_sensor {}
 
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 {8'000u}
 Sample frequency [Hz] (sample takes 125µs, conversion frame 20ms)
 
constexpr auto conversion_frame_samples {160uz}
 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 analog::AdcTask adc_task
 
struct analog::TempTask temp_task
 
struct analog::VoltagesQueue voltages_queue
 
struct analog::CurrentsQueue currents_queue
 
struct analog::TemperatureQueue temperature_queue
 

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>

◆ Voltage

Initial value:
ztl::implicit_wrapper<VoltageMeasurement::value_type, struct VoltageTag>

◆ VoltageMeasurement

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

Function Documentation

◆ adc_task_function()

void 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, state is set to short circuit and a Z21 track short circuit message is broadcast.

◆ init()

esp_err_t analog::init ( BaseType_t xCoreID)

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

  • Creates queues for raw voltage and current vales as well as temperatures in Si units
  • Initializes the ADC in continuous mode and applies a curve fitting calibration
  • Initializes the internal temperature sensor
  • Creates an ADC and temperature task

◆ mA2measurement()

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

◆ measurement2mA()

Current analog::measurement2mA ( CurrentMeasurement meas)
Parameters
measCurrent measurement
Returns
Current

◆ measurement2mV()

Voltage analog::measurement2mV ( VoltageMeasurement meas)
Parameters
measVoltage measurement
Returns
Voltage

◆ mV2measurement()

VoltageMeasurement analog::mV2measurement ( Voltage mV)
Parameters
mVVoltage in [mV]
Returns
VoltageMeasurement

◆ temp_task_function()

void 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.

Variable Documentation

◆ adc1_handle

adc_continuous_handle_t analog::adc1_handle {}
inline

◆ adc_task

struct analog::AdcTask analog::adc_task

◆ attenuation

auto analog::attenuation {ADC_ATTEN_DB_0}
inlineconstexpr

◆ cali_handle

adc_cali_handle_t analog::cali_handle {}
inline

◆ channels

std::array analog::channels {current_channel, voltage_channel}
inlineconstexpr

◆ conversion_frame_samples

auto analog::conversion_frame_samples {160uz}
inlineconstexpr

◆ conversion_frame_samples_per_channel

auto analog::conversion_frame_samples_per_channel
inlineconstexpr
Initial value:
{
conversion_frame_samples / size(channels)}
constexpr auto conversion_frame_samples
Number of samples per frame.
Definition config.hpp:199

◆ conversion_frame_size

auto analog::conversion_frame_size
inlineconstexpr
Initial value:
SOC_ADC_DIGI_DATA_BYTES_PER_CONV}

◆ conversion_frame_time

auto analog::conversion_frame_time
inlineconstexpr
Initial value:
sample_freq_hz}

◆ current_channel

auto analog::current_channel {ADC_CHANNEL_9}
inlineconstexpr

◆ current_k

auto analog::current_k {800}
inlineconstexpr

◆ current_r

auto analog::current_r {180}
inlineconstexpr

◆ currents_queue

struct analog::CurrentsQueue analog::currents_queue

◆ max_measurement

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

◆ ol_on_gpio_num

auto analog::ol_on_gpio_num {GPIO_NUM_17}
inlineconstexpr

◆ sample_freq_hz

auto analog::sample_freq_hz {8'000u}
inlineconstexpr

This frequency was chosen explicitly to avoid any beats with the DCC signal (~58/100µs).

◆ temp_sensor

temperature_sensor_handle_t analog::temp_sensor {}
inline

◆ temp_task

struct analog::TempTask analog::temp_task

◆ temperature_queue

struct analog::TemperatureQueue analog::temperature_queue

◆ voltage_channel

auto analog::voltage_channel {ADC_CHANNEL_2}
inlineconstexpr

◆ voltage_lower_r

auto analog::voltage_lower_r {470}
inlineconstexpr

◆ voltage_upper_r

auto analog::voltage_upper_r {14300}
inlineconstexpr

◆ voltages_queue

struct analog::VoltagesQueue analog::voltages_queue

◆ vref

auto analog::vref {1000}
inlineconstexpr