STL Programming help again

STL???

Member
Join Date
Sep 2005
Location
UK
Posts
879
Hi,
I need to create a FC/FB to sort through DB error messages and prioritise them in the order of Importance. the values generated(x5) will be the basis for the display Text using the highest number as the highest priority.

I wrote a single block which when called in seperate instances (x5) does what i want,but i'm trying to combine it all into one call.

I'm having problems ironing out the issues with the code and tightening it up and would apprieciate some help!


Problem 1 - When DBX0.0 is set the CPU stops

Problem 2 - I've tried to add range protection to the Loop_index, but each way i try either stops the cpu or causes the Loop not to work!

FUNCTION "Alarm generator V3" : VOID
TITLE =
VERSION : 0.1


VAR_INPUT
Alarm_DB : BLOCK_DB ;
DB_Length : INT ;
END_VAR
VAR_IN_OUT
Loop_Index : INT ;
END_VAR
BEGIN
NETWORK
TITLE =Check Range

L #DB_Length;
L 0; // if zero then no further bits to interrogate
<=I ;
BEC ;

OPN #Alarm_DB; // Open Alarm Datablock
NETWORK
TITLE =Scan the Alarm DB Looking for Active Faults
//
//
//
L #DB_Length; // Total number of Alarm bits to scan
TOP: T #Loop_Index;
+ -1; // align index to array i.e dbx0.0 = ALARM[1]
LAR1 ;

A DBX [AR1,P#0.0]; // Scan for match
JC ERR1; // Jump out if match found
L #Loop_Index;
LOOP TOP; // minus 1 from index and re-scan until match or zero achieved

//No match found
L 0;
T #Loop_Index;
JU end;

//Match found
ERR1: L #Loop_Index;
T DBW [AR2,P#14.0]; // Point to beginning of Text storage (DBW14)

+AR2 P#2.0; // increment pointer to transfer additional matches to next word (max 5)
TAK ; // move index back to accu 1
JC TOP;

end: NOP 0;






END_FUNCTION


 
Going back to basics, i can get it to work:

OPN DB 2
L 50

Top: T #Loop_Index
+ -1
LAR1

A DBX [AR1,P#0.0]
JC ALM

L #Loop_Index
LOOP Top

L 0
T #Loop_Index
JU CLR

ALM: L #Loop_Index
T DBW [AR2,P#14.0]
CLR: NOP 0




Problems are to increment the + ar2 offset and re-enter the Loop were it left off!
 
Right! this works but its a bit of a jump mess...
        OPN   DB     2
L 50

Top: T #Loop_Index
+ -1
LAR1

A DBX [AR1,P#0.0]
JC ALM

L #Loop_Index
LOOP Top

L 0
T #Loop_Index
JU End

ALM: L #Loop_Index
T DBW [AR2,P#14.0]
// rescan

L 1
<=I
JC End

+AR2 P#2.0
TAK
+ -1
JU Top


End: NOP 0




not sure i understand why i need the + -1 (in red) when 1 is removed at label Top, however without it the 5 word registers get filled with the same result!
 
Good point, i hadnt thought about that, i could initialise it before the loop starts, I used a FC to remove any issues with IDB and AR2.
 
The Loop decreases the variable, all the way to 0 I believe.

In yiur original block, if you subtracted 1 from the DB_Length before the label TOP it should be OK.

i.e.

Code:
[/size][/font]
		  L	 #DB_Length; // Total number of Alarm bits to scan
		  +	 -1; // align index to array i.e dbx0.0 = ALARM[1]

	TOP:  T	 #Loop_Index; 
		
		  LAR1  ;


I would also at the start do the following have temp called AR2_Store and save AR2 into it at the start, then set AR2 to zero and at the end recover AR2 before leaving the block.
 
Hi Peter,
I was going to store/restore AR2 in the final version of the code and revert back to a variable for DB number and Scan index,But at the moment i'm just trying to see if i have removed all the issues with it.

Ill try moving the -1 back and see how that goes!

Cheers Steve
 
Hi

you want to scan bits right from top to bottom

OPN #Alarm_DB; // Open Alarm Datablock
L #DB_Length; // Total number of Alarm bits to scan
T
#Loop_Index;
TOP:L #Loop_Index; // make this 32 bits wide

A DBX [
#Loop_Index]; // Scan for match
JC ERR1; // Jump out if match found

L #Loop_Index;
DEC 1
LOOP TOP; // minus 1 from index and re-scan until match or zero achieved

L 0;
T #Loop_Index;

JU end;
ERR1: L #Loop_Index // is value in bits
INC 112 // Is offset but must be bits so 14x8
T DBW[
#Loop_Index]
// T DBW [AR2,P#14.0]; // Point to beginning of Text storage (DBW14)



try this ... could still be full of bugs . but I prefer the
L or T DBW or DBX [Pointer in double and bit]

ie L 20
SLW 3
T MD200 Call DBxx
L DBW[MD200] to load DW200

L 20
+1
T MD200
Call DBxx
A DBX[MD200] to 'and' DBxx.DBX20.1

Bye

Eric

 
Its the index number of the alarm bit i'm interested in, to display as follows:
Testtable.JPG

alarmview.JPG
 
To make the code even more compact try to remove Loop_Index:

LAR2 p#0.0 //clean up - don't forget to store it before
OPN DB 2
L 50
+ -1

Top: LAR1

A DBX [AR1,P#0.0]
JCN CONT // continue

T DBW [AR2,P#14.0]
+AR2 P#2.0

CONT: LOOP Top

End: NOP 0


BTW, the red "+ -1" you need because you jump over the "LOOP" command
 
        OPN   DB     2
L 50

Top: T #Loop_Index // Loop_index is 50
+ -1
LAR1

A DBX [AR1,P#0.0]
JC ALM

L #Loop_Index
LOOP Top

L 0
T #Loop_Index
JU End

ALM: L #Loop_Index // Loop_index is still 50
T DBW [AR2,P#14.0]
// rescan

L 1
<=I
JC End

+AR2 P#2.0
TAK // Loop_index is still 50
+ -1 // Needed to simulate the LOOP instruction, that decrements the value automatically
JU Top


End: NOP 0




Thats why you need the + -1. Or did I miss anything?

Jeebs
 
Jeebs said:
  
Thats why you need the + -1. Or did I miss anything?

Jeebs



The Loop instruction decrements whats in the accumulator by 1. The reason he had to decerement it at that point is because he jumped over the loop instruction.

 
jacekd,
To make the code even more compact try to remove Loop_Index:

LAR2 p#0.0 //clean up - don't forget to store it before
OPN DB 2
L 50
+ -1

Top: LAR1

A DBX [AR1,P#0.0]
JCN CONT // continue

T DBW [AR2,P#14.0]
+AR2 P#2.0

CONT: LOOP Top

End: NOP 0

BTW, the red "+ -1" you need because you jump over the "LOOP" command

Thanks for posting that, it has given me a different perspective on things, however for some reason (which i cant figure out)it ignores DBX0.0 when set and instead assigns the value of 1 to dbx0.1 which should be 2?

Newtest.JPG


Thanks to everyone so far who has helped me with this.
 
STL??? said:
however for some reason (which i cant figure out)it ignores DBX0.0 when set and instead assigns the value of 1 to dbx0.1 which should be 2?

You really mean assigns 1 to DBW14 don't you ?

Did you want to search from the bottom of the list backwards, or is this just the way it turned out.
 
STL??? said:
...however for some reason (which i cant figure out)it ignores DBX0.0 when set and instead assigns the value of 1 to dbx0.1 which should be 2...

My fault. Some corrections below.

LAR2 p#0.0 //clean up - don't forget to store it before
OPN DB 2
L 50

Top: + -1
LAR1
+ 1
A DBX [AR1,P#0.0]
JCN CONT // continue

T DBW [AR2,P#14.0]
+AR2 P#2.0

CONT: LOOP Top

End: NOP 0
 

Similar Topics

I have a programming problem. I was originally asked to read and display a flowmeter with a 4-20mA o/p and display a continuous flow reading. The...
Replies
4
Views
2,342
Hello all, I want (need to learn ) STL programming. I never use it because i solwe all the problem in LAD diagrams. But now for some testing i...
Replies
4
Views
1,559
I'm new in STL programming, today I was checking some example codes and found this: L 1 L QB 4 SLW T QB 4 SET SAVE...
Replies
5
Views
2,555
Dear experts, I m new to the STL programming and I have a problem that I can not solve. I'm working on a program that controls the...
Replies
2
Views
2,696
Hello everyone! I've just stared with programming on STL and I have problem which I can't understand. I'm writing programs on Step 7 and I'm...
Replies
2
Views
2,173
Back
Top Bottom