I would like to trigger loopFOC() and move() by Timers. Which ones are used already for the PWM and ADC by simpleFOC? Is there a way to find out which timers are used by default, maybe some general approach? I am not so familiar yet with STM32duino
I am programing in PlatformIO and its a Nucleo-64 board.
You need to find the complementory timers. For example, TIM1 CH1 / TIM1 CH1N will drive high/low of one of the phases. Read the documentation.
For 3pwm, any three on the same timer will work.
PS For example, PE2 (TIM1_CH1) and PA7 (TIM1_CH1N) would form one such pair on the 64 pin stm32f446re. Page 64 and onwards. All must be on the same timer, so look for TIM1_CHx and TIM1_CHxN and match the channel numbers for the same timer. N means “negative”, or they also call it “complementary”. These types of complementary timers are specifically designed for motor control with centrally aligned PWM timer. This is done to guarantee dead-time between the high and low signals.
For in-depth treatment of the motor control timers, please read Page 29 onwards from the one below.
Maybe my questions was not specific enough. I know that the driver class of simplefoc will use some timers, depending on whether its 6PWM or 3PWM. Thats fine. I just want to know which ones are used, so I dont mess those up with my code.
For example: 3PWM uses TIM1, TIM2, TIM3. That means my added functionality shall not use, or reconfigure those timers. I could use for example TIM4 and would not interfere with the PWM generation. So i just need the information which timers I shall not touch
I tried to read it from the source code in stm32_mcu.cpp of simplefoc. Unfortunately there is no explicit use of TIM. Instead pinmap_peripheral() is used to get a suitable Timer.
That’s incorrect. For 3PWm you must use TIM1_CH1, TIM1_CH2 and TIM1_CH3, or any other TIMn. Using PWM on different timers is incorrect.
Please read the documentation first, it will be of great help.
The code just takes the pins you specify, there are no hard-coded pins there, don’t look for those in the code.
You MUST use the same timer with the attached timer channels for all signals. In other words, your 3 or 6 PWM signals MUST be generated by the SAME timer on three different channels for 3PWM or 6PWM you need 3 channel/complementary matching channel pairs. Channel is not the same as timer. The timer is a physical oscillator. The channel is a wire connecting the oscillator to a pin with some extra logic to it. You could have up to 7 pins attached to an oscillator, with 4 of them main channels and another 3 complementary logic channels. Not all timers have complementary pairs, so you need to read very carefully the pin assignments. Also, not all pins are exposed on different packages, so you need to again read and create a list for what’s available for the package you use.
One more thing, STM32 does channel multiplexing, so you may have the same channel exposed on different pins, and you have the option of selecting which pin to use for a particular channel or channel/complementary channel pair.
okay so that means simplefoc uses TIM1 only? According to the doc one could also use TIM8 as they both have the same features (Advanced-control timers). How could I check in the source code which timers are used by simple foc?
I dont want to generate a PWM signal. I just want to add a new timer triggered function that will do something different and is not related or a replacement to the simplefoc PWM generation. I understand that depending on what I want to do, i have to choose a specific TIM. But before that I wanted to know which TIM I should not use, because it is already used by simplefoc driver.
You can use ANY timer as long as it is the SAME timer for 3PM and as long as it has 3 complementary channels for 6PWM. It is up to you to choose the timers. SimpleFOC does not choose the timers. You specify the channels in the code when you write the code to initialize the motor control.
The MCU you used, stm32f446re, has 17 timers: 2x watchdog, 1x SysTick timer and up to
twelve 16-bit and two 32-bit timers up to 180 MHz, each with up to four IC/OC/PWM or pulse counter.