Add ADC2 channel configuration for STM32G4 board

Some changes regarding DMA setup and data alignment were necessary to
store all values from ADC1 and ADC2 in the same adc_readings array.
This commit is contained in:
Martin Jäger
2020-02-20 11:07:02 +01:00
parent d40dafd8d9
commit 3c0bc41164
8 changed files with 79 additions and 58 deletions
+2
View File
@@ -100,6 +100,8 @@ enum {
NUM_ADC_CH // trick to get the number of enums
};
#define NUM_ADC_1_CH NUM_ADC_CH
// selected ADC channels (has to match with above enum)
#define ADC_CHSEL ( \
ADC_CHSELR_CHSEL0 | \
+2
View File
@@ -111,6 +111,8 @@ enum {
NUM_ADC_CH // trick to get the number of elements
};
#define NUM_ADC_1_CH NUM_ADC_CH
// selected ADC channels (has to match with above enum)
#if defined(STM32F0) || defined(CONFIG_SOC_SERIES_STM32F0X)
#define ADC_CHSEL ( \
+2
View File
@@ -115,6 +115,8 @@ enum {
NUM_ADC_CH // trick to get the number of elements
};
#define NUM_ADC_1_CH NUM_ADC_CH
// selected ADC channels (has to match with above enum)
#define ADC_CHSEL ( \
ADC_CHSELR_CHSEL0 | \
+37 -17
View File
@@ -74,34 +74,54 @@ const enum pin_state_t led_pin_setup[NUM_LEDS][NUM_LED_PINS] = {
#define NTC_BETA_VALUE 3435
#define NTC_SERIES_RESISTOR 10000.0
#define ADC_GAIN_V_LOW (105.6 / 5.6) // both voltage dividers: 100k + 5.6k
#define ADC_GAIN_V_HIGH (105.6 / 5.6)
#define ADC_GAIN_I_LOAD (1000 / 4 / 50) // amp gain: 50, resistor: 4 mOhm
#define ADC_GAIN_I_DCDC (1000 / 4 / 50)
#define ADC_GAIN_V_LOW (105.6 / 5.6)
#define ADC_GAIN_V_HIGH (102.2 / 2.2)
#define ADC_GAIN_V_PWM (1 + 120/12 + 120/8.2)
#define ADC_GAIN_I_DCDC (1000 / 2 / 20) // amp gain: 20, resistor: 2 mOhm
// op amp gain: 68/2.2, resistor: 2 mOhm
#define ADC_GAIN_I_LOAD (1000 / 2 / (68/2.2))
#define ADC_GAIN_I_PWM (1000 / 2 / (68/2.2))
// to be multiplied with VREF to get absolute voltage offset
#define ADC_OFFSET_V_PWM (-120.0 / 8.2)
// position in the array written by the DMA controller
enum {
ADC_POS_V_LOW, // ADC 0 (PA_0)
ADC_POS_V_HIGH, // ADC 1 (PA_1)
ADC_POS_TEMP_FETS, // ADC 5 (PA_5)
ADC_POS_I_DCDC, // ADC 7 (PA_7)
ADC_POS_I_LOAD, // ADC 6 (PA_6)
ADC_POS_VREF_MCU, // ADC 17
ADC_POS_TEMP_MCU, // ADC 16
// ADC1
ADC_POS_V_LOW,
ADC_POS_V_HIGH,
ADC_POS_V_SC_SENSE,
ADC_POS_V_PWM,
ADC_POS_TEMP_FETS,
ADC_POS_VREF_MCU,
ADC_POS_TEMP_MCU,
// ADC2
ADC_POS_I_DCDC,
ADC_POS_I_LOAD,
ADC_POS_I_PWM,
NUM_ADC_CH // trick to get the number of elements
};
// selected ADC 1 channels (has to match with above enum)
#define NUM_ADC_1_CH 5
// selected ADC channels (has to match with below arrays)
#define NUM_ADC_1_CH 7
#define NUM_ADC_2_CH 3
const uint32_t adc_1_sequence[] = {
LL_ADC_CHANNEL_12, // V_BAT
LL_ADC_CHANNEL_15, // V_SOLAR
LL_ADC_CHANNEL_12, // V_LOW
LL_ADC_CHANNEL_15, // V_HIGH
LL_ADC_CHANNEL_11, // V_SC_SENSE
LL_ADC_CHANNEL_4, // V_PWM
LL_ADC_CHANNEL_6, // TEMP_FETS
LL_ADC_CHANNEL_1, // I_DCDC
LL_ADC_CHANNEL_2, // I_LOAD
LL_ADC_CHANNEL_VREFINT, // VREF_MCU
LL_ADC_CHANNEL_TEMPSENSOR_ADC1, // TEMP_MCU
};
const uint32_t adc_2_sequence[] = {
LL_ADC_CHANNEL_1, // I_DCDC
LL_ADC_CHANNEL_2, // I_LOAD
LL_ADC_CHANNEL_5, // I_PWM
};
#endif
+2
View File
@@ -119,6 +119,8 @@ enum {
NUM_ADC_CH // trick to get the number of enums
};
#define NUM_ADC_1_CH NUM_ADC_CH
// selected ADC channels (has to match with above enum)
#define ADC_CHSEL ( \
ADC_CHSELR_CHSEL0 | \
+2
View File
@@ -95,4 +95,6 @@ enum {
NUM_ADC_CH // trick to get the number of elements
};
#define NUM_ADC_1_CH NUM_ADC_CH
#endif
+2
View File
@@ -146,6 +146,8 @@ enum {
NUM_ADC_CH // trick to get the number of elements
};
#define NUM_ADC_1_CH NUM_ADC_CH
// selected ADC channels (has to match with above enum)
#define ADC_CHSEL ( \
ADC_CHSELR_CHSEL0 | \