Summary: the BSR is designed to shift its addressed bits by one bit position per execution, and that only on a rising edge of its input rung.
Possible solutions (there are others):
- Fifteen BSR instructions in fifteen consecutive rungs
- each fed by the same rung logic to detect the rising edge;
- each with its own unique control structure (e.g. R6:0 through R6:15);
- I am fairly certain that, in RSLogix 500, control structure references cannot use indirect addressing;
- To shift by N bit (N in the range [:15]) positions, enable the only the first (or last) N of those instructions;
- Logic that increments N may be on branches with each of the BSRs, or on separate rungs before each BSR
- N.B. changing N on successive scans, while the input rung logic that supply the rising edge are true, can produce unexpected results
- One BSR instruction in a loop
- Control the rising edge separately i.e.
- detect the rising edge before the loop,
- save the result in a bit
- make loop execution dependent on that rising edge result bit
- Unlatch the .EN member of the control structure to 0 in the loop before the BSR
- Put no logic on the rung of the BSR
- Divide word by 2**N
- e.g
- N7:0 - input word with bits to be shifted
- N7:1 - result word with shifted bits; also some intermediate values
- N7:2 - N, i.e. number of bit positions to shift, 0 to 15
- N7:3 - divisor i.e. mask with 1 in lowest bit to be shifted and all other bits 0
- N7:4 - shifted sign bit position
- Create the following single rung:
- BST CLR N7:3 NXB OTE N7:3/[N7:2] NXB SUB N7:3 1 N7:1 NXB NOT N7:1 N7:1 NXB OTU N7:1/15 NXB AND N7:0 N7:1 N7:1 NXB DIV N7:1 N7:3 N7:1 NXB SUB 15 N7:2 N7:4 NXB XIC N7:0/15 OTE N7:1/[N7:4] BND
- Update to fix previous item; tested and working now
TL;DR
See the
BSR Flow Chart (True) at the end of the BSR documentation at
this link; that is RSLogix 5000, but it explains how the BSR works. the key steps to notice are
- The <examine .EN bit> conditional diamond in the upper left
- where the logic goes if that conditional of .EN finds a 1
- where the logic goes if that conditional of .EN finds a 0
- The [.EN bit is set to true ...] box under that conditional
The OP says "shift the 15th bit in the word address by
10 bit," but the example diagram shows a shift by
15 bit. So I assume the example diagram should be something like
1100 1010 0000 0000 -> First state
0000 0000 0110 0101 -> Second state
Anyway, the issue OP is coming up against is that the BSR is designed to shift the bits in a word by exactly one bit position. and that only on a rising edge of the input rung state, so by design a single BSR executed once per scan in a program can only shift bits by one position on every other scan, i.e. on alternating scans.
So if we put multiple BSR instructions
with the same control object (e.g. R6:0) one after the other, the second and later BSRs will detect a rising edge, because the first instruction sees the rising edge and changes the state of the control object (e.g. R6:0.EN)