Select Bit in Shift Register (DirectSOFT)...

Eric Nelson

Lifetime Supporting Member + Moderator
Join Date
Apr 2002
Location
Randolph, NJ
Posts
4,346
Hi guys,

Sorry I haven't had much time to contribute to the forum lately. I still drop in on occasion... :site:

Let's say I have a 32-bit shift register. I want an operator to be able to enter a value from 0 to 31 to select which bit to examine. When the corresponding bit in the shift register is ON, an output will turn on.

Looks like I want to use the 'decode' instruction (DECO), which will take a value from 0-31 and turn on the corresponding bit in the result. Then, take that result and AND it with the shift register. If the matching bit in the shift register is also ON, then the result will have a '1' in that location. Otherwise, the result will contain all zeros. Therefore, if the result is 'greater than' zero, the shift register bit being examined must be ON, so I can turn on my output.

Quicky ladder...
|     ALW_ON               +------------+
|------] [------------+----| LD V2000 | V2000 Contains a value of 0-31
| | +------------+
| | +------------+
| +----| DECO | Turn on the corresponding bit
| | +------------+
| | +------------+
| +----| OUTD V2001 | V2001 and V2002 contain the decoded value
| | +------------+
| | +------------+
| +----| LDD V2001 |
| | +------------+
| | +------------+
| +----| ANDD V2003 | V2003 and V2004 contain the shift register bits
| | +------------+
| | +------------+
| +----| OUTD V2005 | V2005 and V2006 contain the result of the AND
| | +------------+
| | +------------+
| +----| LDD V2005 |
| | +------------+
| | +------------+
| +----| CMPD K0 | Compare the result to zero
| +------------+
| RESULT > 0
|------] [--------------------------(OUT) If the result of the comparison is greater than zero, turn on the output

For example:

V2000 = 19 Value entered by operator
V2001/V2002 = 0000000000001000 0000000000000000 Decoded value (19th bit is ON)
V2003/V2004 = 0000100010110100 0100010100110010 Current shift register value (19th bit is OFF)
V2005/V2006 = 0000000000000000 0000000000000000 Result of AND. Since result is NOT greater than zero, output is OFF

Shift register advances

V2001/V2002 = 0000000000001000 0000000000000000 Decoded value (19th bit is ON)
V2003/V2004 = 0001000101101000 1000101001100100 Current shift register value (19th bit is now ON)
V2005/V2006 = 0000000000001000 0000000000000000 Result of AND. Since result is greater than zero, output is ON

Am I approaching this correctly? I know that I don't have to store the intermediate results of the accumulator. I just left them in for clarity. I will have a few dozen of these, all looking at the same shift register. Just wondering if there might be a more elegant solution?

I'm using a D2-250-1 CPU

🍻

-Eric
 
I think it's fine. We use the DECO - ANDD in our units.

One application is to test for the presence of an item in a shift register, like yours.

The other is to, on a timed basis, cycle through possibly multiple error bits to be able to display, under PLC control, multiple error conditions - in that case the selector (your V2000) is incremented on a time basis. If the result of the ANDD is ON then a copy of the selector is sent to another V register which acts as the index for a multi-state message display.
 
Sorry I haven't had much time to contribute to the forum lately. I still drop in on occasion...
Hello Eric,
Several have wondered what happened to you. I am glad to know that you are still alive and able.

:site:
 
Thanks for the confirmation, Bernie... :) I see how it could be handy for message display as well. I use a different method, but might try this as an alternative.

Yes, Lancie, I'm still around. Just not as often. I guess being swamped with work is a good thing, but it doesn't allow me much free time to keep up with the forum.

Many thanks as always!... :site:

🍻

-Eric
 
As a followup, this worked out great!... :site:

I also needed a way to turn off an individual bit based on an inspection result. I used this method to determine where to perform the inspection, but also stored the decoded value in a separate register. I then XORed this with the shift register to turn off the same bit that initiated the inspection (to flag a failure). Worked perfectly!

Thanks again, Bernie!... :)

🍻

-Eric
 

Similar Topics

Hello, We recently upgraded our control server to a newer model. After the transition we are experiencing issues with our trend graphs to where...
Replies
1
Views
26
Hi all, I really need help with this one. I'm at a complete loss... For months and months, I've had no problems with pressing a NEXT button to...
Replies
14
Views
1,433
Hello everyone, I'm having trouble solving this one and was hoping someone could help. I have a AB CompactLogix L16ER PLC connected to a AB...
Replies
2
Views
577
Is there a way to select a parameter file when loading a given screen based on the value of a variable? I see that under "Global Connections" the...
Replies
2
Views
1,100
When attempting to add IO modules to the backplane of a Guardlogix controller (5069-L330ERMS), there are only 18 modules from which to select, and...
Replies
3
Views
1,370
Back
Top Bottom