RLidster

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

Link to comment
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.
Link to comment
Share on other sites

  • 6 years later...

It is supposed to do that because it is designed to pulse to give a partial output.  If you just want it on or off then you really don't want PID, you just want to create a thermostat type control which is much simpler.  Then the code is something like (assuming heating):

global sp = 50
while(1)
   if (myvariable[0] < sp)
      output = 1 // turn on heater
   endif
   if (myvariable[0] > sp * 1.05)
      output = 0 // turn off heater
   endif
   delay(1)
endwhile

Note the * 1.05 is hysteresis, and keeps it from turning on and off rapidly when around the SP.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.