How to determine how many bits some specific DB is containing

naturephoenix

Member
Join Date
Jan 2015
Location
Vienn
Posts
181
I got some function which is looping some shared DB, input variable is number of bits...but is there any way to find out number of bits inside specific DB
 
I am trying to get how many set bits is inside the DB, but its not working
LAR2 P#DBX 0.0
OPN "Alarmi"
L DBLG
L 8
*I

Lp: T #LoopSize
A [AR2,P#0.0]
JC inc
JU end
inc: L "Tag1".Alarm_count
L 1
+I
T "Tag1".Alarm_count


end: +AR2 P#0.1
L #LoopSize
LOOP Lp

Whats wrong over here?
 
Try this: (Note: pointer value is not shifted with shl 3 or multipled with number 8 now, because we want also look bit pattern (dbx x.0 .. x.7)



OPN DB100
L DBLG
T MD 30 // db-area lengt (bytes)

L MD 30
L 8
*I
T MD 34 // db-area lengt (bits)

L L#0 // zero for bit_pointer
T MD 38 // and bit_nmb_conter
T MD 42



a001: A DBX [MD 38] // check bit value
= M 50.0 // only for testing
JNB a002
L MD 42 // if bit=1 -> count up
L 1
+I
T MD 42

a002: L MD 38 // bit checked/counted up
L 1
+I // check next bit (pointer +1)
T MD 38

L MD 38
L MD 34 //loop back, if db-area not
//fully checked
>=I

JNB a001


NOP 0

 
I am trying to get how many set bits is inside the DB, but its not working
LAR2 P#DBX 0.0
OPN "Alarmi"
L DBLG
L 8
*I

Lp: T #LoopSize
A [AR2,P#0.0]
JC inc
JU end
inc: L "Tag1".Alarm_count
L 1
+I
T "Tag1".Alarm_count


end: +AR2 P#0.1
L #LoopSize
LOOP Lp

Whats wrong over here?


Looks like that you need only need zero alarm_count before looping, now alarm counter will keep adding from old counted value, when db-block is checked and new checkin is started:

LAR2 P#DBX 0.0
L 0
T "Tag1".Alarm_count

OPN "Alarmi"
L DBLG
L 8
*I

Lp: T #LoopSize
 
I always got Alarm_count is equal to 1 no matter how many bits is SET
Once they all are equal to false Alarm_Count becomes equal to 0

L "Tag1".Alarm_count
T "Tag1".Alarm_count_history

//

LAR2 P#DBX 0.0

L 0
T "Tag1".Alarm_count

OPN "Alarmi"
L DBLG
L 8
*I

Lp: T #LoopSize
SET
A [AR2,P#0.0]
JCN end

L "Tag1".Alarm_count
L 1
+I
T "Tag1".Alarm_count


end: +AR2 P#0.1
L #LoopSize
LOOP Lp
L "Tag1".Alarm_count
T MW 100


Mistake is somewhere here "A [AR2,P#0.0],+AR2 P#0.1"
I think at least
 
There is no mistake in your code as posted, here it is being used with a DB containing 3 bits that are true. Post the code you are running in an archived library as an attachment.

ac.JPG
 
I always got Alarm_count is equal to 1 no matter how many bits is SET
Once they all are equal to false Alarm_Count becomes equal to 0

L "Tag1".Alarm_count
T "Tag1".Alarm_count_history

//

LAR2 P#DBX 0.0

L 0
T "Tag1".Alarm_count

OPN "Alarmi"
L DBLG
L 8
*I

Lp: T #LoopSize
SET
A [AR2,P#0.0]
JCN end

L "Tag1".Alarm_count
L 1
+I
T "Tag1".Alarm_count


end: +AR2 P#0.1
L #LoopSize
LOOP Lp
L "Tag1".Alarm_count
T MW 100


Mistake is somewhere here "A [AR2,P#0.0],+AR2 P#0.1"
I think at least

Do you use FC or FB block for this? (if there is any difference, but FB blocks uses AR2 also deeply inside)
 
if I use datablock area for loopsize and alarmcount directly on loop, I get for some reasons area lenght errors.

But if I use memory marker area (MW) first and afterwards copy markers to db-area then PLC don't give area lengt errors
(I runned code at simulator, maybe some limits there with indirect addressing???)
 
There is no mistake in your code as posted, here it is being used with a DB containing 3 bits that are true. Post the code you are running in an archived library as an attachment.

Oops, yes there is a coding error:

Code:
OPN   "Alarmi"
      L     DBLG
      L     8
      *I    

Lp:   T     #LoopSize
      [COLOR=Red][B]OPN   "Alarmi"[/B][/COLOR] //this instruction required.
      SET   
      A      [AR2,P#0.0]
      JCN   end

      L     "Tag1".Alarm_count
 
Oops, yes there is a coding error:

Code:
OPN   "Alarmi"
      L     DBLG
      L     8
      *I    

Lp:   T     #LoopSize
      [COLOR=Red][B]OPN   "Alarmi"[/B][/COLOR] //this instruction required.
      SET   
      A      [AR2,P#0.0]
      JCN   end

      L     "Tag1".Alarm_count


why there is Set-command before A [AR2,P#0.0]?
 

Similar Topics

Hello, i am a beginner with a Siemens Logo 8 PLC. I would determine the direction of an object if it passes a whole cycle of 2 input sensors. See...
Replies
2
Views
181
Hi all, Just looking through the CIP_AXIS_DRIVE data type in a Logix controller to look for something that can tell me whether the current...
Replies
2
Views
1,065
I'm currently working on an MES interface PLC which passes around a whole bunch of strings. A lot of these strings are really just to allow for an...
Replies
0
Views
1,115
I don't use AB much these days, and any installs I've done in years past have been setup by myself from scratch, so I've always known what...
Replies
8
Views
2,082
Hello: I wonder if there is a way to find the CPU load of a Logix processor, and if it is not possible to determine this in an absolute way, I...
Replies
6
Views
1,996
Back
Top Bottom