Programming error

Hi, I have a problem, I need to detect what bits that are becoming low when a negative edge of a general bit happens.

this is the fault in S7 that I get on my code that I tried to write for it:

aligig.JPG


This is the source code:

FUNCTION_BLOCK "BIT LOGGER"
TITLE =BIT LOGGER
VERSION : 0.1

VAR_INPUT
FN_MAIN : BOOL ;
bit_0 : BOOL ;
bit_1 : BOOL ;
bit_2 : BOOL ;
bit_3 : BOOL ;
bit_4 : BOOL ;
bit_5 : BOOL ;
bit_6 : BOOL ;
bit_7 : BOOL ;
bit_8 : BOOL ;
bit_9 : BOOL ;
bit_10 : BOOL ;
bit_11 : BOOL ;
bit_12 : BOOL ;
bit_13 : BOOL ;
bit_14 : BOOL ;
bit_15 : BOOL ;
END_VAR
VAR_OUTPUT
LOGGED_DT : DATE_AND_TIME ;
Mbit_0 : BOOL ;
Mbit_1 : BOOL ;
Mbit_2 : BOOL ;
Mbit_3 : BOOL ;
Mbit_4 : BOOL ;
Mbit_5 : BOOL ;
Mbit_6 : BOOL ;
Mbit_7 : BOOL ;
Mbit_8 : BOOL ;
Mbit_9 : BOOL ;
Mbit_10 : BOOL ;
Mbit_11 : BOOL ;
Mbit_12 : BOOL ;
Mbit_13 : BOOL ;
Mbit_14 : BOOL ;
Mbit_15 : BOOL ;
END_VAR
VAR
MEMO : WORD ;
FN_MEM : BOOL ;
DT_ACT : DATE_AND_TIME ;
DT_MEM : STRUCT
DT_ACT : DATE_AND_TIME ;
FN_MEM : BOOL ;
MEMO : WORD ;
DT_YEAR : BYTE ;
DT_MONTH : BYTE ;
DT_DAY : BYTE ;
DT_HOUR : BYTE ;
DT_MINUTE : BYTE ;
DT_SECOND : BYTE ;
DT_mS_DOW_1 : BYTE ;
DT_mS_DOW_2 : BYTE ;
END_STRUCT ;
END_VAR
VAR_TEMP
FLT_1 : INT ;
FLT_2 : INT ;
END_VAR
BEGIN
NETWORK
TITLE =EVALUATE BITS + DATE&TIME

A #FN_MAIN;
FN #FN_MEM;
JCN SND;
CALL "READ_CLK" (
RET_VAL := #FLT_1,
CDT := #DT_ACT);
LAR1 P##bit_0;
L LW [AR1,P#0.0];
T #MEMO;
LAR2 P##DT_ACT;
L DIB [AR2,P#0.0];
T #DT_MEM.DT_YEAR;
L DIB [AR2,P#1.0];
T #DT_MEM.DT_MONTH;
L DIB [AR1,P#2.0];
T #DT_MEM.DT_DAY;
L DIB [AR1,P#3.0];
T #DT_MEM.DT_HOUR;
L DIB [AR1,P#4.0];
T #DT_MEM.DT_MINUTE;
L DIB [AR1,P#5.0];
T #DT_MEM.DT_SECOND;
L DIB [AR1,P#6.0];
T #DT_MEM.DT_mS_DOW_1;
L DIB [AR1,P#7.0];
T #DT_MEM.DT_mS_DOW_2;
NETWORK
TITLE =SEND LOGGED DATA

SND: LAR1 P##LOGGED_DT;
CALL "BLKMOV" (
SRCBLK := #DT_MEM,
RET_VAL := #FLT_2,
DSTBLK := #LOGGED_DT);
LAR2 P##Mbit_0;
A #FN_MAIN;
= #Mbit_0;
A #bit_0;
= #Mbit_1;
A #bit_1;
= #Mbit_2;
A #bit_2;
= #Mbit_3;
A #bit_3;
= #Mbit_4;
A #bit_4;
= #Mbit_5;
A #bit_5;
= #Mbit_6;
A #bit_6;
= #Mbit_7;
A #bit_7;
= #Mbit_8;
A #bit_8;
= #Mbit_9;
A #bit_9;
= #Mbit_10;
A #bit_10;
= #Mbit_11;
A #bit_11;
= #Mbit_12;
A #bit_12;
= #Mbit_13;
A #bit_13;
= #Mbit_14;
A #bit_14;
= #Mbit_15;

END_FUNCTION_BLOCK
 
You cannot use AR2 for indirect addressing inside a function block and access static data variables at the same time. If you want to use AR2 you must first save the current value of AR2 in a temp variable, use AR2 for indirect addressing (making sure you do not access any in/out/in_out/static variables), then restore AR2 to allow access to static variables etc.
 
...

I don't understand

L D[AR2 said:
You cannot use AR2 for indirect addressing inside a function block and access static data variables at the same time. If you want to use AR2 you must first save the current value of AR2 in a temp variable, use AR2 for indirect addressing (making sure you do not access any in/out/in_out/static variables), then restore AR2 to allow access to static variables etc.
 
Well spotted, I knew there had to be a link somewhere.

Combo - looking at the required functionality of your block, on the negative edge of FN_MAIN the clock is read and stored in static data. At all other times, the stored clock value is copied to the output and all but one of the inputs are copied to the outputs (shifted up one bit). Is this correct ? - it seems like you want to take a copy of the inputs on the negative edge and store the input states as well as the date.
 
...

That's what I want to do...

I made the program a bit better, but still goes to stop on a negative edge...

I'll to understand the problem with the AR1 AR2

Here is the new code:

bbbx.JPG


L D[AR2 said:
Well spotted, I knew there had to be a link somewhere.

Combo - looking at the required functionality of your block, on the negative edge of FN_MAIN the clock is read and stored in static data. At all other times, the stored clock value is copied to the output and all but one of the inputs are copied to the outputs (shifted up one bit). Is this correct ? - it seems like you want to take a copy of the inputs on the negative edge and store the input states as well as the date.
 
...

If I only use AR1 it would work...

I'll try this

L D[AR2 said:
You cannot use AR2 for indirect addressing inside a function block and access static data variables at the same time. If you want to use AR2 you must first save the current value of AR2 in a temp variable, use AR2 for indirect addressing (making sure you do not access any in/out/in_out/static variables), then restore AR2 to allow access to static variables etc.
 
currently

currently:

FUNCTION_BLOCK "BIT LOGGER"
TITLE =BIT LOGGER
VERSION : 0.1

VAR_INPUT
FN_MAIN : BOOL ;
bit_0 : BOOL ;
bit_1 : BOOL ;
bit_2 : BOOL ;
bit_3 : BOOL ;
bit_4 : BOOL ;
bit_5 : BOOL ;
bit_6 : BOOL ;
bit_7 : BOOL ;
bit_8 : BOOL ;
bit_9 : BOOL ;
bit_10 : BOOL ;
bit_11 : BOOL ;
bit_12 : BOOL ;
bit_13 : BOOL ;
bit_14 : BOOL ;
bit_15 : BOOL ;
END_VAR
VAR_OUTPUT
LOGGED_DT : DATE_AND_TIME ;
Mbit_0 : BOOL ;
Mbit_1 : BOOL ;
Mbit_2 : BOOL ;
Mbit_3 : BOOL ;
Mbit_4 : BOOL ;
Mbit_5 : BOOL ;
Mbit_6 : BOOL ;
Mbit_7 : BOOL ;
Mbit_8 : BOOL ;
Mbit_9 : BOOL ;
Mbit_10 : BOOL ;
Mbit_11 : BOOL ;
Mbit_12 : BOOL ;
Mbit_13 : BOOL ;
Mbit_14 : BOOL ;
Mbit_15 : BOOL ;
END_VAR
VAR
MEMO : WORD ;
FN_MEM : BOOL ;
DT_ACT : DATE_AND_TIME ;
DT_MEM : STRUCT
DT_ACT : DATE_AND_TIME ;
FN_MEM : BOOL ;
MEMO : WORD ;
DT_YEAR : BYTE ;
DT_MONTH : BYTE ;
DT_DAY : BYTE ;
DT_HOUR : BYTE ;
DT_MINUTE : BYTE ;
DT_SECOND : BYTE ;
DT_mS_DOW_1 : BYTE ;
DT_mS_DOW_2 : BYTE ;
END_STRUCT ;
END_VAR
VAR_TEMP
FLT_1 : INT ;
FLT_2 : INT ;
END_VAR
BEGIN
NETWORK
TITLE =EVALUATE BITS + DATE&TIME

A #FN_MAIN;
FN #FN_MEM; // Negative Edge
JCN SND;
CALL "READ_CLK" (// Actual Date & Time
RET_VAL := #FLT_1,
CDT := #DT_ACT);
LAR1 P##bit_0; // Save state of the 16 bits
L DIW [AR1,P#0.0];
T #MEMO;
LAR1 P##DT_ACT; // Save Date & Time
L DIB [AR1,P#0.0];
T #DT_MEM.DT_YEAR;
L DIB [AR1,P#1.0];
T #DT_MEM.DT_MONTH;
L DIB [AR1,P#2.0];
T #DT_MEM.DT_DAY;
L DIB [AR1,P#3.0];
T #DT_MEM.DT_HOUR;
L DIB [AR1,P#4.0];
T #DT_MEM.DT_MINUTE;
L DIB [AR1,P#5.0];
T #DT_MEM.DT_SECOND;
L DIB [AR1,P#6.0];
T #DT_MEM.DT_mS_DOW_1;
L DIB [AR1,P#7.0];
T #DT_MEM.DT_mS_DOW_2;
NETWORK
TITLE =SEND LOGGED DATA

SND: CALL "BLKMOV" (// Send logged Date & Time
SRCBLK := #DT_MEM,
RET_VAL := #FLT_2,
DSTBLK := #LOGGED_DT);
LAR1 P##Mbit_0; // Send logged 16 bits
L #MEMO;
T DIW [AR1,P#0.0];
END_FUNCTION_BLOCK
 
The error in your code concerns these instructions:

Code:
LAR1 P##bit_0; // Save state of the 16 bits
L DIW [AR1,P#0.0];

bit_0 is the second boolean parameter so AR1 will contain a non-zero bit address. Attempting to access a word with a non-zero bit address will result in an alignment error. Here's an alternative implementation that does not require indirect addressing.

Code:
FUNCTION_BLOCK FB 100
TITLE =BIT LOGGER
VERSION : 0.1

VAR_INPUT
  FN_MAIN : BOOL ; 
  bit_0 : BOOL ; 
  bit_1 : BOOL ; 
  bit_2 : BOOL ; 
  bit_3 : BOOL ; 
  bit_4 : BOOL ; 
  bit_5 : BOOL ; 
  bit_6 : BOOL ; 
  bit_7 : BOOL ; 
  bit_8 : BOOL ; 
  bit_9 : BOOL ; 
  bit_10 : BOOL ; 
  bit_11 : BOOL ; 
  bit_12 : BOOL ; 
  bit_13 : BOOL ; 
  bit_14 : BOOL ; 
  bit_15 : BOOL ; 
END_VAR
VAR_OUTPUT
  LOGGED_DT : DATE_AND_TIME ; 
  Mbit_0 : BOOL ; 
  Mbit_1 : BOOL ; 
  Mbit_2 : BOOL ; 
  Mbit_3 : BOOL ; 
  Mbit_4 : BOOL ; 
  Mbit_5 : BOOL ; 
  Mbit_6 : BOOL ; 
  Mbit_7 : BOOL ; 
  Mbit_8 : BOOL ; 
  Mbit_9 : BOOL ; 
  Mbit_10 : BOOL ; 
  Mbit_11 : BOOL ; 
  Mbit_12 : BOOL ; 
  Mbit_13 : BOOL ; 
  Mbit_14 : BOOL ; 
  Mbit_15 : BOOL ; 
END_VAR
VAR
  MEMO : WORD ; 
  FN_MEM : BOOL ; 
  DT_ACT : DATE_AND_TIME ; 
  DT_MEM : STRUCT  
   DT_ACT : DATE_AND_TIME ; 
   FN_MEM : BOOL ; 
   MEMO : WORD ; 
   DT_YEAR : BYTE ; 
   DT_MONTH : BYTE ; 
   DT_DAY : BYTE ; 
   DT_HOUR : BYTE ; 
   DT_MINUTE : BYTE ; 
   DT_SECOND : BYTE ; 
   DT_mS_DOW_1 : BYTE ; 
   DT_mS_DOW_2 : BYTE ; 
  END_STRUCT ; 
END_VAR
VAR_TEMP
  FLT_1 : INT ; 
  FLT_2 : INT ; 
END_VAR
BEGIN
NETWORK
TITLE =EVALUATE BITS + DATE&TIME
	  A	 #FN_MAIN; 
	  FN	#FN_MEM; // Negative Edge
	  JCN   Exit; 
	  CALL SFC	1 (// Actual Date & Time
		   RET_VAL				  := #FLT_1,
		   CDT					  := #DT_ACT);
	  CALL SFC   20 (// Send logged Date & Time
		   SRCBLK				   := #DT_ACT,
		   RET_VAL				  := #FLT_2,
		   DSTBLK				   := #LOGGED_DT);
	  A	 #bit_0; 
	  =	 #Mbit_0; 
	  A	 #bit_1; 
	  =	 #Mbit_1; 
	  A	 #bit_2; 
	  =	 #Mbit_2; 
	  A	 #bit_3; 
	  =	 #Mbit_3; 
	  A	 #bit_4; 
	  =	 #Mbit_4; 
	  A	 #bit_5; 
	  =	 #Mbit_5; 
	  A	 #bit_6; 
	  =	 #Mbit_6; 
	  A	 #bit_7; 
	  =	 #Mbit_7; 
	  A	 #bit_8; 
	  =	 #Mbit_8; 
	  A	 #bit_9; 
	  =	 #Mbit_9; 
	  A	 #bit_10; 
	  =	 #Mbit_10; 
	  A	 #bit_11; 
	  =	 #Mbit_11; 
	  A	 #bit_12; 
	  =	 #Mbit_12; 
	  A	 #bit_13; 
	  =	 #Mbit_13; 
	  A	 #bit_14; 
	  =	 #Mbit_14; 
	  A	 #bit_15; 
	  =	 #Mbit_15; 
NETWORK
TITLE =exit
Exit: SET   ; 
	  SAVE  ; 
END_FUNCTION_BLOCK
 
...

I now understand the problem, but...

Is adress 0.1 not permitted then ? It allways has to start from 0.0 ?
Indeed, if you declare a new word or integer, or real, it always will start with a x.0 offset...


I replaced FN_MAIN, so that everything works, and it does now.

I'm doing the bits via the adress register because I want the tobe stored in the Instance DB.

Thanks, you are a big help !!!


:geek:


L D[AR2 said:
The error in your code concerns these instructions:

Code:
LAR1 P##bit_0; // Save state of the 16 bits
L DIW [AR1,P#0.0];

bit_0 is the second boolean parameter so AR1 will contain a non-zero bit address. Attempting to access a word with a non-zero bit address will result in an alignment error. Here's an alternative implementation that does not require indirect addressing.
 
Final result

Final result:

Code:
FUNCTION_BLOCK "BIT LOGGER"
TITLE =BIT LOGGER
VERSION : 0.1

VAR_INPUT
  bit_0 : BOOL ; 
  bit_1 : BOOL ; 
  bit_2 : BOOL ; 
  bit_3 : BOOL ; 
  bit_4 : BOOL ; 
  bit_5 : BOOL ; 
  bit_6 : BOOL ; 
  bit_7 : BOOL ; 
  bit_8 : BOOL ; 
  bit_9 : BOOL ; 
  bit_10 : BOOL ; 
  bit_11 : BOOL ; 
  bit_12 : BOOL ; 
  bit_13 : BOOL ; 
  bit_14 : BOOL ; 
  bit_15 : BOOL ; 
  FN_MAIN : BOOL ; 
END_VAR
VAR_OUTPUT
  Mbit_0 : BOOL ; 
  Mbit_1 : BOOL ; 
  Mbit_2 : BOOL ; 
  Mbit_3 : BOOL ; 
  Mbit_4 : BOOL ; 
  Mbit_5 : BOOL ; 
  Mbit_6 : BOOL ; 
  Mbit_7 : BOOL ; 
  Mbit_8 : BOOL ; 
  Mbit_9 : BOOL ; 
  Mbit_10 : BOOL ; 
  Mbit_11 : BOOL ; 
  Mbit_12 : BOOL ; 
  Mbit_13 : BOOL ; 
  Mbit_14 : BOOL ; 
  Mbit_15 : BOOL ; 
  LOGGED_DT : DATE_AND_TIME ; 
END_VAR
VAR
  FN_MEM : BOOL ; 
  DT_ACT : DATE_AND_TIME ; 
  DT_MEM : DATE_AND_TIME ; 
  MEMO : WORD ; 
END_VAR
VAR_TEMP
  FLT_1 : INT ; 
  FLT_2 : INT ; 
  FLT_3 : INT ; 
END_VAR
BEGIN
NETWORK
TITLE =EVALUATE BITS + DATE&TIME

	  A	 #FN_MAIN; 
	  FN	#FN_MEM; // Negative Edge
	  JCN   SND; 
	  CALL "READ_CLK" (// Actual Date & Time
		   RET_VAL				  := #FLT_1,
		   CDT					  := #DT_ACT);
	  CALL "BLKMOV" (// Save Date & Time
		   SRCBLK				   := #DT_ACT,
		   RET_VAL				  := #FLT_2,
		   DSTBLK				   := #DT_MEM);
	  LAR1  P##bit_0; // Save state of the 16 bits
	  L	 DIW [AR1,P#0.0]; 
	  T	 #MEMO; 
NETWORK
TITLE =SEND LOGGED DATA

SND:  CALL "BLKMOV" (// Send logged Date & Time
		   SRCBLK				   := #DT_MEM,
		   RET_VAL				  := #FLT_3,
		   DSTBLK				   := #LOGGED_DT);
	  LAR1  P##Mbit_0; // Send logged 16 bits
	  L	 #MEMO; 
	  T	 DIW [AR1,P#0.0]; 
END_FUNCTION_BLOCK
 

Similar Topics

I have a customer who had a faulty Siemens OP7. They sourced a replacement. They have the original program. I downloaded the program to the...
10
Replies
4,066
Views
Hello. I first off I wanna say that I am completely new to PLCs and am trying to help fix my Uncles hydraulic press machine that uses a Mitsubishi...
2
Replies
4,612
Views
Hello all I have an internal error on S7-416 PLC. You can see the diagnostic in the attached file. Can someone explain me the module number in...
5
Replies
2,389
Views
This problem is a little easy for this board but it is driving me mad so i can use the help. I'm using a PID FB from the TwinCAT PLC Library...
2
Replies
2,793
Views
I want to use register 8107 of a Sy/Max 400 to point to an error register stack but not sure how to program the rung to reserve this 16 register...
0
Replies
2,066
Views
Top