Header file for managing ADC sampling, compensation, and filtering for the supercapacitor control board. More...
#include <adc.h>#include <dma.h>#include <stdint.h>#include <arm_math.h>#include "supercap_def.h"#include "main.h"Go to the source code of this file.
Data Structures | |
| struct | mov_avrg_filter |
| Moving average filter structure. More... | |
| struct | LoopCtrl_PID |
| PID loop controller structure. More... | |
| class | adc_manager |
| Class to manage ADC hardware sampling and filtering. More... | |
Macros | |
| #define | ADC_RES 4095.0f |
| ADC maximum value (12-bit) | |
| #define | INV_VOLT_DIV 11.0f |
| Inverse of voltage divider ratio (used for voltage measurement scaling) | |
| #define | ADC_REF 3.3f |
| Reference voltage for ADC (V) | |
| #define | INA186A2_GAIN 50.0f |
| INA186A2 current amplifier gain (datasheet) | |
| #define | SHUNT_RESISTOR 0.004f |
| Value of current sensing shunt resistor (Ohms) | |
| #define | VCAP_GAIN ADC_REF * INV_VOLT_DIV / ADC_RES |
| Voltage measurement gain: V = (ADC / 4095) * 3.3 * 11. | |
| #define | VBAT_GAIN ADC_REF * INV_VOLT_DIV / ADC_RES |
| #define | IBAT_GAIN -(ADC_REF / SHUNT_RESISTOR / INA186A2_GAIN / ADC_RES) |
| Current measurement gain from each source, sign indicates direction. | |
| #define | ISOURCE_GAIN -(ADC_REF / SHUNT_RESISTOR / INA186A2_GAIN / ADC_RES) |
| #define | ICAP_GAIN -(ADC_REF / SHUNT_RESISTOR / INA186A2_GAIN / ADC_RES) |
| #define | ADC1_CHANNELS 2 |
| #define | ADC2_CHANNELS 3 |
| #define | ADC_FIRST_BUFFER 0 |
| #define | ADC_SECOND_BUFFER 1 |
| #define | ADC_BUFFER_DEPTH 16 |
| #define | GET_COMPENSATED_ADC(ADC_VAL, NAME) |
| Helper macro for applying gain + offset compensation on raw ADC readings. | |
Enumerations | |
| enum | adc_names { I_cap , V_cap , V_bat , I_chassis , I_bat } |
| Enum for identifying ADC channels. More... | |
| enum | pid_names { P_bat , P_chassis , I_capa , V_cap_max , V_cap_min } |
| Enum for identifying PID loops. More... | |
Variables | |
| uint16_t | adc1_samples [2][16][2] |
| Raw buffer for ADC1. | |
| uint16_t | adc2_samples [2][16][3] |
| Raw buffer for ADC2. | |
| uint16_t | ADC_filtered_data [5] |
| Filtered data per channel. | |
| mov_avrg_filter | filters [5] |
| Filter states per channel. | |
| float | adc_gains [5] |
| Gain correction per channel. | |
| float | adc_offsets [5] |
| Offset correction per channel. | |
Header file for managing ADC sampling, compensation, and filtering for the supercapacitor control board.
Defines gain/offset macros, buffer sizes, filtering structures, and the ADC manager class.
Created on: Jul 5, 2024 Author: Yassine Bakkali
| #define ADC1_CHANNELS 2 |
| #define ADC2_CHANNELS 3 |
| #define ADC_BUFFER_DEPTH 16 |
| #define ADC_FIRST_BUFFER 0 |
| #define ADC_REF 3.3f |
Reference voltage for ADC (V)
| #define ADC_RES 4095.0f |
ADC maximum value (12-bit)
| #define ADC_SECOND_BUFFER 1 |
| #define GET_COMPENSATED_ADC | ( | ADC_VAL, | |
| NAME ) |
Helper macro for applying gain + offset compensation on raw ADC readings.
| #define IBAT_GAIN -(ADC_REF / SHUNT_RESISTOR / INA186A2_GAIN / ADC_RES) |
Current measurement gain from each source, sign indicates direction.
| #define ICAP_GAIN -(ADC_REF / SHUNT_RESISTOR / INA186A2_GAIN / ADC_RES) |
| #define INA186A2_GAIN 50.0f |
INA186A2 current amplifier gain (datasheet)
| #define INV_VOLT_DIV 11.0f |
Inverse of voltage divider ratio (used for voltage measurement scaling)
| #define ISOURCE_GAIN -(ADC_REF / SHUNT_RESISTOR / INA186A2_GAIN / ADC_RES) |
| #define SHUNT_RESISTOR 0.004f |
Value of current sensing shunt resistor (Ohms)
| #define VBAT_GAIN ADC_REF * INV_VOLT_DIV / ADC_RES |
| #define VCAP_GAIN ADC_REF * INV_VOLT_DIV / ADC_RES |
Voltage measurement gain: V = (ADC / 4095) * 3.3 * 11.
| enum adc_names |
| enum pid_names |
|
extern |
Raw buffer for ADC1.
|
extern |
Raw buffer for ADC2.
|
extern |
Filtered data per channel.
|
extern |
Gain correction per channel.
|
extern |
Offset correction per channel.
|
extern |
Filter states per channel.