naturephoenix
Member
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
OPN DB 4
L DBLG
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?
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.
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