Reading bits into and out of registers
04 Apr 2016 21:23 #72741
by buckym1a
buckym1a created the topic: Reading bits into and out of registers
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
- Todd Zuercher
- Away
- Platinum Boarder
Less
More
- Posts: 2689
- Karma: 143
- Thank you received: 520
05 Apr 2016 02:24 #72760
by Todd Zuercher
Todd Zuercher replied the 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.
05 Apr 2016 02:53 - 05 Apr 2016 02:56 #72762
by buckym1a
buckym1a replied the 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
Time to create page: 0.197 seconds