cancel
Showing results for 
Search instead for 
Did you mean: 

Can One-Pulse mode only be set for CH1 and CH2?

diverger
Associate III
Posted on December 25, 2017 at 02:29

In STM32F4's HAL code for function 'HAL_TIM_OnePulse_Start':

/**

* @brief Starts the TIM One Pulse signal generation.

* @param htim pointer to a TIM_HandleTypeDef structure that contains

* the configuration information for TIM module.

* @param OutputChannel TIM Channels to be enabled.

* This parameter can be one of the following values:

* @arg TIM_CHANNEL_1: TIM Channel 1 selected

* @arg TIM_CHANNEL_2: TIM Channel 2 selected

* @retval HAL status

*/

HAL_StatusTypeDef

HAL_TIM_OnePulse_Start

(TIM_HandleTypeDef

*

htim,

uint32_t

OutputChannel)

{

/* Prevent unused argument(s) compilation warning */

UNUSED

(OutputChannel);

/* Enable the Capture compare and the Input Capture channels

(in the OPM Mode the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2)

if TIM_CHANNEL_1 is used as output, the TIM_CHANNEL_2 will be used as input and

if TIM_CHANNEL_1 is used as input, the TIM_CHANNEL_2 will be used as output

in all combinations, the TIM_CHANNEL_1 and TIM_CHANNEL_2 should be enabled together

No need to enable the counter, it's enabled automatically by hardware

(the counter starts in response to a stimulus and generate a pulse */

TIM_CCxChannelCmd

(htim->

Instance

, TIM_CHANNEL_1, TIM_CCx_ENABLE);

TIM_CCxChannelCmd

(htim->

Instance

, TIM_CHANNEL_2, TIM_CCx_ENABLE);

if

(

IS_TIM_ADVANCED_INSTANCE

(htim->

Instance

)

!=

RESET)

{

/* Enable the main output */

__HAL_TIM_MOE_ENABLE

(htim);

}

/* Return function status */

return

HAL_OK;

}

It seems only CH1 and CH2 is used, does this mean only CH1 or CH2 can be used in one-pulse mode?

#one-pulse-mode
3 REPLIES 3
Jan Waclawek
Senior II
Posted on December 25, 2017 at 18:33

One-pulse is a mode of the counter, i.e. that the counter disables itself upon update event (i.e. overflows). There's nothing capture/compare-specific in it, i.e. it's relevant to all channels in the same way.

JW

Posted on December 26, 2017 at 06:10

You mean all channels of the timer will support this mode? But why the HAL code only use 

TIM_CHANNEL_1 and 

TIM_CHANNEL_2?

Posted on January 17, 2018 at 23:35

Because this is not what OPM (i.e. mode enabled by TIMx_CR1.OPM) is about.

This function is part of a suite fulfilling one single, complex and quite useless task - turning the timer into a one-shot. This is Cube ad absurdum: this ought to be an example, not part of a 'library'.

Btw. even for this task, the functions are unnecessarily crippled: while the inputs indeed can be only of channels 1 and 2 (as trigger source to slave-mode controller), any channel could be as output.

JW