2019-11-06 02:43 AM
Hi, I am using STM32F779NI for development. My requirements are:
Is it possible to configure the Timer for both this functionalities on different channels of same Timer?
Solved! Go to Solution.
2019-11-07 01:20 AM
> Now, with the above timing value unchanged, I will just configure the IC functionality. If I want to measure the frequency of a signal at PB7,
> what will be the limitations?
Without any additional "tricks", like what @S.Ma mentioned above, or counting separately the overflows in an interrupt or counting the overflows using another timer in master-slave arrangement (and both ways is rather tedious expecially when it comes to resolving events at the vicinity of the overflow), the capture is basically restricted by:
> htim4.Init.Prescaler = 5;
> htim4.Init.Period = 1000;
which means, for capture, maximum resolution (granularity) i.e. the minimum time difference resolvable is (5 + 1)*1/ftim, and the maximum period you can capture is (1000 + 1)*(5 + 1)*1/ftim (i.e. the minimum frequency of the captured input signal is 1/that), where ftim is the frequency of the timer input clock.
JW
2019-11-06 06:29 AM
Yes.
The counter's range is given by the PWM frequency, though.
JW
2019-11-06 08:15 AM
Actually if the channel 4 has DMA on channel compare, you can generate a burst of PWM pulses to extend the timer timeout by multiple of PWM periods...
2019-11-06 10:35 AM
Good idea, @S.Ma
JW
2019-11-06 07:09 PM
Thanks for the reply.
Do you mean the frequency of the signal to be measured on PB7 will be limited to some upper lower range since the timing parameters are with respect to to the PWM configuration. ?
Following are the values set for PWM output. PWM signal of freq around 33khz is generated.
htim4.Instance = TIM4;
htim4.Init.Prescaler = 5;
htim4.Init.CounterMode = TIM_COUNTERMODE_UP;
htim4.Init.Period = 1000;
htim4.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim4.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
if (HAL_TIM_Base_Init(&htim4) != HAL_OK)
{
return HAL_ERROR;
}
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
if (HAL_TIM_ConfigClockSource(&htim4, &sClockSourceConfig) != HAL_OK)
{
return HAL_ERROR;
}
if (HAL_TIM_PWM_Init(&htim4) != HAL_OK)
{
return HAL_ERROR;
}
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
if (HAL_TIMEx_MasterConfigSynchronization(&htim4, &sMasterConfig) != HAL_OK)
{
return HAL_ERROR;
}
sConfigOC.OCMode = TIM_OCMODE_PWM1;
sConfigOC.Pulse = 500;
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
if (HAL_TIM_PWM_ConfigChannel(&htim4, &sConfigOC, TIM_CHANNEL_4) != HAL_OK)
{
return HAL_ERROR;
}
Now, with the above timing value unchanged, I will just configure the IC functionality. If I want to measure the frequency of a signal at PB7,
what will be the limitations?
2019-11-06 07:22 PM
Corrections: PWM signal of frequency around 16.5 KHZ is generated with the above timing parameter configurations.
2019-11-07 01:20 AM
> Now, with the above timing value unchanged, I will just configure the IC functionality. If I want to measure the frequency of a signal at PB7,
> what will be the limitations?
Without any additional "tricks", like what @S.Ma mentioned above, or counting separately the overflows in an interrupt or counting the overflows using another timer in master-slave arrangement (and both ways is rather tedious expecially when it comes to resolving events at the vicinity of the overflow), the capture is basically restricted by:
> htim4.Init.Prescaler = 5;
> htim4.Init.Period = 1000;
which means, for capture, maximum resolution (granularity) i.e. the minimum time difference resolvable is (5 + 1)*1/ftim, and the maximum period you can capture is (1000 + 1)*(5 + 1)*1/ftim (i.e. the minimum frequency of the captured input signal is 1/that), where ftim is the frequency of the timer input clock.
JW
2019-11-07 06:30 AM
Thanks @Community member
Since the two requirement are mutually exclusive i.e generating PWM at one time and input capture at another time .So I am planning to use below settings.
htim4.Init.Prescaler = 5;
htim4.Init.Period = 1000;
2. For Input capture, as per the intended freq range of the signal, I will change htim4.Init.Prescaler and htim4.Init.Period . I will switch between the these two Timing values as per the current functionality required i.e PWM output or Input Capture thing.
Please let me know if there are any restrictions or limitations with this?
2019-11-07 06:34 AM
That sounds good.
JW
2019-11-12 07:13 PM
Thanks. It worked.