cancel
Showing results for 
Search instead for 
Did you mean: 

Hello everyone! I am trying to implement FOC control on stm32f405 mcu. What I want to do is to start Adc conversation in the middle of PWM cycle. I am using complementary PWM of timer1 which runs at 42 kHz.

YSEVİ.1
Associate II

 I have done the research but couldn't do more  than triggering the adc cycle with a timer trigger. Is there any example to do it using cube mx and DMA?

Thank you

4 REPLIES 4

Run another timer with TIM1, with the same period, having them in master-slave arrangement with the slave in Trigger mode. so that they run synchronously. Use that other timer to trigger the ADC from some of its channels, set to Compare at an appropriate time of the period.

JW

YSEVİ.1
Associate II

Thanks for the answer. I am actually doing this without using extra timer by using channel 4 of timer1 in OC mode. This OC event triggers injected conversation. But I couldn't find a way to do it using DMA. Currently I am polling values in ConversationCompleted interrupt.

> I am actually doing this without using extra timer by using channel 4 of timer1 in OC mode. This OC event triggers injected conversation.

Injected conversions don't trigger DMA. That's why you have to circumvent this problem by using a second timer, even if it's inconvenient.

JW

YSEVİ.1
Associate II

Okay I see your point now. There is something I didnt understand though, Let's say I chose TIM 5 to be master and the bus it is connected to is 84MHz. So I set its prescaler to zero and counter period to 1000, so I have 84 kHz clock source to TIM1. After that point I set TIM1's prescaler and counter period to any value different from zero then those timer will be running at different frequencies. for example adc will be triggered at 84 kHz but my PWM is 42 kHz. also with the counter period is set to zero, I wont be able to control duty cycle anymore. I think I am missing something here and I would be appreciated if you could enlighten me with this too. Thanks.