Skip to main content
cpc
Associate II
September 23, 2019
Question

SPI is triggering PWM

  • September 23, 2019
  • 4 replies
  • 1198 views

Hi,

I am using STM32l072CZYx. I am generating the PWM using timer 3 channel 2. But PWM is getting trigger by SPI, PWM is resetting for some time. When I disabled the SPI, I am getting exact PWM.

What will be the reason?

What can be done to avoid such thing?

This topic has been closed for replies.

4 replies

cpc
cpcAuthor
Associate II
September 24, 2019

IS there any update?

void MX_TIM3_Init(void)
{
	__HAL_RCC_TIM3_CLK_ENABLE();
 
	 TIM_ClockConfigTypeDef sClockSourceConfig = {0};
 
	 htim3.Instance = TIM3;
	 htim3.Init.Prescaler = 320;
	 htim3.Init.CounterMode = TIM_COUNTERMODE_UP;
	 htim3.Init.Period = 100;
	 htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
	 htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
	 HAL_TIMEx_RemapConfig(&htim3,TIM3_TI2_GPIOB5_AF4);
	 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();
	 }
 
	 sConfigOC.OCMode = TIM_OCMODE_PWM1;
	 sConfigOC.Pulse = 50;
	 sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
	 sConfigOC.OCFastMode = TIM_OCFAST_ENABLE;
 
	 if (HAL_TIM_PWM_ConfigChannel(&htim3, &sConfigOC, TIM_CHANNEL_2) != HAL_OK)
	 {
	 Error_Handler();
	 }
}

this is timer initialization.

Any external event is affecting the PWM.

I am using LoRa as well.

what is missing in this?

waclawek.jan
Super User
September 24, 2019

Shorts between SPI and TIM pins?

Unstable power resetting MCU?

JW

cpc
cpcAuthor
Associate II
September 25, 2019

No there is no short between timer and SPI pins. I have also tried using another timer on another pin but same issue.

Is my timer configuration correct?

Am I missing something?

waclawek.jan
Super User
September 25, 2019

I don't use Cube, but as long as you set a timer to generate PWM and then don't touch its registers, and unless it's in one-pulse mode, it should tick regularly to infinity.

JW