cancel
Showing results for 
Search instead for 
Did you mean: 

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

parth kothiya
Senior

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?

2 REPLIES 2
Piranha
Chief II
  • 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.

what is 15 & 21 in nPeriod equation?

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