Sequence Stuck in While Loop


Sean_M

Recommended Posts

Hi, I'm trying to automate a piece of equipment and am having some trouble with the coding. Below is my sequence to control stir rate which is related to the system pressure. I would like to have stirring incrementally increase when pressure is too low and decrease while pressure is too high. The problem that I am encountering is that the sequence will not leave the "Pressure too high" while loop. It will enter and leave the "Pressure too low" loop and enter "Pressure too high", but will continue decreasing stir speed even when the pressure leaves the defined range. Any thoughts would be helpful.

//Stir Command Control Sequence//

while(1)

	//Stir Control for MANUAL SETTING//
	while(otto_status==0)
		stir = setfreq*(60/100)*(60/61.6)
		setfreq = freq*(5/60)
		delay(1)
	endwhile

	//Stir Control for AUTO SETTING//
	while(otto_status==1)

		//Pressure too low//
		while(p_gas_out[0] <0.75)
			stir = stir_target*(5/100)
			stir_target = stir_target[0] + 0.25
			if(otto_status==0)
				break
			endif
			delay(10)
		endwhile

		//Pressure too high//
		while(1.5<= p_gas_out[0] <2.5)
			stir = stir_target*(5/100)
			stir_target = stir_target[0] - 0.5
			if(otto_status==0)
				break
			endif
			delay(10)
		endwhile

		//Pressure in range//
		while(0.75<= p_gas_out[0] <1.5)
			stir = stir_target*(5/100)
			switch
				case(150<= tc2[0] <350)
					stir_target = stir_target[0]
				case(tc2[0] <150)
					stir_target = stir_target[0] - 0.25
				case(350<=  tc2[0])
					stir_target = stir_target[0] + 0.25
			endcase
			if(otto_status==0)
				break
			endif
			delay(10)
		endwhile

		//Over pressure with blockage detection off//
		if(blockage_status==0)
			while(2.5<= p_gas_out[0])
				stir_target = 0
				stir = stir_target[0]
				if((otto_status==0)||(blockage_status==1))
					break
				endif
				delay(1)
			endwhile
		endif

		delay(1)
	endwhile

	delay(1)
endwhile

-Sean

Link to comment
Share on other sites

This:

1.5<= p_gas_out[0] <2.5

is probably not the expression you think it is. First, it will look to see if p_gas_out[0] >= 1.5. That will result in either 1 or 0. Then it will compare that value to 2.5, and if its < 2.5, which it always is, it will return 1 which will cause the loop to run forever.

Link to comment
Share on other sites

Thanks for the quick response.

You are most certainly right, that is not the expression I was thinking it was. Switching to:

while((1.5<= p_gas_out[0]) && (p_gas_out[0] <2.5))

seems to work quite nicely.

Link to comment
Share on other sites

Archived

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