2023-01-04 06:30 PM
I am trying to Trigger timer 15 from timer 1....Yellow in scope pic shows timer 1 output to be used as gated trigger... I am trying to get PWM gated out of Timer 15....
Can anyone tell me what I am doing wrong in the code bcz I get no PWM out of PA2?
CONFIGURATION:
htim15.Instance = TIM15;
htim15.Init.Prescaler = 20 - 1;
htim15.Init.CounterMode = TIM_COUNTERMODE_UP;
htim15.Init.Period = 10;
htim15.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim15.Init.RepetitionCounter = 0;
htim15.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;
if (HAL_TIM_Base_Init(&htim15) != HAL_OK)
{
Error_Handler();
}
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
if (HAL_TIM_ConfigClockSource(&htim15, &sClockSourceConfig) != HAL_OK)
{
Error_Handler();
}
if (HAL_TIM_PWM_Init(&htim15) != HAL_OK)
{
Error_Handler();
}
sSlaveConfig.SlaveMode = TIM_SLAVEMODE_GATED;
sSlaveConfig.InputTrigger = TIM_TS_ITR0;
if (HAL_TIM_SlaveConfigSynchro(&htim15, &sSlaveConfig) != HAL_OK)
{
Error_Handler();
}
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
if (HAL_TIMEx_MasterConfigSynchronization(&htim15, &sMasterConfig) != HAL_OK)
{
Error_Handler();
}
sConfigOC.OCMode = TIM_OCMODE_PWM1;
sConfigOC.Pulse = 2;
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH;
sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET;
sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET;
if (HAL_TIM_PWM_ConfigChannel(&htim15, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)
{
Error_Handler();
}
sBreakDeadTimeConfig.OffStateRunMode = TIM_OSSR_DISABLE;
sBreakDeadTimeConfig.OffStateIDLEMode = TIM_OSSI_DISABLE;
sBreakDeadTimeConfig.LockLevel = TIM_LOCKLEVEL_OFF;
sBreakDeadTimeConfig.DeadTime = 0;
sBreakDeadTimeConfig.BreakState = TIM_BREAK_DISABLE;
sBreakDeadTimeConfig.BreakPolarity = TIM_BREAKPOLARITY_HIGH;
sBreakDeadTimeConfig.AutomaticOutput = TIM_AUTOMATICOUTPUT_DISABLE;
if (HAL_TIMEx_ConfigBreakDeadTime(&htim15, &sBreakDeadTimeConfig) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN TIM15_Init 2 */
/* USER CODE END TIM15_Init 2 */
HAL_TIM_MspPostInit(&htim15);
FUNCTION CALL:
HAL_TIM_PWM_Start(&htim15, TIM_CHANNEL_1);
Thanks
2023-01-05 12:14 AM
Read out and check/post both TIM and the relevant GPIO registers' content.
JW
2023-01-05 05:31 AM
Timer15 registers:
Timer1 registers:
Port A Timer15 output:
2023-01-07 12:17 AM
I don't see TIM15_SMCR. Is this from CubeIDE?
JW
PS.
@Imen DAHMEN , can you please check why is there not TIM15_SMS in STM32L476 in CubeIDE's registers view? Thanks.
2023-01-07 12:30 AM
The main problem most likely is, that in TIM1 you've selected Update as TRGO source in TIM1_CR2.MMS. Update event is only one clock wide, so that generates a very short pulse on TRGO, you can't use that as source for Gate in TIM15.
You need to configure one of the channels in TIM1 as Compare (PWM), to generate a relatively wide pulse, and use that as TRGO.
(Btw. I also don't understand why did you set TIM1_RCR=1, but in this case it should be harmless).
JW
2023-01-09 01:47 PM
Thank you for the response....The RCR is because ultimately I want a 20 minute delay per trigger event...I was testing the RCR portion as well....I will look into making PWM compare out as you said when I get the opportunity.....