We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi! I am a beginner in programming STM32f4 and that is my biggest problem, I think...
I am working now on the project where I need do profile the velocity of servo motor (i.e. trapezoidal velocity)... So I need to control the number of pulses I have sent and periodically update the frequency of signal...
So I have a question: Can I just change just: TIMx->ARR, PSC and CCRx registers in the PWM signal generator...? Or for example I must turn of timer first, and then update parameters...?
Thanks a lot for any hints, best regards,
P.S Have You any example projects of velocity profiling in C...? Or any tutorial of doing that on uC... Thanks again...
It's normal to have a one-pulse lag between reconfiguration and the change being seen on the output pin - since it isn't until the PWM has done one complete pulse period that it will latch in the new values to use for the next pulse period. And a pulse period is the combination of the time the pin is high and the time the pin is low.
If you are generating an analog value, then you normally have so high pulse frequency that this lag doesn't matter - you have a large number of very small pulses accumulating to the intended analog output value.
If you are controlling a motor, then the motor supports limited acceleration/deceleration. Which means that you can't make a large change in pulse frequency - so it normally doesn't matter if your source code is one pulse period ahead of what is seen on the pin.
Note that a traditional proportional regulator always has lag because when it get close enough the error difference will become so small. That's why there exists PID regulation where you can have one extra term allowing a quicker reaction when you need large steps, and then an integrating part that will give you a perfect match at times when there are no requested changes - the integration accumulates many small errors until it becomes large enough to react to.
So unless you are running at extremely slow pulse frequencies, you normally don't have to worry about the PWM output reacting one pulse period late compared to your configured values.