I don't think you are understanding. Here is a very summarized pseudo-code of what I do:If the motor speed is too slow the PID loop should set the duty-cycle to the maximum value, not the minimum.
I don't understand why it's setting it to the minimum?
Sounds like you have the PID signal phase reversed from what it should be.
...
output = kp*erro + ki*i_term + kd*d_term;
duty = abs(output);
if (duty > 0 && duty < 30000) duty = 30000; //this is the line of code i'm talking about
//30000 is the minimum OCR value to make the motor rotate (30000/65535)*100% = 45%
if (duty > 65535) duty = 65535;
OCR1A = duty;
Like I said this is a very summarized version of the code and I skip many steps but neither the output or duty variables are used in those steps I skiped.
The problem is not the PID code because I've asked an automation engineer to look at it and he said that is correct except the part where I set the duty cycle as 30000 when the PID output is lower than duty cycle (the line of code we are talking about) and that it should be exactly the output of the PID controller, but if the motor doesn't move I can do what I'm doing (wich is a poor solution) but the minimum value can't be 30000, is too high. From the research I made the minimum value should 10% duty cycle or lower for a proper control but I can't make the motor move for values that low. The engineer didn't know aswell why the motor needs such a high duty cycle.
My guess would be that it can't overcome the friction from the gearbox but I don't know how to solve it.