I am trying to implement PID control with a heater controlled through a Solid State Relay (SSR). The process variable is the temperature measured using a type K thermocouple at the point of interest.The set point (temperature) can be controlled using a numeric control on the front panel.
The PID.vi output is given as a number between -100 and 100; this represents the percentage of ON/OFF for pulse width modulation (PWM). Essentially it tells you what percentage of the time a 1 or 0 is represented. If the output is 70, then the pulse will be ON 70% of the time and then OFF for 30% of the time for each cycle.
The output is not in a form that can be directly connected to the heater output, so PWM must be implemented. The heater is controlled through a SSR which is fed a digital signal (ON/OFF). Thus, we must convert the output to a digital signal.
For each iteration, I want to do the following:
- Calculate the OUTPUT using the subVI
- Create a loop that will send an ON signal to the SSR for a percentage of time and OFF signal the rest of the time
The following is an image of the VI I have created:
Pseudocode of the VI
- Ask for inputs
- Set Point
- PID Settings
- Output Range
- Total number of steps to run through (iterations the
forloop will run through)
- Calculate the number of iterations the digital signal will be ON by multiplying the number of iterations by the OUTPUT (%)
- for each iteration, if
i < (iterations * output), send ON to the SSR, otherwise send OFF
- Move on to the next Cycle
Using this process and implementing a quick step test, you get something like the following:
Clearly, the loop still needs to be tuned, but this is a good start! If you have any ideas on how to improve this method, please fork the code and try it yourself.