opticaldynamics Posted September 3, 2009 Share Posted September 3, 2009 Hey I am working with a reactor that is set to heat up to 146C then cool down to 80C and stay at 80 for 25 hours. How would I write a code that would start counting down the 25 hours when the reactor gets to 80C so we are able to see how much time is left? Thanks Link to comment Share on other sites More sharing options...
AzeoTech Posted September 3, 2009 Share Posted September 3, 2009 Just set a global variable to systime() when the cool down starts, and then display 25 * 3600 - (systime() minus that variable) for the amount of time left (in secs). OK: global starttime = systime() // when the 25 hours starts the expression for elapsed time (in secs): (systime() - starttime) in hours: (systime() - starttime) / 3600 for remaining time (in hours from 25) 25 - (systime() - starttime) / 3600 Link to comment Share on other sites More sharing options...
opticaldynamics Posted September 4, 2009 Author Share Posted September 4, 2009 Okay, so how would i incorporate that into my code so it will start as soon as the temperature is 80? my Code looks like this.. using("device.labjack.") include("c:\program files\labjack\drivers\labjackud.h")//Both lines of code establish connection with LJ //Declare global variables that will be used throughout sequence global uppertemp global setpoint global synthesistime global hysteresis global systime() //ZnO Synthesis, heat up to a certain temperature (uppertemp) while(min(controltemp[0,4])<uppertemp) ePut(0, LJ_ioPUT_DIGITAL_BIT,6,0,0)//set FI06 to output-low (heater on) output=3.6 delay(1) endwhile //Cool to set temp while(max(internal[0,4])>setpoint) eGet(0, LJ_ioGET_DIGITAL_BIT,6,@FI06Reading,0)//set FI06 to input (heater off) output=0 delay(1) endwhile //Control for synthesis time private starttime = systime() while(systime()<starttime + 3600*synthesistime)//control for 1 hour X synthesis time if (internal[0]<setpoint - hysteresis) ePut(0, LJ_ioPUT_DIGITAL_BIT,6,0,0)//heater on output=3.6 endif if (internal[0]>setpoint-1) eGet(0, LJ_ioGET_DIGITAL_BIT,6,@FI06Reading,0)//heater off output=0 endif delay(5) endwhile eGet(0, LJ_ioGET_DIGITAL_BIT,6,@FI06Reading,0)//heater off output=0 Thanks Link to comment Share on other sites More sharing options...
AzeoTech Posted September 4, 2009 Share Posted September 4, 2009 Just make your "starttime" variable global instead of private so you can access it from screen components, and replace the 25 with synthesistime in my expressions. Also this line: global systime() is invalid. Systime is a reserved function so can't be used as a variable, nor needs to be declared, and putting () in a variable declaration is not valid either. The sequence executor probably just skips over the line. Link to comment Share on other sites More sharing options...
opticaldynamics Posted September 17, 2009 Author Share Posted September 17, 2009 okay, I have the timer working in a way. the code seems to work and it displays a number of hours left and decreases over time but it comes up as a huge number such as 125786129.688 hours left.. Link to comment Share on other sites More sharing options...
AzeoTech Posted September 18, 2009 Share Posted September 18, 2009 Everything in DF is in seconds. Perhaps you forgot to divide by 3600? Of course that's still about 35,000 hours, so there is something else wrong in your math. I'd need to see your script to help any further. Link to comment Share on other sites More sharing options...
opticaldynamics Posted September 21, 2009 Author Share Posted September 21, 2009 Under Variable Value Component, we have the caption called remaining time. the expression for it is: Starttime- (systime() - starttime) / 3600. should the First starttime actually say synthesis time since our synthesis time is set to 25 hours? thanks Link to comment Share on other sites More sharing options...
AzeoTech Posted September 21, 2009 Share Posted September 21, 2009 Correct, provided sythesis time is in hours, not seconds. If its in seconds, it will need to be SynthesisTime / 3600, or do the appropriate algebra to simplify it. Link to comment Share on other sites More sharing options...
opticaldynamics Posted September 21, 2009 Author Share Posted September 21, 2009 ok thanks for all your help I think I have it working now Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.