News:

  • June 09, 2026, 01:20:56 PM

Login with username, password and session length

Author Topic: Looking at bits  (Read 13779 times)

PLCGuy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 677
Looking at bits
« on: November 09, 2017, 10:39:00 AM »
I have a DWORD coming from a drive that shows the status of the outputs. Bit 0=Enable, Bit 1=Ready,.. and so on.
The binary may look like this 000_000_000_000_0111.  So I was thinking I want to look at bit 0 and if TRUE set C0. If bit 1 is TRUE then set C1,... etc. I was going to use a math box but confused how to use brackets and the such. How would one of you do it?

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3827
    • Host Engineering
Re: Looking at bits
« Reply #1 on: November 09, 2017, 10:42:25 AM »
Are you simply doing a MOVE?  If so
MOVE SourceDWORD C0:SD

If you want to set/latch, then use MATH
MATH C0:SD "SourceDWORD | C0:SD"

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6158
  • Yes Pinky, Do-more will control the world!
Re: Looking at bits
« Reply #2 on: November 09, 2017, 10:43:27 AM »
If the data were located in D0, you could use a simple bit cast like D0:n where n = bits 0-31. So read or write the third bit in D0, it is D0:2.
"It has recently come to our attention that users spend 95% of their time using 5% of the available features. That might be relevant." -BobO

PLCGuy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 677
Re: Looking at bits
« Reply #3 on: November 09, 2017, 12:09:45 PM »
Forgot to mention is it being loaded into my made up memory. ormectrx6, it is a dword.
So would it I use a math box? Result would be C0, Calculation would be: if(ormectrx6:0,1,0)

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6158
  • Yes Pinky, Do-more will control the world!
Re: Looking at bits
« Reply #4 on: November 09, 2017, 12:28:27 PM »
Forgot to mention is it being loaded into my made up memory. ormectrx6, it is a dword.
So would it I use a math box? Result would be C0, Calculation would be: if(ormectrx6:0,1,0)

MATH box works, but not needed. STR ormectrx:8 OUT C0 works fine, or a MOVE, INIT, or any other instruction that will do the assignment.
"It has recently come to our attention that users spend 95% of their time using 5% of the available features. That might be relevant." -BobO

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6158
  • Yes Pinky, Do-more will control the world!
Re: Looking at bits
« Reply #5 on: November 09, 2017, 12:30:15 PM »
Forgot to mention is it being loaded into my made up memory. ormectrx6, it is a dword.
So would it I use a math box? Result would be C0, Calculation would be: if(ormectrx6:0,1,0)

MATH box works, but not needed. STR ormectrx:8 OUT C0 works fine, or a MOVE, INIT, or any other instruction that will do the assignment.

And if you did a MATH box you don't need the IF(). Just MATH C0 ormectrx:6 works.
"It has recently come to our attention that users spend 95% of their time using 5% of the available features. That might be relevant." -BobO

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3827
    • Host Engineering
Re: Looking at bits
« Reply #6 on: November 09, 2017, 12:37:59 PM »
Are you simply doing a MOVE?  If so
MOVE SourceDWORD C0:SD

If you want to set/latch, then use MATH
MATH C0:SD "SourceDWORD | C0:SD"

or the new COPY instruction in lieu of MOVE

PLCGuy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 677
Re: Looking at bits
« Reply #7 on: November 09, 2017, 02:16:43 PM »
Ended up using Copy. I did not realize to treat the bits as STR.

Thanks, you both got me thinking.

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3827
    • Host Engineering
Re: Looking at bits
« Reply #8 on: November 09, 2017, 02:30:43 PM »
Take 2

Since both the Source and the Destination are both contiguous, just set the Count to 6

PLCGuy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 677
Re: Looking at bits
« Reply #9 on: November 10, 2017, 07:37:54 AM »
Thanks that works great. I did not know I could write C0-C5 like that in the box.

I tried to show this stuff to a die hard AB guy and he just walked away, lol.