Articles Hierarchy

Articles Home » RPI » RPI operates ARDUINO PID control

RPI operates ARDUINO PID control


loop check, control start up and TUNING
-.1- what is PID
it is a BOX with a mathematical model with 2 inputs
- PV ( process value / our Temperature )
- SP ( setpoint from poti in AUTO or from RPI in RSP mode )
and one output
- OUT ( 0 .. 100% ) here send to a servo
and even we use computer / numeric calculation it is
ANALOG ( and could have been build with one operation amplifier and some components )
in our case it is actually only a 2 line code in arduino


d = SP - PV

OUT = GAIN * d + RESET * ( iOLD + d ) + RATE * ( d - dOLD )



there are 2 memory variables
- iOLD
- dOLD
what makes that box smart and we have already 3 tuning variables
- GAIN
- RESET
- RATE
add there is a
- PIDaction ( 1 or -1 )
and outside the BOX a
- OUTPUT INVERT ( 1 or -1 )
and also outside / prior to the BOX is a PV filter installed
- PV = PVOLD * PVfil0 + PV(input) * PVfil1
with PVfil0 + PVfil1 = 1

for the PID / BOX this PV filter is part of the process, like the output invert and the valve and the real process and the sensor and sampling...
thinking in a CLOSED LOOP


-.2- open loop / closed loop
now when control is in AUTO or RSP the loop is closed.
when you now look at the trend of PV, SP, OUTPUT there is no way to know what is responsible for what.
if you want tune the PID parameter you first have to operate
the open loop ( MAN ) and learn how the field ( or better OUTSIDE of the PID BOX ) reacts.

-a- if the OUTPUT is 75% the valve must be open 75%
and not 25%, if you have a increase close valve like i build here you need to invert the output tuning first

-b- if you now change in MAN the output you can see a PV reaction
that is the combination of your real process AND the PV filter
i have seen that this confuses most of the "TUNERS"
and i consider the filter tuning as more critical as the PID parameter.
while testing sensor ... and the PV is jumpy you tend to filter stronger.
later when you tune the PID you want to make it faster, but it does not work!!!
and as the real temperature might be higher as the filtered indicated value already product got damaged.

-c- there is NO WAY a PID can be faster as the PV reacts on a MAN OUTPUT 0 to 100% jump!
that is called process identification ( and that includes the PV filter tuning!
now later in the real world you might not be able to do that 0 ..100% output jump
( because the product got damaged or even the plant might burn down )
so you have to learn to identify the field by a smaller output step.

-d- now we adjust the output in MAN so that the
PV is near to the setpoint, that we adjusted to our requirements .
if you can not do that something is basically wrong
and also a PID AUTO will not help.
( check valve moves, heater is on, sensor works ...)

-e- and now we think / or we test / what the control does when its in AUTO
we need to tell the PID how to work "as HEATER or COOLER" and adjust PIDaction
so the PV will follow the SP after a small SP change. If the PV goes to the opposite direction change it.
now here is a funny thing: if PIDaction and OUTPUT INVERT are both wrong, PID will work! BUT the indicated valve position is wrong.
i see that hundred of times, a very confusing thing.

-f- and only after all above works you can start playing with the PID parameter GAIN RESET RATE.

above PV reaction on a output change already gives you a feeling for your process,
actually it can be analyzed mathematically according several methods to find good PID parameter,
that is called auto tuning... but its to early for that here.

i want to mention a old RULE i learned
( still on analog control boxes with potis for tuning... )

- start with a P control ( I ( reset ) and D ( rate) = 0 )
- - increase the P ( gain) until PV can catch SP.
- - increase if further until the PV ( and output ) starts swinging,
- - and now reduce P to 1/2 of its setting
- and increase I ( reset ) until the PV catch SP in a acceptable time and not with too much swinging "over" the SP.

that should be tested in several working points ( if possible)


the D ( rate ) is often considered as a tool ( help ) to react fast on influences / disturbances on the process ( PV ) from the outside.
But there are processes what require definitely a rate tuning.

Actually tuning know how is less important as process know how, i admire that process engineers ( like in chemical plants ) what sit and stare at the current trend for 3 days ( without any of the above necessary SP changes i would need to check if my tuning change worked ) and then they change the parameters.
And only in case of a change of working point ( like plant throughput increase ) they need to do it again.


as this little project was about a (one) PID control in UNO/Leonardo/ProMicro/
and operation from RPI ( or WIN 7 PC )
now i want go back to the bigger brother, the uPCS project.