Naotake
Materials
- Nov 29, 2012
- 2
Dear All,
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:
Variables
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
Initialization
LOOP
According to you, could this be a functional implementation of a PID ?
Thanks for your replies,
Naotake
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.
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:
Variables
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
Initialization
Code:
[b]SP[/b] is set to the desired value
[b]MV[/b] is set to a value that is expected to yield an a close result for [b]PV[/b]
[b]previous_time[/b] is set to the current time
Waiting for 1 second
LOOP
Code:
[b]current_time[/b] is set to the current time
[b]PV[/b] is set to the value read on the sensor
[b]Error[/b] is set to (SP - PBV)
[b]dt[/b] is set to ([b]current_time[/b] - [b]previous_time[/b])
[b]integ[/b] is set to ([b]integ[/b] + [b]Error[/b]*[b]dt[/b])
[b]MV[/b] is set to [b]Kp*Error[/b] + [b]Ki*integ[/b] + [b]Kd*(Error / dt)[/b]
[b]previous_time[/b] is set to [b]current_time[/b]
Waiting 1 second
Repeating the loop
According to you, could this be a functional implementation of a PID ?
Thanks for your replies,
Naotake
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.