@@ -35,7 +35,6 @@ int _adc_init(Stm32CurrentSenseParams* cs_params, const STM32DriverParams* drive
35
35
return -1 ;
36
36
}
37
37
38
-
39
38
/* *Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion)
40
39
*/
41
40
hadc.Instance = (ADC_TypeDef *)pinmap_peripheral (analogInputToPinName (cs_params->pins [0 ]), PinMap_ADC);
@@ -74,10 +73,15 @@ int _adc_init(Stm32CurrentSenseParams* cs_params, const STM32DriverParams* drive
74
73
// https://github.com/stm32duino/Arduino_Core_STM32/blob/e156c32db24d69cb4818208ccc28894e2f427cfa/system/Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_adc.h#L170C13-L170C27
75
74
hadc.Init .DMAContinuousRequests = DISABLE;
76
75
// not sure about this one!!! maybe use: ADC_SAMPLING_MODE_NORMAL
77
- hadc.Init .SamplingMode = ADC_SAMPLING_MODE_TRIGGER_CONTROLED ;
76
+ hadc.Init .SamplingMode = ADC_SAMPLING_MODE_BULB ;
78
77
#endif
79
78
hadc.Init .NbrOfConversion = 1 ;
79
+ hadc.Init .NbrOfDiscConversion = 0 ;
80
80
hadc.Init .EOCSelection = ADC_EOC_SINGLE_CONV;
81
+
82
+ hadc.Init .LowPowerAutoWait = DISABLE;
83
+
84
+
81
85
if ( HAL_ADC_Init (&hadc) != HAL_OK){
82
86
#ifdef SIMPLEFOC_STM32_DEBUG
83
87
SIMPLEFOC_DEBUG (" STM32-CS: ERR: cannot init ADC!" );
@@ -91,16 +95,20 @@ int _adc_init(Stm32CurrentSenseParams* cs_params, const STM32DriverParams* drive
91
95
// if ADC1 or ADC2
92
96
if (hadc.Instance == ADC1 || hadc.Instance == ADC2){
93
97
// more info here: https://github.com/stm32duino/Arduino_Core_STM32/blob/e156c32db24d69cb4818208ccc28894e2f427cfa/system/Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_adc.h#L658
94
- sConfigInjected .InjectedNbrOfConversion = ADC_SAMPLETIME_2CYCLE_5;
98
+ sConfigInjected .InjectedSamplingTime = ADC_SAMPLETIME_2CYCLE_5;
95
99
}else {
96
100
// adc3
97
101
// https://github.com/stm32duino/Arduino_Core_STM32/blob/e156c32db24d69cb4818208ccc28894e2f427cfa/system/Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_adc.h#L673
98
- sConfigInjected .InjectedNbrOfConversion = ADC3_SAMPLETIME_2CYCLES_5;
102
+ sConfigInjected .InjectedSamplingTime = ADC3_SAMPLETIME_2CYCLES_5;
99
103
}
100
104
sConfigInjected .ExternalTrigInjecConvEdge = ADC_EXTERNALTRIGINJECCONV_EDGE_RISINGFALLING;
101
105
sConfigInjected .AutoInjectedConv = DISABLE;
102
106
sConfigInjected .InjectedDiscontinuousConvMode = DISABLE;
103
107
sConfigInjected .InjectedOffset = 0 ;
108
+ sConfigInjected .InjectedSingleDiff = ADC_SINGLE_ENDED;
109
+ sConfigInjected .InjectedOffsetNumber = ADC_OFFSET_NONE;
110
+ sConfigInjected .QueueInjectedContext = DISABLE;
111
+ sConfigInjected .InjecOversamplingMode = DISABLE;
104
112
105
113
// automating TRGO flag finding - hardware specific
106
114
uint8_t tim_num = 0 ;
@@ -139,11 +147,11 @@ int _adc_init(Stm32CurrentSenseParams* cs_params, const STM32DriverParams* drive
139
147
#endif
140
148
}
141
149
150
+ uint32_t ranks[4 ] = {ADC_INJECTED_RANK_1, ADC_INJECTED_RANK_2, ADC_INJECTED_RANK_3, ADC_INJECTED_RANK_4};
142
151
for (int i=0 ; i<3 ; i++){
143
152
// skip if not set
144
- if (!_isset (cs_params->pins [i])) continue ;
145
-
146
- sConfigInjected .InjectedRank = ADC_INJECTED_RANK_1 + i;
153
+ if (!_isset (cs_params->pins [i])) continue ;
154
+ sConfigInjected .InjectedRank = ranks[i];
147
155
sConfigInjected .InjectedChannel = _getADCChannel (analogInputToPinName (cs_params->pins [i]));
148
156
if (HAL_ADCEx_InjectedConfigChannel (&hadc, &sConfigInjected ) != HAL_OK){
149
157
#ifdef SIMPLEFOC_STM32_DEBUG
@@ -152,7 +160,9 @@ int _adc_init(Stm32CurrentSenseParams* cs_params, const STM32DriverParams* drive
152
160
return -1 ;
153
161
}
154
162
}
155
-
163
+
164
+
165
+ delay (1000 );
156
166
#ifdef SIMPLEFOC_STM32_ADC_INTERRUPT
157
167
// enable interrupt
158
168
HAL_NVIC_SetPriority (ADC_IRQn, 0 , 0 );
0 commit comments