- Posts: 5
- Thank you received: 0
Reading bits into and out of registers
10 years 6 months ago #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 to join the conversation.
- Todd Zuercher
- Offline
- Platinum Member
-
Less
More
- Posts: 4739
- Thank you received: 2
10 years 6 months ago #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 to join the conversation.
10 years 6 months ago #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
Please Log in to join the conversation.
10 years 6 months ago #72764
by cmorley
Replied by cmorley on topic Reading bits into and out of registers
you could do the conversion outside of classicladder with say mux16 and send it back to classicladder.
or this ladder seemed to work:
or this ladder seemed to work:
Attachment not found
Please Log in to join the conversation.
Time to create page: 0.284 seconds
