You are not registered yet. Please click here to register!


 
 
plc storereviewsdownloads
This board is for PLC Related Q&A ONLY. Please DON'T use it for advertising, etc.
 
Try our online PLC Simulator- FREE.  Click here now to try it.

---------->>>>>Get FREE PLC Programming Tips

New Here? Please read this important info!!!


Go Back   PLCS.net - Interactive Q & A > PLCS.net - Interactive Q & A > LIVE PLC Questions And Answers

PLC training tools sale

Reply
 
Thread Tools Display Modes
Old March 7th, 2018, 12:49 AM   #1
stretch_af
Member
United States

stretch_af is offline
 
Join Date: Mar 2011
Location: WI
Posts: 5
BIT SHIFT equivalent for a word

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.
  Reply With Quote
Old March 7th, 2018, 01:00 AM   #2
(8{)} ( .)
Lifetime Supporting Member
Israel

(8{)} ( .) is offline
 
(8{)} ( .)'s Avatar
 
Join Date: Apr 2004
Location: Israel
Posts: 586
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
  Reply With Quote
Old March 7th, 2018, 01:27 AM   #3
stretch_af
Member
United States

stretch_af is offline
 
Join Date: Mar 2011
Location: WI
Posts: 5
Oh yeah, I'm using a Control Logix.
Thanks, I'll look in to that.
  Reply With Quote
Old March 7th, 2018, 02:18 AM   #4
janner_10
Supporting Member
United Kingdom

janner_10 is offline
 
Join Date: Dec 2014
Location: Tewkesbury
Posts: 593
Or roll your own with a Location[i]

'i' being a dint you increment at your leisure and just move values into Location[i]
  Reply With Quote
Old March 7th, 2018, 05:24 AM   #5
cwal61
Member
United States

cwal61 is offline
 
Join Date: Jan 2011
Location: NC
Posts: 946
Quote:
Originally Posted by (8{)} ( .) View Post
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 by cwal61; March 7th, 2018 at 05:27 AM.
  Reply With Quote
Old March 7th, 2018, 12:48 PM   #6
(8{)} ( .)
Lifetime Supporting Member
Israel

(8{)} ( .) is offline
 
(8{)} ( .)'s Avatar
 
Join Date: Apr 2004
Location: Israel
Posts: 586
Quote:
Originally Posted by cwal61 View Post
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.
  Reply With Quote
Old March 7th, 2018, 01:29 PM   #7
Aardwizz
Member
United Kingdom

Aardwizz is offline
 
Aardwizz's Avatar
 
Join Date: Dec 2017
Location: Swindon
Posts: 128
Quote:
Originally Posted by cwal61 View Post
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]
  Reply With Quote
Old March 7th, 2018, 03:43 PM   #8
ASF
Lifetime Supporting Member
Australia

ASF is offline
 
Join Date: Jun 2012
Location: Australia
Posts: 2,550
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.
  Reply With Quote
Old March 7th, 2018, 04:16 PM   #9
cwal61
Member
United States

cwal61 is offline
 
Join Date: Jan 2011
Location: NC
Posts: 946
Quote:
Originally Posted by (8{)} ( .) View Post
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.
Quote:
Originally Posted by (8{)} ( .)
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.
  Reply With Quote
Old March 7th, 2018, 11:53 PM   #10
(8{)} ( .)
Lifetime Supporting Member
Israel

(8{)} ( .) is offline
 
(8{)} ( .)'s Avatar
 
Join Date: Apr 2004
Location: Israel
Posts: 586
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!
  Reply With Quote
Reply
Jump to Live PLC Question and Answer Forum

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Topics
Thread Thread Starter Forum Replies Last Post
Sequencers randy LIVE PLC Questions And Answers 43 December 20th, 2014 02:10 PM
Mitsi .. bit set / bit test of a word cjd1965 LIVE PLC Questions And Answers 3 July 31st, 2008 10:18 AM
installing a panelview 600 + rjmarinaro LIVE PLC Questions And Answers 10 June 17th, 2008 11:52 AM
s7 300 to simoreg SHYAMAL LIVE PLC Questions And Answers 9 January 30th, 2008 12:53 PM
16 bit input in word address rjanociak LIVE PLC Questions And Answers 3 May 15th, 2002 11:43 AM


All times are GMT -5. The time now is 08:32 PM.


.