STM32G0 - brushless motor control driver - PWM + ADC + DMA. I need to read first ADC value ASAP.
- July 4, 2022
- 2 replies
- 2325 views
Hi, I'm starting to design motor control driver using discrete analog H bridges - first time with STM32 micro. Currently using Nucleo G031K8 for experiments until custom board will be ready. So far I configured 3 PWM channels - normal and complementary central aligned PWMs (20 kHz) with deadtime using advanced TIM1 timer. TIM1 also generates update event trigger for ADC1 to start conversion. I'm using DMA to capture 10 ADC conversions in one sequence (2*3 values for H bridges and + 4 additional values). Using Cube and LL drivers. ADC settings captured in screenshot. It seems to work, TIM1 update interrupt comes in the middle of PWM pulse as expected. ADC data are coming into DMA double circular buffer, half transfer interrupt takes about 4.8us: 64 MHz internal oscillator clock, 32 MHz ADC clock, 1.5 clock sampling time. Based on datasheet formula it is: (1.5 + 12.5) * 1/32MHz * 10 = 4.4 us - close to expected value.
Now the problem - I want to read motor current (the first ADC channel) ASAP every PWM period so I can run control loop in paralell with the rest of ADC conversions. I was searching for solution. I found that F4 and G4 have possibility to create ADC injected conversion group which seems to be ideal solution, but we cannot use these micros because of cost limitation. Is there another way? Can I read ADC channel data (the first channel) when DMA is active somehow? I tried to enable ADC EOC (End of Conversion) interrupt, but it triggers interrupt in very slow period around 6.5 ms. Any idea why? Maybe it is not possible to use it when DMA is enabled? I also notices that enabling EOC enables EOS (End of Sequence) interrupt. EOS is triggering every 9.8 us. Why? In Cube there is also parameter called "End of Conversion Selection" but it doesn't seem to have any impact on the generated code when I switch from "End of single conversion" to "End of sequence of conversion". Is there maybe any example how to drive brushless motor using STM32G0 or similar micro?
