Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The Prescaler and Period of the timer will need to be configured to meet the 50Hz. (period of 20ms) and 1ms to 2ms on-time (5-10% duty cycle) required to drive the motor.

The timer works as a counter, it counts up to the set counter period value before changing the output. The maximum number it can count to is 65535, or the maximum 2 byte number (uint16_t of 0xFFFF). The prescaler will slow down the system clock by dividing by (prescaler + 1) that way the speed is unaffected if prescaler = 0.

The equations based on the input clock speed are:

...

For this system the input clock speed is 48.0MHz. and the desired frequency is 50.0Hz.

Hint: A lower prescaler value with a higher counter period value will produce more accurate results.

Coding in STM32 Cube IDE

Once you have generated the code for the SPI and TIM (timer) configuration, you can find those values and setting will show up in the Core->Src directory in the project. Since you have configured those

...