2024-09-15 02:41 PM
Hi,
as you can see from the screenshot below I have TIM2 clock source set to disable but the PWM is still running as configured and generates PWM. And it has been like that for the entire project for a while so I just noticed.
Does the time start function automatically select the source to some default like the Internal clock? Or is that Clock source referring to something else? Just asking because I want to make sure the code is running correctly for the right configuration not because of some other settings that somehow override these.
Thank you
Solved! Go to Solution.
2024-09-16 03:36 AM
Hello,
When Clock source is disabled, HAL_TIM_ConfigClockSource() is not generated and when "Internal Clock" is selected, the following code is generated:
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
if (HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig) != HAL_OK)
{
Error_Handler();
}
And according to HAL_TIM_ConfigClockSource() implementation TIM_CLOCKSOURCE_INTERNAL does almost nothing, just some bit reset before:
/* Reset the SMS, TS, ECE, ETPS and ETRF bits */
tmpsmcr = htim->Instance->SMCR;
tmpsmcr &= ~(TIM_SMCR_SMS | TIM_SMCR_TS);
tmpsmcr &= ~(TIM_SMCR_ETF | TIM_SMCR_ETPS | TIM_SMCR_ECE | TIM_SMCR_ETP);
htim->Instance->SMCR = tmpsmcr;
switch (sClockSourceConfig->ClockSource)
{
case TIM_CLOCKSOURCE_INTERNAL:
{
assert_param(IS_TIM_INSTANCE(htim->Instance));
break;
}
So "Internal Clock" and "Disable" seems to have the same behavior.
2024-09-16 03:36 AM
Hello,
When Clock source is disabled, HAL_TIM_ConfigClockSource() is not generated and when "Internal Clock" is selected, the following code is generated:
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
if (HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig) != HAL_OK)
{
Error_Handler();
}
And according to HAL_TIM_ConfigClockSource() implementation TIM_CLOCKSOURCE_INTERNAL does almost nothing, just some bit reset before:
/* Reset the SMS, TS, ECE, ETPS and ETRF bits */
tmpsmcr = htim->Instance->SMCR;
tmpsmcr &= ~(TIM_SMCR_SMS | TIM_SMCR_TS);
tmpsmcr &= ~(TIM_SMCR_ETF | TIM_SMCR_ETPS | TIM_SMCR_ECE | TIM_SMCR_ETP);
htim->Instance->SMCR = tmpsmcr;
switch (sClockSourceConfig->ClockSource)
{
case TIM_CLOCKSOURCE_INTERNAL:
{
assert_param(IS_TIM_INSTANCE(htim->Instance));
break;
}
So "Internal Clock" and "Disable" seems to have the same behavior.