STM32f407vet6 blackboard malfunctional PWM

lobivan
Posts: 7
Joined: Wed Oct 21, 2020 3:06 pm

Re: STM32f407vet6 blackboard malfunctional PWM

Post by lobivan »

stevestrong wrote: Thu Oct 22, 2020 12:06 pm Timerx.setPeriod() is necessary if you want to output PWM signal with a specific period, not identical with your case (maximum resolution 65535).
Do you know how to init different channels of timers? It can barely activate half of the pwm pins with that code and aditional LED. It seems I am missing smth, but this code works almost wit every timer except TIM2:

Code: Select all

volatile bool LEDOn13 = 0;

void setup()
{
  pinMode(PE2, OUTPUT);
  Timer4.init();
  Timer4.setPrescaleFactor(720);
  Timer4.attachInterrupt(TIMER_UPDATE_INTERRUPT, func_tim_3);
  Timer4.refresh();
  Timer4.resume();
}

void loop() 
{}

void func_tim_3()
{
  digitalWrite(PE2, (LEDOn13 = !LEDOn13));
} 
stevestrong
Posts: 502
Joined: Fri Dec 27, 2019 4:53 pm
Answers: 8
Location: Munich, Germany
Contact:

Re: STM32f407vet6 blackboard malfunctional PWM

Post by stevestrong »

It is important to set pin mode after timer init.
Then it is recommended to attach interrupt after refresh, otherwise the interrupt will be fired by refresh.
Which timer 2 pin does not work?
Timer 5 was preferred over timer 2, but you can change this by editing the mapping table.
lobivan
Posts: 7
Joined: Wed Oct 21, 2020 3:06 pm

Re: STM32f407vet6 blackboard malfunctional PWM

Post by lobivan »

stevestrong wrote: Thu Oct 22, 2020 12:42 pm It is important to set pin mode after timer init.
Then it is recommended to attach interrupt after refresh, otherwise the interrupt will be fired by refresh.
Which timer 2 pin does not work?
Timer 5 was preferred over timer 2, but you can change this by editing the mapping table.
I've found out that functional timers are TIM1, TIM3, TIM4, TIM8. None of TIM2 or TIM5 pins work. I've also found out that PWM attached to TIM1,TIM2, TIM5 and TIM8 don't work either (I've checked every PWM pin on the right of the board). While I was checking, I've found out that when you start a timer, some pins not referring to it begin having voltage (for example, PB7 has voltage also on PB3, PA2 has voltage on PB1). So there is a possibility that my board has a defect and this issue is only mine
mrburnette
Posts: 633
Joined: Thu Dec 19, 2019 1:23 am
Answers: 7

Re: STM32f407vet6 blackboard malfunctional PWM

Post by mrburnette »

lobivan wrote: Wed Oct 21, 2020 3:22 pm Hello, everyone. I've bought a STM32f407vet6 blackboard from China. It seems to work mostly well when speaking about digital inputs and outputs, but I have problems with the PWM,
...

For readers of this thread who may be inclined to buy one (1) board from China - do not. Buy at least two (2) because you will have to do your own hardware support. I do not know how many times I can say it, but Quality Assurance for Chinese board manufacturers is problematic.

Better still, buy your first hardware directly from STM as a Discovery or Nucleo board; the pricing may be a bit more, but you are supporting a quality product that is supported. Then, after testing code and sensors and peripheral devices, go ahead and make your own board or order from China... you will still have to support your hardware, but you have the STM factory board to fall back on if you need to test hardware. It is a sensible solution, IMO, and will avoid much frustration.

Ray
Post Reply

Return to “STM32F4 based boards”