cancel
Showing results for 
Search instead for 
Did you mean: 

STM32MP131 One Pulse Mode with PWM

Stnoobs
Associate II

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

Stnoobs_0-1731651591602.png

 

 

 

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);

}

 

 

2 REPLIES 2
PatrickF
ST Employee

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.

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.
 

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:

Pins

  • 4-Line QuadSPI Data
  • Latch (Active Low): GPIO Mode
  • Strobe (Active Low): AF Mode, One Pulse
    The pulse width of the Strobe signal needs to vary depending on the situation.

Procedure

  1. Transmit QuadSPI Data.
  2. After data transmission is complete, send the Latch signal.
  3. Within 30ns after the Latch signal ends, send the Strobe signal.

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.