function used for a period of time


valerio

Recommended Posts

Hallo, i'm programming a sequence for a test bench used to pressurize hoses.

My test has two steps:

in the first one i command a pump with a on-off valv and a proportional valv to increase the pressure to a specified value (pres1).

in second part ,when pres1 is reached i want that during a period of time(V.pause) proportional valv stay at it's last value and only on-off valve works to mantain the value pres1

actually i just pressurize the hose to pres1 but for the second part i don't know how to mantain pressurization

while (press <= pres1)

valve1 = 1

proportional = proportional+0.1

delay(0.1)

endwhile

delay(V.pause)

thanks in advance

Link to comment
Share on other sites

OK, I'm assuming that the pressure drops slowly when the valve is off. You have the right idea for the start, but you can't simply use delay() because you need to do some automated control. I think you want something like this:

while (press &lt;= pres1)
   valve1 = 1
   proportional = proportional+0.1
   delay(0.1)
endwhile
valve1 = 0
private st = systime()
while (systime() &lt; st + V.pause)
   valve1 = (press &lt; pres1)
   delay(0.1)
endwhile

So, the first part stays the same as what you had. Then I turn off the valve. I record the current (start) time, then loop while the current time is less than the start time plus the pause time. Inside the loop, I set valve1 based on whether press is below pres1. I actually recommend some hysterisis, something more like:

...
while (systime() &lt; st + V.pause)
   if (press &lt; pres1*0.95)
	  valve1 = 1
   endif
   if (press &gt;= pres1)
	  valve1 = 0
   endif
   delay(0.1)
endwhile

This will keep the valve from toggling on and off too fast. It will only turn on the valve when the pressure drops below 95% of the setpoint, and will turn it off at the setpoint.

Link to comment
Share on other sites

hi, i tried to use you code but i'm doing something wrong, thi is my actual code:

while (press[0] &lt; V.press1)
		proportional = proportional [0]+0.02
		valv1 = 1
  delay(0.1)
endwhile
valv=0
private st =systime()
while (systime &lt; st + V.pause)
	 if (press[0] &lt; V.pres1)	  
		 valv1 = 1
	  endif
  delay(0.1)
endwhile

program stops and there is an alarm corresponding to de declaration of private st =systime()

have i to declare this variable in any other way?

thanks

Link to comment
Share on other sites

Actually, I think the issue is with the line after that. Systime() is a function and as such you have to put () after it. You forgot to in your second while(). Also, note that with the logic you have, the system will turn the valve on if the pressure drops, but then the valve will stay on.

Link to comment
Share on other sites

Archived

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