cancel
Showing results for 
Search instead for 
Did you mean: 

CubeMX support of One pulse modes for timers

GreenGuy
Lead
Posted on August 23, 2016 at 07:23

Some of the timers that contain multiple channels are supposed to be able to support a one pulse mode where a delay precedes the pulse after a trigger is received.  However in CubeMX I cannot see how to set that up.  Is that mode only attainable by altering the CubeMX generation after the fact with user code?

5 REPLIES 5
Walid FTITI_O
Senior II
Posted on August 24, 2016 at 13:55

Hi greenwood.greg,

You just select the channel of TIMx and after that pick the ''One Pulse Mode'' from the TIMx menu on the bottom as showed in the figure bellow.

0690X00000602cfQAA.jpg

-Hannibal-
Posted on September 28, 2017 at 04:24

Uh....

Clock source and input capture channel should also be configured, right?

Posted on December 05, 2017 at 19:34

I'm trying to get this to work on a STM32F410RB nucleo board.  So far without much luck. I know that you have to use Channels 1 and 2 on the timer.  One of them will be configured as the input trigger and the other will be the output.

I've found this MXCube configuration and code in 'Mastering STM32' (sorry it's not in the code format.  I'm not sure how that works with the '<>')

0690X000006094fQAA.png

---------------------------------------------------------------------------------------------------------------------------------------------------------------

24 void MX_TIM3_Init(void) {

25 TIM_OnePulse_InitTypeDef sConfig;

26

27 htim3.Instance = TIM3;

28 htim3.Init.Prescaler = 47;

29 htim3.Init.CounterMode = TIM_COUNTERMODE_UP;

30 htim3.Init.Period = 65535;

31 HAL_TIM_OnePulse_Init(&htim3, TIM_OPMODE_SINGLE);

32

33 /* Configure the Channel 1 */

34 sConfig.OCMode = TIM_OCMODE_PWM1;

35 sConfig.OCPolarity = TIM_OCPOLARITY_LOW;

36 sConfig.Pulse = 19999;

37

38 /* Configure the Channel 2 */

39 sConfig.ICPolarity = TIM_ICPOLARITY_RISING;

40 sConfig.ICSelection = TIM_ICSELECTION_DIRECTTI;

41 sConfig.ICFilter = 0;

42

Timers 377

43 HAL_TIM_OnePulse_ConfigChannel(&htim3, &sConfig, TIM_CHANNEL_1, TIM_CHANNEL_2);

44 }

---------------------------------------------------------------------------------------------------------------------------------------------------------------

But the STM32Cube initialization code looks like this:

---------------------------------------------------------------------------------------------------------------------------------------------------------------

static void MX_TIM9_Init(void)

{

TIM_ClockConfigTypeDef sClockSourceConfig;

TIM_IC_InitTypeDef sConfigIC;

TIM_OC_InitTypeDef sConfigOC;

htim9.Instance = TIM9;

htim9.Init.Prescaler = 10000;

htim9.Init.CounterMode = TIM_COUNTERMODE_UP;

htim9.Init.Period = 1000;

htim9.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;

if (HAL_TIM_Base_Init(&htim9) != HAL_OK)

{

_Error_Handler(__FILE__, __LINE__);

}

sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;

if (HAL_TIM_ConfigClockSource(&htim9, &sClockSourceConfig) != HAL_OK)

{

_Error_Handler(__FILE__, __LINE__);

}

if (HAL_TIM_IC_Init(&htim9) != HAL_OK)

{

_Error_Handler(__FILE__, __LINE__);

}

if (HAL_TIM_PWM_Init(&htim9) != HAL_OK)

{

_Error_Handler(__FILE__, __LINE__);

}

if (HAL_TIM_OnePulse_Init(&htim9, TIM_OPMODE_SINGLE) != HAL_OK)

{

_Error_Handler(__FILE__, __LINE__);

}

sConfigIC.ICPolarity = TIM_INPUTCHANNELPOLARITY_RISING;

sConfigIC.ICSelection = TIM_ICSELECTION_DIRECTTI;

sConfigIC.ICPrescaler = TIM_ICPSC_DIV1;

sConfigIC.ICFilter = 0;

if (HAL_TIM_IC_ConfigChannel(&htim9, &sConfigIC, TIM_CHANNEL_1) != HAL_OK)

{

_Error_Handler(__FILE__, __LINE__);

}

sConfigOC.OCMode = TIM_OCMODE_PWM1;

sConfigOC.Pulse = 100;

sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;

sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;

if (HAL_TIM_PWM_ConfigChannel(&htim9, &sConfigOC, TIM_CHANNEL_2) != HAL_OK)

{

_Error_Handler(__FILE__, __LINE__);

}

HAL_TIM_MspPostInit(&htim9);

}

---------------------------------------------------------------------------------------------------------------------------------------------------------------

I believe that you can call functions from 'if' statement arguments so that shouldn't be a problem.  I'm still looking through the Cube generated code to find where the PWM pin is set high/low.  I'll let you know if I get it working.

David SIORPAES
ST Employee
Posted on December 06, 2017 at 10:19

Here's attached a One Pulse Timer demo project I generated some time ago with CubeMX for STM32F0-Discovery. Open the IOC file to see CubeMX confguration.

Demo setup details are descibed in the enclosed readme file.

Hope it helps.

________________

Attachments :

STM32F0Discovery-OnePulseTimer.zip : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006Hy4U&d=%2Fa%2F0X0000000b5K%2FY3RzMa9IjlnaAomMdkM5_hH.H4.fQUTzJCd0nOfjy9A&asPdf=false
shane mattner
Senior
Posted on December 06, 2017 at 17:25

Thanks for the example. It looks similar to how I tried setting up my project. 

For the output compare of the timer why do you use the 'frozen' mode?  I would think you need 'Active level on match'.  Also, can you modify the 'Pulse' value for the output compare to phase modulate the Triac?  I've successfully used the following HAL functions to set the auto reload set the timer counter back to 0:

__HAL_TIM_SET_AUTORELOAD();

__HAL_TIM_SET_COUNTER();