Adding Timer 2nd PWM channel breaks execution

Post here first, or if you can't find a relevant section!
Post Reply
el_fela
Posts: 2
Joined: Fri May 13, 2022 2:33 pm

Adding Timer 2nd PWM channel breaks execution

Post by el_fela »

Hi everyone, I'm struggling with the use of a 2nd or 3rd PWM channel on one timer.
CORE STM32 official, stm34f411ce6 (blackpill)

For example, the following code works:

Code: Select all

   HardwareTimer *htim2 = new HardwareTimer(TIM2);
   HardwareTimer *htim3 = new HardwareTimer(TIM3);

void setup()
{  
htim2->setPWM(1, PA5, 272.25, 50);
htim3->setPWM(1, PA6, 50000, 25); 
}

void loop() {  
  htim2->setOverflow(227272, TICK_FORMAT);
  delay(2000);
  htim2->setOverflow(427272, TICK_FORMAT);
  delay(2000);
}
but if I add " htim3->setPWM(3, PB0, 50000, 25);" , the execution stops at that line. Example code:

Code: Select all

   HardwareTimer *htim2 = new HardwareTimer(TIM2);
   HardwareTimer *htim3 = new HardwareTimer(TIM3);

void setup()
{  
htim2->setPWM(1, PA5, 272.25, 50);
htim3->setPWM(1, PA6, 50000, 25); 
htim3->setPWM(3, PB0, 50000, 25); 
}

void loop() {  
  htim2->setOverflow(227272, TICK_FORMAT);
  delay(2000);
  htim2->setOverflow(427272, TICK_FORMAT);
  delay(2000);
}
I really need that channel! IT works fine on STM32CubeIDE, I'm using the same pins. What can I do?
by ABOSTM » Fri May 13, 2022 9:21 pm
Hi @el_fela ,
According to Blackpill Timer pin mapping PinMap_TIM[] , PB0 (or PB_0) is by default assigned to TIM1_CH2N :
https://github.com/stm32duino/Arduino_C ... 11CE.c#L99

In order to use TIM3_CH3 you should use PB0_ALT1 (or PB_0_ALT1)
https://github.com/stm32duino/Arduino_C ... 1CE.c#L100

Can you try to use PB0_ALT1 ?
Go to full post
ABOSTM
Posts: 60
Joined: Wed Jan 08, 2020 8:40 am
Answers: 7

Re: Adding Timer 2nd PWM channel breaks execution

Post by ABOSTM »

Hi @el_fela ,
According to Blackpill Timer pin mapping PinMap_TIM[] , PB0 (or PB_0) is by default assigned to TIM1_CH2N :
https://github.com/stm32duino/Arduino_C ... 11CE.c#L99

In order to use TIM3_CH3 you should use PB0_ALT1 (or PB_0_ALT1)
https://github.com/stm32duino/Arduino_C ... 1CE.c#L100

Can you try to use PB0_ALT1 ?
el_fela
Posts: 2
Joined: Fri May 13, 2022 2:33 pm

Re: Adding Timer 2nd PWM channel breaks execution

Post by el_fela »

Hello @ABOSTM , thank you sooo much! That was it!

I didn't know PB0_ALT1 was different from PB0, that seemed kinda confusing. But now I'll keep the pinmap information at hand.

Thanks again!!! :D
Post Reply

Return to “General discussion”