Skip to main content
SWenn.1
Senior III
January 5, 2023
Question

TRGO Timer1 to ITR0 Timer 15? Nucleo-L476

  • January 5, 2023
  • 5 replies
  • 1791 views

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?

0693W00000Y7RgOQAV.jpgCONFIGURATION:

 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

This topic has been closed for replies.

5 replies

waclawek.jan
Super User
January 5, 2023

Read out and check/post both TIM and the relevant GPIO registers' content.

JW

SWenn.1
SWenn.1Author
Senior III
January 5, 2023

Timer15 registers:

0693W00000Y7UdDQAV.png 

Timer1 registers:

0693W00000Y7UdSQAV.pngPort A Timer15 output:

0693W00000Y7UeBQAV.png 

waclawek.jan
Super User
January 7, 2023

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.

waclawek.jan
Super User
January 7, 2023

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

SWenn.1
SWenn.1Author
Senior III
January 9, 2023

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.....