Hello everyone!!
I'm a computer programmer and in the world of PLC i'm a newbie. It's different from event-based programming and I've been a bit confused with a PLC scan time. I want to get the level of a tank while it is fully fedding but my program exhibits unexpected behavior when I pooling to read a sensor.
analog_reading := sensor;
level := tank_level(analog_reading, volt_ref);
WHILE level < 99 DO
VALVE_IN := 1;
analog_reading := sensor;
level := tank_level(analog_reading, volt_ref);
END_WHILE;
IF level = 99 THEN VALVE_IN := 0;
END_IF;
an LED simulating a VALVE_IN does not blink in a while loop, it only works correctly with the IF instruction in the PLC cycle time.
and also, I flashed a openPLC runtime on a board and wrote a program to read memory locations using libmodbus and when I try to access the holding register that stores the "level" variable, my libmodbus program exits with "Operation timed out" error. This doesn't happen if I don't use the while loop.
I tried adding a delay, but it didn't work. What is wrong?!
level := tank_level(analog_reading, volt_ref);
WHILE level < 99 DO
VALVE_IN := 1;
delay(IN:= not delay.Q, PT:= T#2s);
IF (delay.Q) THEN
analog_reading := sensor;
level := tank_level(analog_reading, volt_ref);
END_IF;
END_WHILE;
IF level = 99 THEN VALVE_IN := 0;
END_IF;
the cycle of my task0 in Resource Res0 is 20ms and my delay in loop is 2 seconds, this is a problem?!
taking advantage this topic...
Can't read an analog input into a user-defined function? The openplc editor does not allow defining memory locations (%IW0) in local variables of a function, is it true?
Thank you all!!