News:

  • June 01, 2023, 05:52:38 PM

Login with username, password and session length

Author Topic: bit shift  (Read 1437 times)

bowtie496

  • Newbie
  • *
  • Posts: 2
bit shift
« on: December 13, 2018, 07:04:53 PM »
How do I do a bit shift in dirctSOFT? I have a prox sensor on a crane need shift left in one direction then right in the other direction. So I can keep track of location. 

b_carlton

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 606
    • thePLCguy
Re: bit shift
« Reply #1 on: December 14, 2018, 12:09:24 AM »
There is no single instruction which allows both left and right shifts. The SR instruction direction of shift is controlled by the order of the two operands.

I haven't tried this but you might try two SR commands, One with the operands ascending (eg C0 - C17) and the other descending (eg C17 -  C0). I don't have a system to test this on so try it yourself and get back.

I think of this because of the Allen Bradley SLC line of creating an Up/Down counter. Two counter instructions, an Up counter and a Down counter are used both using the same counter number.
An output is a PLC's way of getting its inputs to change.

alectek

  • Jr. Member
  • **
  • Posts: 12
Re: bit shift
« Reply #2 on: December 14, 2018, 12:18:23 PM »
Maybe you can try SHFL AND SHFR?

A binary 0000100000000 in which 1 is the location?

b_carlton

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 606
    • thePLCguy
Re: bit shift
« Reply #3 on: December 14, 2018, 01:30:38 PM »
SHFL and SHFR are great if 32 or fewer bits. A great suggestion.
An output is a PLC's way of getting its inputs to change.

bowtie496

  • Newbie
  • *
  • Posts: 2
Re: bit shift
« Reply #4 on: December 14, 2018, 05:51:21 PM »
thanks for the info, I will play around with it this weekend.