Home AW-SYS Support Demo

 

Previous
Next

Example 26
Counter for closed inputs (solution II)

Count the number of closed inputs in module 0.

In this exercise we will use a shift operation to apply a solution other than that used in the previous example.
The counter for closed inputs is still MB80 and its initial value is 0 at the beginning of the OB1. MB10 represents a mask of 8 bits only one of which will, in turn, be set to 1. The initial value is 1, that is (00000001)2, where only bit 0 is true.
The first three statements of the FB4 block load the accumulators with the values of the mask and the byte corresponding to the input to module 0 and then execute the AND one bit at a time. On the first step, with the value of the mask hardly visible, the AND only gives a result other than 0 if E0.0 is closed. This means that the derivation on zero included in the next statement will only be carried out if the input is open.
If the input is closed, as in the previous example, the counter byte MB80.0 is increased.
Whatever the case, the two paths come together in label INC where, after loading the mask in ACCU1, it is shifted one position to the left. The result of this displacement, or better yet the low part, is again transferred to MB10. After the statement L KF+256, ACCU1 will have the value of 256 and ACCU2 will contain the result of the displacement. If the mask bit, after 8 displacements, has ended up in position 8 of the 16 bit register of the accumulator, the value of this accumulator will be 28 = 256, the statement of the conditional jump is ignored and processing of the block stops. If the bit is located in lower positions then the content of the accumulator is less than 256 and the jump to the TEST label is executed to repeat the process and examine the next input.

More examples: 1 ] 2 ] 3 ] 4 ] 5 ] 6 ] 7 ] 8 ] 9 ] 10 ] 11 ] 12 ] 13 ] 14 ] 15 ] 16 ] 17 ] 18 ] 19 ] 20 ] 21 ] 22 ] 23 ] 24 ] 25 ] [ 26 ] 27 ] 28 ] 29 ] [ List ]
More PLCs examples: Not still available