Data Acquisition
Data Acquisition (DAQ)
Measurements are taken using ADC with DMA. The DAC is used to generate reference voltages for bi-directional current measurement. Data is stored in structs, which are afterwards used by the control algorithms
All calculations assume a 16-bit ADC, even though the STM32 ADCs natively support 12-bit. Using 16-bit for calculation allows to increase resolution by oversampling. Left-aligned 12-bit ADC readings can be treated as 16-bit ADC readings.
Functions
-
static inline float adc_raw_to_voltage(int32_t raw, int32_t vref_mV)
Convert 16-bit raw ADC reading to voltage
- Parameters:
raw – 16-bit ADC reading
vref_mV – Reference voltage in millivolts
- Returns:
Voltage in volts
-
static inline int32_t adc_voltage_to_raw(float voltage, int32_t vref_mV)
Convert voltage to 16-bit raw ADC reading
- Parameters:
voltage – Voltage in volts
vref_mV – Reference voltage in millivolts
- Returns:
16-bit ADC reading
-
void calibrate_current_sensors(void)
Set offset vs. actual measured value, i.e. sets zero current point.
All input/output switches and consumers should be switched off before calling this function
-
void daq_update(void)
Updates structures with data read from ADC
-
void daq_setup(void)
Initializes ADC, DAC and DMA
-
void adc_update_value(unsigned int pos)
Read, filter and check raw ADC readings stored by DMA controller
-
void daq_set_lv_limits(float lv_overvoltage, float lv_undervoltage)
Set lv side (battery) voltage limits where an alert should be triggered
- Parameters:
lv_overvoltage – Upper voltage limit
lv_undervoltage – Lower voltage limit
-
void daq_set_hv_limit(float hv_overvoltage)
Set hv side (grid/solar) voltage limit where an alert should be triggered
- Parameters:
hv_overvoltage – Upper voltage limit
-
void adc_upper_alert_inhibit(int adc_pos, int timeout_ms)
Add an inhibit delay to the alerts to disable it temporarily
- Parameters:
adc_pos – The position of the ADC measurement channel
timeout_ms – Timeout in milliseconds
-
struct AdcAlert
- #include <daq.h>
Struct to define upper and lower limit alerts for any ADC channel