Hi, I want to control the speed of a conveyor belt. I can measure the linear velocity of the belt using a encoder mounted at the roller of the belt. My confusion is not with the PID but only the mapping of PID output to PWM for the motor.

The PID error is in terms of meter/seconds(m/s) of the conveyor belt. The P, I and, D parts are summed to give a control signal. The motor interprets 0 as 0 PWM and 16393 as 100% PWM. The range from 0 to 16393 is serially communicated to the motor. I want this to be from the PID.

My question is: How do I map the PID output based on error(m/s) to PWM for the motor.

Example: I am using just PI and ignoring D for now to avoid noise amplification issues.

The maximum speed of the belt is when 16393 is sent to it and the speed is 0.5 m/s. I set desired speed as 0.2 m/s,

At the start, error = 0.2 m/s Lets say Kp = 4, Ki = 2.

output = Kp * error + Ki * sum_of_errors * sampling_time

I would get a PID output but it would be very small compared to 16393 needed for the 100 % PWM for the motor. I need 100 % PWM to power motor in the start and gradually decrease the PWM as the belts speed goes from 0 m/s to 0.2 m/s. How can I map this small PID output to 16393 need for the Motors 100 % PWM?


1 Answer 1


Convert your PWM units to belt velocity units, or vice-versa. The quick and dirty way of doing this is to multiply your P, I, and D terms by $16,393 \over 0.5$. The PWM-to-belt velocity mapping won't be exactly linear, like this method assumes, but it will be close enough that your controller can squash any residual errors.

Caution: since you are controlling the velocity of the belt, in which the speed of the conveyor is sure to lag behind the speed of your control input, you should consider setting your I gain to 0 until you are "close" to the desired speed. Otherwise that windup will induce overshoot in your conveyor speed.

  • $\begingroup$ thank you, its clear :), i get the following graph with the suggestion you made, any idea about the cause of these strange oscillations? I tried varying the gains but these strange oscillations don't go away. link $\endgroup$ Commented Sep 8, 2017 at 22:29
  • 1
    $\begingroup$ It is hard to tell what the cause is from that graph. It could be cyclical varying friction from the conveyor, but it is more likely your gains. Learn how to tune using the Ziegler-Nichols method and I bet the performance will be remarkably better. $\endgroup$
    – SteveO
    Commented Sep 9, 2017 at 0:15
  • $\begingroup$ Hi SteveO, I did the mapping as you suggested and the speed control works but there is one confusion. If I make Kp gain 0 and only have Ki gain, everything is fine and if I give even a small Kp like 0.1, the belt starts oscillating. I tried varying Ki and Kp but the best result I get is with just the I part active. So essentially an I controller. Any idea what might be causing such an unusual behavior? I am clueless tbh $\endgroup$ Commented Sep 12, 2017 at 20:07
  • $\begingroup$ If your control loops are implemented correctly, and the friction of the conveyor is reasonable, there has to be a range of P values that drive the conveyor's speed to the target value, in which a lower P value results in slower closure to the target. Since the conveyor oscillated when I was 0 and P gain was 0.1, try P values of 0.01, then 0.001, etc., until you see the controller respond appropriately. We've gotten past your initial question, so if you have further questions you should post them as new items. $\endgroup$
    – SteveO
    Commented Sep 12, 2017 at 20:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.