2023-05-04 06:36 PM
The function HAL_TIM_OnePulse_Start() only operates on channels 1 and 2.
The comment inside it says:
"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; whatever the combination, the TIM_CHANNEL_1 and TIM_CHANNEL_2 should be enabled together".
Nothing in the reference manual says anything about this limitation. I'm trying to use this function to generate a single pulse on channel 3, and I don't understand why the HAL API doesn't allow this.
I'm using the latest FW package FW_F0 V1.11.4 for the STM32F0xx chip series, but I've seen identical code for the FW package for the STM32H7xx series chips.
2023-05-04 09:26 PM
Cube/HAL inevitably implements a tiny fraction of all possible combinations of functionality offered by the hardware, deemed as typical by its authors, and serves primarily as the vehicle for the clicking interface of CubeMX. While naming of its functions is supposed to be "intuitive", is not necessarily so and it does not necessarily match the RM - it's a different world of different concepts.
If it does not fulfill your expectations, just don't use it.
JW
2023-05-05 03:07 PM
Moreover, the HAL_TIM_OnePulse_Start() and HAL_TIM_OnePulse_Start_IT() functions are the only "Start" functions in the timer module that don't start any timers. The function description says "Starts the TIM One Pulse signal generation", but this is misleading. No signal generation is actually started by calling these functions.
The comment about the true functionality of these functions is hidden in the middle of the function bodies:
"No need to enable the counter, it's enabled automatically by hardware (the counter starts in response to a stimulus and generate a pulse"
2023-05-22 04:49 AM
Hello,
HAL_TIM_OnePulse_*** functions stick to the example given in the reference manual (you may refer to RM0091, section 17.3.15). This choice was made on purpose when the HAL TIM driver was created and kept later on to avoid any compatibility break in the API. If you need more flexibility (different trigger and/or different output channel) you can rely on the code generated by CubeMX (see code below where input channel 2 is used as trigger and output channel 3 is used to output the pulse).
...
TIM_SlaveConfigTypeDef sSlaveConfig;
TIM_OC_InitTypeDef sConfigOC;
...
htim1.Instance = TIM1;
htim1.Init.Prescaler = PRESCALER_VALUE;
htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
htim1.Init.Period = 0xFFFF;
htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim1.Init.RepetitionCounter = 0;
htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
if (HAL_TIM_OnePulse_Init(&htim1, TIM_OPMODE_SINGLE) != HAL_OK)
{
Error_Handler();
}
sSlaveConfig.SlaveMode = TIM_SLAVEMODE_TRIGGER;
sSlaveConfig.InputTrigger = TIM_TS_TI2FP2;
sSlaveConfig.TriggerPolarity = TIM_TRIGGERPOLARITY_RISING;
sSlaveConfig.TriggerFilter = 0;
if (HAL_TIM_SlaveConfigSynchronization(&htim1, &sSlaveConfig) != HAL_OK)
{
Error_Handler();
}
sConfigOC.OCMode = TIM_OCMODE_PWM2;
sConfigOC.Pulse = 16383;
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH;
sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET;
sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET;
if (HAL_TIM_PWM_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_3) != HAL_OK)
{
Error_Handler();
}
if (HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_3) != HAL_OK)
{
/* Starting Error */
Error_Handler();
}
regards,
François
2023-05-22 02:54 PM
So that's what it's for! Thank you for this example and explanation.