2023-07-18 08:13 AM
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)
TIM2 (TIM to ADC)
ADC Configuration
correct order of measurements
wrong order of measurements
it can be noticed that the measurements are shifted from order
Code
Initialize
Interrupt
The ADC is started on the TIM1 interrupt