RLidster Posted January 6, 2015 Share Posted January 6, 2015 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 Quote Link to comment Share on other sites More sharing options...
AzeoTech Posted January 6, 2015 Share Posted January 6, 2015 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. Quote Link to comment Share on other sites More sharing options...
Pioneer Posted July 23, 2021 Share Posted July 23, 2021 When I use the above code my SSR channel alternates between 0 and 1. How do I get it to stay on the correct value? Edit: Added at the top of sequence code: global PIDOut PIDOut = 1 Quote Link to comment Share on other sites More sharing options...
AzeoTech Posted July 27, 2021 Share Posted July 27, 2021 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.