Page 1 of 1

Adding Timer 2nd PWM channel breaks execution

Posted: Fri May 13, 2022 3:31 pm
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?

Re: Adding Timer 2nd PWM channel breaks execution

Posted: Fri May 13, 2022 9:21 pm
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 ?

Re: Adding Timer 2nd PWM channel breaks execution

Posted: Sat May 14, 2022 5:32 pm
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