Skip to main content
parth kothiya
Associate III
January 12, 2022
Question

TIMER PWM mode driving stepper motor how to soft start or acceleration time?

  • January 12, 2022
  • 1 reply
  • 3110 views

i am driving STEPPER MOTOR using TIMER in PWM mode use interrupt for counting PULSES

now how can i accelerate motor slowly(acceleration time 200ms) then running at set speed?

acceleration time(ex 200ms) is variable how can i do it? Can iuse dma for very frequency?

This topic has been closed for replies.

1 reply

Piranha
Principal III
January 13, 2022
  • Set output channel to PWM mode 1 and set CCR for an active pulse width.
  • Set timer to a downcounting mode and do not enable ARR preload.
  • Use update interrupt to count full steps and adjust speed by modifying ARR.
  • Use repetition counter for micro-steps, if necessary.
  • At initialization and after stopping the counter, set the CNT to a value of CCR + 1 so that output is inactive and, when starting, timer doesn't have to do useless downcounting before the first pulse.

ARR period can be recalculated as follows:

nPeriod = (nPeriod * 15) / 16; // Acceleration
nPeriod = (nPeriod * 21) / 16; // Deceleration

Of course you have to replace the ratio constants with your specific ones. Just take a note that the divider is recommended to be a power of 2, as that will be optimized to a simple and fast bit shift instruction.

parth kothiya
Associate III
January 17, 2022

what is 15 & 21 in nPeriod equation?

nPeriod value 16bit ? it is full pulse value ON+OFF time (50% duty)?