7
7
#include " ../stm32_mcu.h"
8
8
#include " ../../../../drivers/hardware_specific/stm32/stm32_mcu.h"
9
9
#include " communication/SimpleFOCDebug.h"
10
+ #include " ../stm32_adc_utils.h"
10
11
11
12
#define _ADC_VOLTAGE 3 .3f
12
13
#define _ADC_RESOLUTION 4096 .0f
@@ -25,6 +26,16 @@ static DMA_HandleTypeDef hdma_adc2;
25
26
volatile uint16_t adcBuffer1[ADC_BUF_LEN_1] = {0 }; // Buffer for store the results of the ADC conversion
26
27
volatile uint16_t adcBuffer2[ADC_BUF_LEN_2] = {0 }; // Buffer for store the results of the ADC conversion
27
28
29
+
30
+ // structure containing the configuration of the adc interrupt
31
+ Stm32AdcInterruptConfig adc_interrupt_config[5 ] = {
32
+ {0 , 0 , 0 }, // ADC1
33
+ {0 , 0 , 0 }, // ADC2
34
+ {0 , 0 , 0 }, // ADC3
35
+ {0 , 0 , 0 }, // ADC4
36
+ {0 , 0 , 0 } // ADC5
37
+ };
38
+
28
39
// function reading an ADC value and returning the read voltage
29
40
// As DMA is being used just return the DMA result
30
41
float _readADCVoltageLowSide (const int pin, const void * cs_params){
@@ -155,14 +166,16 @@ void* _driverSyncLowSide(void* _driver_params, void* _cs_params){
155
166
// stop all the timers for the driver
156
167
stm32_pause (driver_params);
157
168
158
- // if timer has repetition counter - it will downsample using it
159
- // and it does not need the software downsample
160
- if ( IS_TIM_REPETITION_COUNTER_INSTANCE (cs_params->timer_handle ->Instance ) ){
161
- // adjust the initial timer state such that the trigger for DMA transfer aligns with the pwm peaks instead of throughs.
162
- // only necessary for the timers that have repetition counters
163
- cs_params->timer_handle ->Instance ->CR1 |= TIM_CR1_DIR;
164
- cs_params->timer_handle ->Instance ->CNT = cs_params->timer_handle ->Instance ->ARR ;
169
+ // get the index of the adc
170
+ int adc_index = _adcToIndex (cs_params->adc_handle );
171
+
172
+ bool tim_interrupt = _initTimerInterruptDownsampling (cs_params, driver_params, adc_interrupt_config[adc_index]);
173
+ if (tim_interrupt) {
174
+ // error in the timer interrupt initialization
175
+ SIMPLEFOC_DEBUG (" STM32-CS: timer has no repetition counter, ADC interrupt not supported for B-G431" );
176
+ return SIMPLEFOC_CURRENT_SENSE_INIT_FAILED;
165
177
}
178
+
166
179
// set the trigger output event
167
180
LL_TIM_SetTriggerOutput (cs_params->timer_handle ->Instance , LL_TIM_TRGO_UPDATE);
168
181
0 commit comments