Basic Question - Continuously Monitoring And Reacting


cadcoke5

Recommended Posts

Please forgive what must be a very basic question.  But, I don't even know where to start and can't seem to come up with the proper search terms.

 

I am creating a program to take a test chamber through various temperatures at certain times through the process.

 

Currently, I have the sequence in a 2D array with the minutes, and the temperature goal.  My running program will loop though each step as follows;

  1. Start
  2. Is temperature at the current goal?
  3. If not, turn heat on.
  4. Wait the number of minutes necessary for this step.
  5. Increment my index counter.
  6. Loop back to the start.

The major problem is my heat will go on, and stay on, until the allocated time for that step is over.  Obviously, I need to constantly monitor the temperature and then turn it off when ever it reaches my goal for that step.  Note that I prefer to keep my clock ticking, rather than pausing until I reach the temperature goal.

 

I would expect that this is a very typical thing for your program to do.  So, I would be surprised if there was not already some features to facilitate this.  What is the proper search term to find it?

 

Thanks for the help,

-Joe

Link to comment
Share on other sites

This is somewhat typical, but every implementation is a little different, so it requires script.  But the script isn't hard.  Really, you want two scripts, one to control the heat, and the other to change the setpoint.  First, you need a global variable with the current set point.  

 

global setPoint = 0

 

then you need a sequence to turn the heater on whenever the temperature is below the setpoint, a very basic thermostat:

global setPoint = 0
while (1)
   if (temperature[0] < setpoint)
      heater = 1
   else
      heater = 0
   endif
   delay(1)
endwhile

I'm going to assume you are reading temperature elsewhere, i.e. through a channel and Timing.  Note that there is no hysterisis in this.  If you wanted hysterisis, it would be something like (with 5% hysterisis):

global setPoint = 0
while (1)
   if (temperature[0] < setpoint)
      heater = 1
   endif
   if (temperature[0] > setpoint * 1.05)
      heater = 0
   endif
   delay(1)
endwhile

Then you just need another sequence to cycle through the steps.  Let's say the array is a 2d array with the first column being seconds since start, and the second column being the desired temperature:

private starttime = systime()
private count = 0
while(count < numrows(myArray))
   if(systime() > starttime + myArray[count][0])
      setpoint = myArray[count][1]
      count++
  endif
  delay(1)
endwhile

That's actually about it.  Run both sequences simultaneously.  You can leave the first sequence running even for continuous temperature control.

Link to comment
Share on other sites

I had forgotten that your program will allow multiple threads to run.  And while it may be possible to start this continuous routine as soon as DAQFactory starts, I imagine it is best to only start it when it is needed.  I.e. when the process itself is being run. That way it doesn't not eat up processing time unnecessarily.

 

I also see that I should not use a Call function to create this conuouisly running routine. Rather, I should use the beginseq(MySequence) / endseq(MySequence) commands.

 

-Joe

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.