Skip to main content
Visitor II
December 24, 2024
Solved

PWM no signal on TIM2 Channel1 and TIM3 Channel 1

  • December 24, 2024
  • 4 replies
  • 1517 views

I want to generate 6 PWMs using channel 1 of timers 1,8,2,3,4,5. All of them are set the same way except ARR, PSC and CCR1 registers. However, it turned out that timers 2 and 3 don't have PWM signal on their pins. The content of registers for those timers are the same (checked during debugging). I also tried to initialize timers by writing directly to registers, with no luck. MCU: STM32F103RCT6. Here is the the initialization for timer 3, for example:

	// ------------------------- PA6 settings ------------------------- //
	RCC->APB2ENR |= RCC_APB2ENR_IOPAEN;		// Port A clock (PA6 - TIM3_CH1)
	GPIOA->CRL |= GPIO_CRL_MODE6; 			// PA6 speed MAX
	GPIOA->CRL &= ~GPIO_CRL_CNF6_0;			// Alternate function Push-Pull
	GPIOA->CRL |= GPIO_CRL_CNF6_1;
	// ------------------------- TIM3 settings ------------------------- //
	RCC->APB1ENR |= RCC_APB1ENR_TIM3EN; 	// TIM3 clock
	TIM3->CCMR1 &= ~TIM_CCMR1_OC1M_0;	// PWM mode 1
	TIM3->CCMR1 |= TIM_CCMR1_OC1M_1;
	TIM3->CCMR1 |= TIM_CCMR1_OC1M_2;
	TIM3->CCMR1 |= TIM_CCMR1_OC1PE;	 // enable preload register
	TIM3->CR1 |= TIM_CR1_ARPE;		// enable auto-reload preload register
	TIM3->EGR |= TIM_EGR_UG;	 // generate an update
	TIM3->CCER &= ~TIM_CCER_CC1P;	 // polarity: active HIGH
	TIM3->CCER |= TIM_CCER_CC1E;		// Output signal enable
	TIM3->ARR = 11999; 			// period
	TIM3->CCR1 = 5999;			// pulse %
	TIM3->PSC = 1; 				// prescaler
	TIM3->CR1 |= TIM_CR1_CEN; 		// PWM on

 I tried another STM32F103RCT6, but behaviour is the same. Is that hardware issue inside the MCU? 

    This topic has been closed for replies.
    Best answer by waclawek.jan

    Unlike every other STM32, the 'F1 GPIO is not flexible, and you cannot have multiple peripherals which map to the same pin enabled at the same time.

    Here, the conflict is probably with SPI1.

    JW

    4 replies

    ST Employee
    December 25, 2024

    Hello @Dan_Ko, welcome to ST community, 

    The issue could be that it's needed to remap the alternate function by software to different port pins, because by default PA6 for example is connected to TIM8_BKIN/ADC12_IN6 

    SarraS_0-1735120404332.pngSarraS_1-1735120415925.png

     

     

    Dan_KoAuthor
    Visitor II
    December 25, 2024

    Hello Sarra,

    If I set up TIM3 using CubeMX, should not it be remapped by default?

    image.png

    Super User
    December 26, 2024

    Unlike every other STM32, the 'F1 GPIO is not flexible, and you cannot have multiple peripherals which map to the same pin enabled at the same time.

    Here, the conflict is probably with SPI1.

    JW

    Dan_KoAuthor
    Visitor II
    January 16, 2025

    I disabled SPI and it worked. Thank you very much for your help! CubeMX seems confusing in that sense because it does not indicate any conflict when I enable SPI in transmit-only mode and want to use MISO pin for different purpose. Is that property of F1 series stated somewhere in datasheet or RM, so I can read about it?

    Super User
    January 16, 2025

    Sorry, I don't know.

    I was just guessing above. I don't use the 'F1.

    JW