Implementing a PID
Implementing a PID
I am a researcher scientist who knows nothing about PID except from what I did read on this forum and on a few sources from the web these past two weeks. For my research, I need to program a PID and I am seeking help to write the algorithm.
Here's what I am planning to do:
SP => requested output for A
PV => actual output of A measured by a sensor
MV => actual value applied to A's input
current_time => value of a timer at the start of the current loop
previous_time =>value of the timer a the start of the previous loop
Kp, Ki, Kd => pid configuration constants
integ => integration storage variable
Before starting the PID:
MV is set to 0 so the output of A is 0 and the measured value (PV) is also 0.
Kp, Ki, Kd are user-defined
SP is set to the desired value MV is set to a value that is expected to yield an a close result for PV previous_time is set to the current time Waiting for 1 second
current_time is set to the current time PV is set to the value read on the sensor Error is set to (SP - PBV) dt is set to (current_time - previous_time) integ is set to (integ + Error*dt) MV is set to Kp*Error + Ki*integ + Kd*(Error / dt) previous_time is set to current_time Waiting 1 second Repeating the loop
According to you, could this be a functional implementation of a PID ?
Thanks for your replies,
More informations on the process
I need to control a process (let's call it A) that has the usual characteristics. A takes an input (MV) and provides an output (PV) that should ideally be equal to MV. PV is measured by a sensor.
When changing MV, the response of A is immediate, but because of the sensor's characteristics, it can take from 1 to 30 seconds for PV to reach a stable value (30 seconds for really extreme changes on MV).
Unfortunately, thought the process's (A) response is immediate, there is a small decrease in time of its output after a change in MV (typically less than 10%). This evolution (drift) takes place over the course of 5-10 minutes and is proportional to the difference between the previous value of MV and the new one. So the moment this is the most noticeable is when the PID has just been started, and when the operator requests a new set point.