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 |
using analog::Current |
using analog::Voltage |
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.
esp_err_t analog::init | ( | BaseType_t | xCoreID | ) |
Initialization takes place in init(). This function performs the following operations:
CurrentMeasurement analog::mA2measurement | ( | Current | mA | ) |
mA | Current in [mA] |
Current analog::measurement2mA | ( | CurrentMeasurement | meas | ) |
meas | Current measurement |
Voltage analog::measurement2mV | ( | VoltageMeasurement | meas | ) |
meas | Voltage measurement |
VoltageMeasurement analog::mV2measurement | ( | Voltage | mV | ) |
mV | Voltage in [mV] |
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.
|
inline |
struct analog::AdcTask analog::adc_task |
|
inlineconstexpr |
|
inline |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
struct analog::CurrentsQueue analog::currents_queue |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
This frequency was chosen explicitly to avoid any beats with the DCC signal (~58/100µs).
|
inline |
struct analog::TempTask analog::temp_task |
struct analog::TemperatureQueue analog::temperature_queue |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
struct analog::VoltagesQueue analog::voltages_queue |
|
inlineconstexpr |