Reading bits into and out of registers
04 Apr 2016 21:23 #72741
by buckym1a
Reading bits into and out of registers was created by buckym1a
Is it possible to read individual bits into and out of registers?
What Im looking to do is take a word variable, say %W2, and copy the individual bits to a series of single bit memory bits, say %B1, %B2, %B3...ect.
I then also would like to be able to write the %B bits back to a %W variable.
Jim
What Im looking to do is take a word variable, say %W2, and copy the individual bits to a series of single bit memory bits, say %B1, %B2, %B3...ect.
I then also would like to be able to write the %B bits back to a %W variable.
Jim
Please Log in or Create an account to join the conversation.
- Todd Zuercher
- Offline
- Platinum Member
Less
More
- Posts: 5007
- Thank you received: 1440
05 Apr 2016 02:24 #72760
by Todd Zuercher
Replied by Todd Zuercher on topic Reading bits into and out of registers
I'm pretty sure that it is possible. I think I did something like that on a machine, I'll have to review my notes and the config. It was several years ago when I set that machine up.
Please Log in or Create an account to join the conversation.
05 Apr 2016 02:53 - 05 Apr 2016 02:56 #72762
by buckym1a
Replied by buckym1a on topic Reading bits into and out of registers
Thank you Todd,
I was able to figure out how to get the bits from a register to single bit holder after a bit of reading here and some tinkering.
A compare block with the expression: %w1&1=1 will evaluate true if the first bit of %w1 is a 1. This can be used to drive a coil.
Each bit can be isolated by using the correct "&" number
|-[%W1&1=1]---(%b1)-|
|-[%W1&2=2]---(%b2)-|
|-[%W1&4=4]---(%b3)-|
Where "1" gives us the binary number 0001
"2" gives us the binary number 0010
and "4" gives us the binary number 0100
Now I just need to figure out how to write from a single bit holder to a register.
Jim
I was able to figure out how to get the bits from a register to single bit holder after a bit of reading here and some tinkering.
A compare block with the expression: %w1&1=1 will evaluate true if the first bit of %w1 is a 1. This can be used to drive a coil.
Each bit can be isolated by using the correct "&" number
|-[%W1&1=1]---(%b1)-|
|-[%W1&2=2]---(%b2)-|
|-[%W1&4=4]---(%b3)-|
Where "1" gives us the binary number 0001
"2" gives us the binary number 0010
and "4" gives us the binary number 0100
Now I just need to figure out how to write from a single bit holder to a register.
Jim
Last edit: 05 Apr 2016 02:56 by buckym1a.
The following user(s) said Thank You: reliantkill
Please Log in or Create an account to join the conversation.
05 Apr 2016 03:59 #72764
by cmorley
Replied by cmorley on topic Reading bits into and out of registers
The following user(s) said Thank You: reliantkill
Please Log in or Create an account to join the conversation.
Time to create page: 0.111 seconds