S7: Evaluate bit pattern

Hedeby

Member
Join Date
Oct 2011
Location
Give
Posts
5
Hello

I need to know how many input are true from at 5-bit pattern.
The True/False sequence is random.

The evaluation has to be in every scan, so a counter is not an option.

Is there a easy way of calculationg that?
 
Here's an FC

Code:
FUNCTION FC 2 : INT
TITLE =
VERSION : 0.1

VAR_INPUT
  Bit0 : BOOL ; 
  Bit1 : BOOL ; 
  Bit2 : BOOL ; 
  Bit3 : BOOL ; 
  Bit4 : BOOL ; 
END_VAR
BEGIN
NETWORK
TITLE =
      L     0; 
      A     #Bit0; 
      JCN   s0; 
      +     1; 
s0:   A     #Bit1; 
      JCN   s1; 
      +     1; 
s1:   A     #Bit2; 
      JCN   s2; 
      +     1; 
s2:   A     #Bit3; 
      JCN   s3; 
      +     1; 
s3:   A     #Bit4; 
      JCN   s4; 
      +     1; 
s4:   T     #RET_VAL; 
END_FUNCTION
 
The evaluation has to be in every scan, so a counter is not an option.

Why Not ? Use a int as a counter register
Code:
Counter=0
If bit 1=1 then counter+1
If bit 2=1 then counter+1
If bit 3=1 then counter+1
If bit 4=1 then counter+1
If bit 5=1 then counter+1
NoOfBits=Counter
 

Similar Topics

Does anyone know how to do this logic in Contrologix?
Replies
3
Views
1,570
Hi there, I have never used Citect before and have a few bugs to fix. I have 2 questions: 1. How can i view the tag database as a whole...
Replies
10
Views
3,444
Hi all, I'd like to know your point of view on this aspect of PLC programming, the example I use is simple, but the concept can be applied to...
Replies
5
Views
2,467
Hi I am having som problems evaluating if the value in an integer created in the Static area, is Odd or Even. As far as I remember, Odd integer...
Replies
17
Views
8,413
Hello, I wrote some vba code for a Factorytalk View Studio SE application display. The code should be around 100 lines long using something...
Replies
2
Views
1,963
Back
Top Bottom