PID library not working

Hi:

I'm running the basic PID example:

http://playground.arduino.cc//Code/PIDLibaryBasicExample

but for some reason is not controlling the output to 100. It shows 0 on almost all the scale of the potentiometer. The only time when it shows some value is nearby zero and the the value begins to increase until it reaches 255.

What could be wrong?

Are you running the sketch exactly as shown in that page you linked to?

What external hardware have you got connected?

What behaviour are you expecting to see if it works correctly?

Gilgamesh90: Hi:

I'm running the basic PID example:

http://playground.arduino.cc//Code/PIDLibaryBasicExample

but for some reason is not controlling the output to 100. It shows 0 on almost all the scale of the potentiometer. The only time when it shows some value is nearby zero and the the value begins to increase until it reaches 255.

What could be wrong?

Sounds like you may not be getting a valid value for the pot input. How have you wired it up? Inserting some timely and well positioned serial print statements might tell you something.

Inserting some timely and well positioned serial print statements might tell you something.

I prefer the phrase "sprinkle some serial prints around"...

Sounds like you may not be getting a valid value for the pot input. How have you wired it up? Inserting some timely and well positioned serial print statements might tell you something.

I think it is wired correctly. One pin of the pot is connected to 5V and, the other to Ground and the central is connected to A0.

I'm getting the input and output values with serial print so I'm 100% sure the pot is being read correctly.

Are you running the sketch exactly as shown in that page you linked to?

What external hardware have you got connected?

What behaviour are you expecting to see if it works correctly?

1.- Yes, I'm running the very same sketch.

2.- No external hardware is connected.

3.- I would be expecting a value of 1.96V on the pin3

To be honest I don't think this code is correct because the error is always the same. Has anyone got this code to work correctly?

3.- I would be expecting a value of 1.96V on the pin3

How would you or are you trying to read the output voltage on pin 3 ? A digital voltmeter will not accurately read a PWM signal unless you first past the signal through a low pass filter.

Lefty

Gilgamesh90: 3.- I would be expecting a value of 1.96V on the pin3

That's not going to happen, because it's only going to produce a LOW or HIGH output. I suspect you've misunderstood what the sketch does. I also suspect that what the sketch does is pretty useless, since there is no mechanism to connect the output to the input so the control algorithm is not actually running a closed loop - unless you manage to get the input to stop at exactly the target value, I'd expect the output to apply more and more correction until it hits one extreme or the other of the output range. This doesn't tell you anything useful about PID except how to compile a sketch using it, as far as I can see.

We had thousands of PID controllers in the refinery I worked at before retirement. The output 'value' of a PID controller was almost always expressed as a percentage output, normally with a full 0-100% range. The output signal might manipulate a control valve where 0% = fully closed and 100% = fully opened. That would also apply to a speed controller where 0% = stopped and 100% maximum rpm that the controller/motor can attain. The PID library has the means to place limits both low and high on the output signal value, so that no matter how large the error the output signal would be constrained between those limits. If one is using pwm as the output signal then it's limits should be set to 0 and 255. The PID will force the output higher or lower in attempt to force the setpoint = the input signal.

To see a PID control work there must be a physical connection to something that can control the process variable and a input back from the process to measure the process variable.

One simple test to witness the PID calculations working without having real world input and output connections, is to use a pot input as the desired setpoint and wire a fixed mid-range voltage (2.5vdc) to the analog input pin (if that is indeed the process variable input). Then hook a scope to the pwm pin and as you adjust the setpoint pot above and below mid travel you should see the output signal go from one extreme (0%) to the other extreme (100%).

Lefty

How would you or are you trying to read the output voltage on pin 3 ? A digital voltmeter will not accurately read a PWM signal unless you first past the signal through a low pass filter.

In that you're wrong. At least with my multimeter I'm able to measure PWM output accurately.

I also suspect that what the sketch does is pretty useless, since there is no mechanism to connect the output to the input so the control algorithm is not actually running a closed loop

Yes, I think so.

So the PID is going to have the same importance that the PWM conversion, right?

In that you're wrong. At least with my multimeter I'm able to measure PWM output accurately.

Must be a higher cost true RMS multimeter in that case? Have a link?

http://www.steren.com.mx/catalogo/prod.asp?f=8&sf=128&c=1143&p=2464

Is in Spanish (didnt find it in English). Hope this works.