cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4 using timer channels to generate shifted pulses

lzielinski66
Associate
Posted on November 08, 2016 at 19:59

Hi, I want to generate short pulses on channels 1, 2 and 3 of TIM4. Pulses on each channel must be shifted relative to other channels, just like on image below:

0690X000006030JQAQ.jpg

Main idea is:

At first I set TIM4 mode to TIM_OCMode_Active, then set different CCRx values to each channel, then in TIM4 interrupt handler i managed to add to CCRx constant value (my pulse width) and set TIM4 mode to TIM_OCMode_Inactive. In the next interrupt CCRx and TIM4 mode were set to the original values.

After many tests it doesn't work, even single channel. I'm not able to paste here my code right now, if needed i can do this later. Is the idea good, is it even possible to do this or am i convicted to use 3 different timers? If it is possible can someone help me with some working code?

#!stm32f4-!timer-!channels-!pulse
4 REPLIES 4
Posted on November 08, 2016 at 20:05

Toggle mode has been used to get specific edge placement.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
lzielinski66
Associate
Posted on November 08, 2016 at 20:34

So all I should do is to set toggle mode at the beginning and in the interrupt handler control only CCRx, right?

Could you please also tell me what actually is TIM_OutputState? I couldn't get any information if should i pass the TIM_OutputState_Enable or TIM_OutputState_Disable...

Thank You in advance, Sir.

Walid FTITI_O
Senior II
Posted on November 09, 2016 at 17:33

Hi varsheim, 

I recommend that you have a look to the example ''TIM_ComplementarySignals'' in the STM32CubeF4 library package where you find how to ouptout signal with dead timer insertion ; at this path  STM32Cube_FW_F4_V1.13.0\Projects\STM324xG_EVAL\Examples\TIM\TIM_ComplementarySignals

-Hannibal-

Posted on November 09, 2016 at 17:53

I've generally initialized the timer, and initial phase angles, and then advanced the phase angles in the CCRx as each of the prior ones have hit. For higher frequencies one might need to decimate interrupt loading using DMA to load from tables.

I've posted examples of the toggle mode method on the forum, but I'm not a motor guy, and this isn't how I use STM32 parts.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..