Can an input X1 change while instruction sequence is still being processed?
e.g.
LD X1
AND X2
OUT Y1
LD X1 // Can X1 loaded here differ from the previous one?
AND X3
OUT Y1
Thanks
Can an input X1 change while instruction sequence is still being processed?
e.g.
LD X1
AND X2
OUT Y1
LD X1 // Can X1 loaded here differ from the previous one?
AND X3
OUT Y1
Thanks
Yes, of course it can - the probably of it changing in this interval will be very low, so if you have a bug where you have assumed that these two values will never differ then it may not show up for a while.
Many, but not all, PLCs work with an IO image. The inputs are read and stored in registers. During processing you are working with the IO image. The image is updated at the end of the cycle. This way the inputs cannot change during processing, but only between cycles.
To add to Jim C's answer, it is worth noting, also, that many (most?) PLCs will allow you to use a special "immediate" type instruction which reads the status of the contact/relay/input/etc directly (as opposed to reading from the IO image) when the CPU scan reaches that particular rung. This typically does not update the IO image, meaning that all other normal reads of that contact for the remainder of the CPU scan will read the old value in the register unless they too are of the "immediate" type.
Example :
//Start of Program
// Here the CPU scan starts with X1 closed, X2 closed in the IO image
LD X1 //(X1 = closed)
AND X2 //(X2 = closed)
OUT Y1 //(Y1 will be set high/closed)
// **suddenly X1 opens**
//(using LDI here to denote "immediate")
LDI X1 //(open - reading true status)
AND X2 //(closed)
OUT Y1 //(Y1 will now open)
LD X1 //(reading from image = closed, still)
AND X2 //(closed)
OUT Y1 //(Y1 will close again)
END of Program
Then, on the next CPU scan the image will update with the new value (X1=open) and all three rungs will return Y1 open.
Immediate instructions usually come with a time penalty, of course, because the PLC must take extra time to seek the current value of the contact rather than read from the image. They can, however, be useful depending on how you want your program to operate. These instructions MUST be used explicitly, however, and the normal operation is simply to read from the IO image, as Jim noted.
ps: I used "LDI" here to denote the immediate instruction, but all PLCs will use different syntax. Koyos, for example, use STR (store) instead of LD and STRI (store immediate).
A common technique is to make a copy of the IO registers to an internal memory address so the programmer can be assured that his IO doesn't change between instructions. Make the inputs copy at the beginning of the scan and copy to your outputs at the end of the scan.