cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F302 ADC+TIM+DMA

JaVerdin
Associate

Hello, I'm working on a project related to SPWM modulation for inverters, I´m using two timers, TIM1(CH1,CH3) as a PWM signals and TIM2(CH1) as a trigger signal for the adc module, the sample frequency is set to 72kHz. I need to read 4 adc channels using DMA : IN1 (2 samples), IN10 (2 samples), IN14 (4 samples) and IN15 (2 samples). In addition, for the IN4 a 3 kHz sine wave is injected. However, I have a problem with the adc, when we are debugging the variable (adc_val [4]) with the values returned by the DMA I noticed that these values are constantly changing position, I mean, the values are stored as follows, adc_val[0] = measurement 1, adc_val[1] = measurement 2, adc_val[2] = measurement 3 and adc_val[3] = measurement 4, but when the program is running theses values can be stored in the next way, adc_val[0] = measurement 3, adc_val[1] = measurement 4, adc_val[2] = measurement 1 and adc_val[3] = measurement 2, I do not know how to solve this problem. Could someone help me to solve it please?
The configurations of the TIM and ADC are depicted in the following captures. Thanks.

TIM1 Configuration (TIM for SPWM)

JaVerdin_0-1689635352637.png

JaVerdin_2-1689635419087.pngJaVerdin_3-1689635451276.png

TIM2 (TIM to ADC)

JaVerdin_4-1689635527078.png

 

ADC Configuration

JaVerdin_5-1689635569090.png

JaVerdin_6-1689635647784.png

 

JaVerdin_8-1689635684150.pngJaVerdin_9-1689635753632.png

correct order of measurements 

JaVerdin_11-1689637690986.png

wrong order of measurements 

JaVerdin_12-1689637807067.png

it can be noticed that the measurements are shifted from order

Code
Initialize

JaVerdin_13-1689637889519.png

Interrupt

JaVerdin_14-1689637986371.png

The ADC is started on the TIM1 interrupt

JaVerdin_0-1689692660487.png

 

 

0 REPLIES 0