Sign in to follow this  
RLidster

Pid And Pwm To Control Temperature

Recommended Posts

Hi There

 

I'm a bit of a novice and i am aware that parts of the title of this post are featured in a few others but i don't quite understand how to bring everything together with my example...

 

My current setup is a; 

 

Temp probe (EI-1034) connected to a labjack U3 (AIN0) (channel = tempprobe)

Solid state relay control set as dig out on FIO4 - (Channel = relay)  logic low  = off (0), Logic High = On (1)

 

What i would like to do is power a heater using the SSR but use PWM and a PID loop to control the temperature of a box. I.e Vary the power to the heater by PWM of the SSR which in turn is controlled by a PID loop with the Temp probe and a temperature setpoint.

 

Thanking you in advance!

 

Best regards

 

Rich

Share this post


Link to post
Share on other sites

You've got basically two parts here: the PID loop and the PWM.  What you'll want to do is create a PID loop with the appropriate Process Variable (your temp probe) and set point (probably a variable?) and then have the output range from -100 to 100 and go to a global variable.  That completes the PID part.  Then create a sequence that loops at the same rate as the PID (default is once per second) and looks at the variable you created to hold the output of the PID and controls the SSR accordingly, where -100 = 0% PWM and 100 = 100% PWM.  The PWM you can either do using LabJack's built in PWM functionallity, and there are samples that show how to do that, or, if your system is on the slower side and a perfect PWM is not required, you can do it in script.  The script is pretty straightforward (assuming PIDOut is the global variable for your PID output, and SSR is the FIO4)

 

private PIDLoopTime = 1  // the interval the PID updates (a setting in the PID)

while(1)

   switch

      case (PIDOut < -95)

         SSR = 0

         delay(PIDLoopTime)

      case (PIDOut > 95)

          SSR = 1

          delay(PIDLoopTime)

      default

          SSR = 1

          delay((PIDOut + 100) / 200 * PIDLoopTime)

          SSR = 0

          delay(1 - (PIDOut + 100) / 200 * PIDLoopTime)

   endcase
endwhile
 
The switch is required to avoid a rapid toggle at the extremes.  If we didn't do that, then if the PID calls for all on or all off, then then the logic under "default" will quickly toggle the SSR, i.e. if it calls for 100% it will run the SSR for one second then turn it off for a millisecond then turn it back on again.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this