2024-11-14 10:18 PM - edited 2024-11-14 10:20 PM
Hello,
I am trying to generate output with adjustable pulse width using One Pulse mode.
The output pin is in a Pull-Up state, with an initial state of High. When One Pulse mode is activated, it outputs a Low signal for the specified duration.
However, there is an issue.
I expected the output to immediately drop to Low when the timer starts, but there is a delay of approximately 820ns before the One Pulse output is generated.
Is there a solution to this?
I am attaching my code.
Thank you in advance.
* Timer source Clock : 200MHz
static void MX_TIM5_Init(void)
{
/* USER CODE BEGIN TIM5_Init 0 */
/* USER CODE END TIM5_Init 0 */
TIM_MasterConfigTypeDef sMasterConfig = {0};
TIM_OC_InitTypeDef sConfigOC = {0};
/* USER CODE BEGIN TIM5_Init 1 */
/* USER CODE END TIM5_Init 1 */
htim5.Instance = TIM5;
htim5.Init.Prescaler = 1-1;
htim5.Init.CounterMode = TIM_COUNTERMODE_UP;
htim5.Init.Period = 1500-1;
htim5.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim5.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
if (HAL_TIM_PWM_Init(&htim5) != HAL_OK)
{
Error_Handler();
}
if (HAL_TIM_OnePulse_Init(&htim5, TIM_OPMODE_SINGLE) != HAL_OK)
{
Error_Handler();
}
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
if (HAL_TIMEx_MasterConfigSynchronization(&htim5, &sMasterConfig) != HAL_OK)
{
Error_Handler();
}
sConfigOC.OCMode = TIM_OCMODE_PWM1;
sConfigOC.Pulse = 1;
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
sConfigOC.OCFastMode = TIM_OCFAST_ENABLE;
if (HAL_TIM_PWM_ConfigChannel(&htim5, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)
{
Error_Handler();
}
__HAL_TIM_DISABLE_OCxPRELOAD(&htim5, TIM_CHANNEL_1);
/* USER CODE BEGIN TIM5_Init 2 */
/* USER CODE END TIM5_Init 2 */
HAL_TIM_MspPostInit(&htim5);
}
2024-11-15 9:15 AM
Hi @Stnoobs
Would you please explain a bit more what it the time you are measuring ?
Which line of code (or HW trigger) set the signal high ? Sound not a pull-up as it could be much slower.
Which line of code (or Hw trigger) set the signal low ?
Would it be possible that the 820ns is linked to some SW execution time between init and timer SW triggering start?
Regards.
2024-11-17 4:44 PM
I am attempting to control a device using QuadSPI. (The device is not Flash Memory.)
The pins and procedure for controlling the device are as follows:
The One Pulse mode is currently being triggered via software without an external trigger signal. The timer output pin is configured with an internal pull-up in CubeMX, so its default state is High.
When One Pulse mode is activated, the signal transitions from High to Low.
I cannot understand why there is a delay of approximately 820ns. This delay varies by 100–200ns every time One Pulse mode is activated.
This is currently running under the ThreadX RTOS environment.
We’re moving the ST Community to a new platform to give you a better and more reliable community experience.