cancel
Showing results for 
Search instead for 
Did you mean: 

External trigger of STM32G474RET6 timer 3 behavior

AlexHalf
Associate III

Hello 

 

I am working with an STM32G474RET6, using Timer 3 in one-pulse mode with an external trigger.

Below is my Timer 3 initialization code:

static void MX_TIM3_Init(void)
{

/* USER CODE BEGIN TIM3_Init 0 */

/* USER CODE END TIM3_Init 0 */

TIM_ClockConfigTypeDef sClockSourceConfig = {0};
TIM_SlaveConfigTypeDef sSlaveConfig = {0};
TIM_MasterConfigTypeDef sMasterConfig = {0};
TIM_OC_InitTypeDef sConfigOC = {0};

/* USER CODE BEGIN TIM3_Init 1 */

/* USER CODE END TIM3_Init 1 */
htim3.Instance = TIM3;
htim3.Init.Prescaler = 0;
htim3.Init.CounterMode = TIM_COUNTERMODE_UP;
htim3.Init.Period = 4097;
htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV4;
htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
if (HAL_TIM_Base_Init(&htim3) != HAL_OK)
{
Error_Handler();
}
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
if (HAL_TIM_ConfigClockSource(&htim3, &sClockSourceConfig) != HAL_OK)
{
Error_Handler();
}
if (HAL_TIM_PWM_Init(&htim3) != HAL_OK)
{
Error_Handler();
}
if (HAL_TIM_OnePulse_Init(&htim3, TIM_OPMODE_SINGLE) != HAL_OK)
{
Error_Handler();
}
sSlaveConfig.SlaveMode = TIM_SLAVEMODE_COMBINED_RESETTRIGGER;
sSlaveConfig.InputTrigger = TIM_TS_ETRF;
sSlaveConfig.TriggerPolarity = TIM_TRIGGERPOLARITY_NONINVERTED;
sSlaveConfig.TriggerPrescaler = TIM_TRIGGERPRESCALER_DIV1;
sSlaveConfig.TriggerFilter = 0xf;
if (HAL_TIM_SlaveConfigSynchro(&htim3, &sSlaveConfig) != HAL_OK)
{
Error_Handler();
}
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
if (HAL_TIMEx_MasterConfigSynchronization(&htim3, &sMasterConfig) != HAL_OK)
{
Error_Handler();
}
sConfigOC.OCMode = TIM_OCMODE_PWM2;
sConfigOC.Pulse = 1;
sConfigOC.OCPolarity = TIM_OCPOLARITY_LOW;
sConfigOC.OCFastMode = TIM_OCFAST_ENABLE;
if (HAL_TIM_PWM_ConfigChannel(&htim3, &sConfigOC, TIM_CHANNEL_4) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN TIM3_Init 2 */

/* USER CODE END TIM3_Init 2 */
HAL_TIM_MspPostInit(&htim3);

}

I am facing an issue in one of our systems where I suspect a very noisy trigger signal. The MCU receives a 1500 µs  width positive trigger, and Timer 3 should be triggered on the rising edge.

Timer 3 clock is 64 MHz, and I have set the filter value: ETF = 0xF, which corresponds to a debounce filter value of 14µs-16µs. However, I discovered that the trigger is not detected with this setting and had to reduce the filter value below ETF = 5 to get it working.

Unfortunately, I cannot observe the actual trigger behavior with an oscilloscope because this system is installed thousands of kilometers away in Australia.

I would like to understand the trigger detection behavior of the MCU in this scenario. Specifically:

  1. If there is noise only around the actual trigger's edge and the trigger is not detected, what happens next?
  2. Does the MCU wait for the next edge to start counting the filter value, or does it start counting the filter value based on the detected edge even if the actual state of the signal is '1'?

Here is some additional context:

  • System Purpose: The system is used in an industrial environment where precise timing and trigger detection are critical.
  • Noise Characteristics: I suspect high-frequency noise generated by nearby motors or machinery, but I do not have exact measurements.
  • Environment: The system operates in a high-noise industrial environment with significant electromagnetic interference.

Any insights or suggestions on how to handle this situation better would be greatly appreciated.

 

Thank you.

Alex

1 REPLY 1
Bob S
Principal

First, when posting code please use the "code tags" (look like "</>" in the tool bar).  It makes it easier to read.

AN4776 shows an example of the filter response.  It basically looks for N consecutive samples before changing the filter output state, where "N" is determined by the EFT value.  If the filter output is 0, then it requires N consecutive "1" samples before outputting a 1.  If the the filter output is 1, then it requires N consecutive samples of 0 before outputting a zero.

If your 1500us pulse doesn't get through the 16us filter then you have serious noise issues.  Do you have external filters on the trigger signal?  Shielding?  Have you tested your product (in your lab) in a similar kind of environment?  Industrial environments are notoriously noisy - both conducted noise through any and all cables, and radiated from motors and/or drive electronics.

If you have the luxury or loading a test program into that device, you can re-configure the timer to measure the "high" time of every pulse that it sees.  Save that data to memory somewhere that you can retrieve.