BIT SHIFT equivalent for a word

stretch_af

Member
Join Date
Mar 2011
Location
Drinking in Wisconsin
Posts
67
I have an array of 10 words. I would like to shift them down for tracking purposes, entering the new value into let's call it "Location[0]". And the value that was in "Location[0]" moves into "Location[1]" and so on all the way down. BSL obviously only dose 1 bit at a time. Is there an easy way to "shift" words? I couldn't think of one.
 
Assuming you're using an AB PLC use the COP or CPS instruction. Enter your newest data at the HIGHEST address, say Location[10]. Your lowest data will be at Location[1]. Copy 10 words from Location[10] to Location[9].

Good Luck,

Yosi
 
Or roll your own with a Location

'i' being a dint you increment at your leisure and just move values into Location
 
Assuming you're using an AB PLC use the COP or CPS instruction. Enter your newest data at the HIGHEST address, say Location[10]. Your lowest data will be at Location[1]. Copy 10 words from Location[10] to Location[9].

Good Luck,

Yosi

This approach will shift words the only thing is you shift using array[1] to array[0] for the length of array. I always make my array 1 greater than the size of shift. If I was shifting 10 elements then I would make my array[11] to give me 0-10. This way you enter you new data in array[10] then copy array[1] to array[0] for a length of 10. This will copy words 1-10 and paste them in words 0-9. This gives you the effect of shifting one position in the array. Your newest data will be in word 9 and the oldest in word 0.

If you want to shift in order then you'll need 10 copy instructions. Just make sure you copy backwards first. 9 to 10 then 8 to 9 then 7 to 8 etc.... That way you move your data to new location before you copy in new data.
 
Last edited:
If you want to shift in order then you'll need 10 copy instructions. Just make sure you copy backwards first. 9 to 10 then 8 to 9 then 7 to 8 etc.... That way you move your data to new location before you copy in new data.

You only need one copy instruction. You must copy from the higher index to the lower index otherwise the copy instruction will fill the array with the value located in the low index.
 
If you want to shift in order then you'll need 10 copy instructions.

I can do it in two. But it takes a "dummy" array to make it work.
COP Array[0] Dummy[0] 10
COP Dummy[0] Array[1] 9
Move NewData Array[0]

But as others have said, the "load from the top" method only requires one COP:
COP Array[1] Array[0] 9
Move NewData Array[9]
 
I think the direct equivalent you're looking for is the FFL/FFU instruction set. That does exactly what you're describing, using words instead of bits.

However, as others have already suggested, if you don't mind loading them backwards you can absolutely do it very quickly and easily using a single COP instruction instead.
 
You only need one copy instruction. You must copy from the higher index to the lower index otherwise the copy instruction will fill the array with the value located in the low index.

I agree with that.
(8{)} ( .) said:
Assuming you're using an AB PLC use the COP or CPS instruction. Enter your newest data at the HIGHEST address, say Location[10]. Your lowest data will be at Location[1]. Copy 10 words from Location[10] to Location[9]

I was just pointing out you stated copy 10 to 9 for length in your first post. If my array is a length of 10 and copy the 10th element to the 9th element then my max length is 1. copying 1 to 0 allows for the full length of 10. I was just trying to clarify your approach. No offense intended.
 
I stand corrected. Yes, you'd copy from [1] to [0] a length of 10 for a 10 member queue. You'd still need only one COP instruction.

Thanks!
 

Similar Topics

Good morning (EST), I am trying to implement the code below in on an S7-1200. It's barely half a dozen instructions, but I am stuck; I have not...
Replies
26
Views
5,525
Hi All. I have a very specific question about tracking using an encoder and bitshift register. We would like to use a Compact or Control Logix PLC...
Replies
40
Views
1,600
Hello. I've been using the answers in this forum for a while now, so thank you. Usually I can find the answer I'm looking for with a basic...
Replies
8
Views
733
Hi, I need some help write a PLC instruction. I am using Proficy Machine Edition 6.5. Our indexing rotating table has 3 nests that are equally...
Replies
15
Views
3,887
I have a program I need to work out for a client and I'm having trouble figuring out the correct logic to do it. Let me see if I can explain it...
Replies
27
Views
6,415
Back
Top Bottom