Two codes

Automatiker

Member
Join Date
Feb 2006
Location
Saarland
Posts
41
Hi,

why two following codes work differently?

First code:

TAR1
T #AR1_Temp
TAR2
T #AR2_Temp

AUF "DB_Taktband"
LAR1 P#DBX 2.1

AUF DI 108
LAR2 P#DIX 58.0

L 16
Nxt2: T #Laufvariable
U [AR1,P#0.0]
= [AR2,P#0.0]

L "DB_Taktband".SteinLaenge
+AR1

L P#0.1
+AR2

L #Laufvariable
LOOP Nxt2

L #AR1_Temp
LAR1
L #AR2_Temp
LAR2

and the second code:

TAR1
T #AR1_Temp
TAR2
T #AR2_Temp

AUF "DB_Taktband"
LAR1 P#DBX 2.1

AUF DB 108
LAR2 P#DBX 58.0

L 16
Nxt2: T #Laufvariable
U [AR1,P#0.0]
= [AR2,P#0.0]

L "DB_Taktband".SteinLaenge
+AR1

L P#0.1
+AR2

L #Laufvariable
LOOP Nxt2

L #AR1_Temp
LAR1
L #AR2_Temp
LAR2

The only difference ist that in the first one is

AUF DI 108
LAR2 P#DIX 58.0

instead of

AUF DB 108
LAR2 P#DBX 58.0


As a hint I can say that the second one does not work :)
 
In your first example, the DB opened as an instance is assigned to AR2, However in your second example the second AUF DB is the DB number used indirectly.

When monitoring this online use the "Indirect",AR1 and AR2 options
This should show whats happening.

If im wrong, im sure Simon or Peter will correct me! :)
 
This first implementation uses ar1 for the global data access and ar2 for the instance DB access.

The second implementation uses global DB's for both AR1 and AR2 accesses and is hence doomed to fail.
 
Last edited:
An alternative fix (in italics) is shown below. This should make it more obvious why the code didn't work.

Code:
TAR1 
T #AR1_Temp
TAR2 
T #AR2_Temp

AUF "DB_Taktband"
LAR1 P#DBX 2.1 

AUF DB 108
LAR2 P#DBX 58.0 

L 16
Nxt2: T #Laufvariable
[i][b]AUF "DB_Taktband" //open DB for AR1 access[/b][/i]
U [AR1,P#0.0]
[b][i]AUF DB108		 //open DB for AR2 access[/i][/b]
= [AR2,P#0.0]

L "DB_Taktband".SteinLaenge [b]//note! [i]"DB_Taktband" is now open[/i][/b] 
+AR1 

L P#0.1
+AR2 

L #Laufvariable
LOOP Nxt2

L #AR1_Temp
LAR1 
L #AR2_Temp
LAR2
 
Hi Simon,

I still don't catch it. What do I do exactly with AUF DB108 and AUF DI 108? What happens with AR1 and AR2? What happens with registers DB1 and DB2 in both cases?

The only difference in your code

Nxt2: T #Laufvariable
AUF "DB_Taktband" //open DB for AR1 access
U [AR1,P#0.0]
AUF DB108 //open DB for AR2 access
= [AR2,P#0.0]
is that you do AUF "DB_Taktband" and AUF DB108. But how can "programm" know that AUF DB_Taktband is for AR1 and AUF DB108 for AR2?

Or maybe I destroy that what was in AR1 or AR2 in a loop? But how?
 
AR1 and AR2 are address registers - they do not specify which DB will be used. You need to open the correct DB beforehand.
 
Last edited:
Simon,
as a first on I implemented the second one. But it didn't work. So I tried with the first one. It worked, but I didn't understand why.
 
Program doesn't know this. AR1 and AR2 content isn't changed when OPN (AUF) is executed. Your AR1 and AR2 point to DBX - but not to concrete DBX which belongs to "DB_Taktband" or DB108, only to bit in DB. When you open DB (DI) DB1 (DB2) content changes to opened DB (DI).
 
Simon, I'm a little confused with that too.

In the solution you put, you opened then two DB's prior to accessing the the bits within. This is the same as normal programming.

I know if you want to pass data between DB's and you don't want the extra time and memory used to opening the two DB's sequentially, as your example above, you can open the second DB as an instance DB, whether its really an instance or not.

i.e.

OPN DB10
A DBX 5.0
OPN DB20
= DBX 5.0

OPN DB10
A DBX 5.1
OPN DB20
= DBX 5.1

etc.

can be done simpler as

OPN DB10
OPN DI20

A DBX 5.0
= DIX 5.0

A DBX 5.1
= DIX 5.1

So what your examples done is to do the same as the first option.


I think the problem with the second code could be the fact that the pointer generated was a pointer of DBX 58.0 only as the instruction LAR2 P#DBX 58.0 does not cater for the DB address ( I maybe wrong), so when the transferring takes place later on, the AR2 naturally looked at the current DI address as that is what AR2 normal function is, as a DI had not been specified (or the wrong DI is specified) it crashes.




EDIT:

I was so long writing this the conversation overtook me :oops:
 
PeterW said:
I think the problem with the second code could be the fact that the pointer generated was a pointer of DBX 58.0 only as the instruction LAR2 P#DBX 58.0 does not cater for the DB address ( I maybe wrong), so when the transferring takes place later on, the AR2 naturally looked at the current DI address as that is what AR2 normal function is, as a DI had not been specified (or the wrong DI is specified) it crashes.
Yes, using of DB and DI is shorter and faster.
AUF "DB_Taktband" // DB1 -> DB_Taktband
LAR1 P#DBX 2.1 // AR1 points to "DB_Taktband".DBX2.1

AUF DB 108 // DB1 -> DB108
LAR2 P#DBX 58.0 // AR2 points to DB108.DBX58.0

L 16
Nxt2: T #Laufvariable
U [AR1,P#0.0] // AR1 -> DB108.DBX2.1, not to DB_Taktband in first loop scan!!!
= [AR2,P#0.0]
 

Similar Topics

Hi all, i have 8 CJ2m plc units that show different numbers on the plc display and i am stuck on reading the info. my unit has an ip address of...
Replies
3
Views
150
Hi there! I've been looking for some fault codes table for the 1734-AENTR adapters, since I'd like to show a message in HMI with some...
Replies
1
Views
599
I just took a skim through 81346-2:2019 and was wondering which codes you all used for Safety devices like Safety Controllers, EStops, and guard...
Replies
0
Views
576
Does anybody happen to have a list of error codes for the Toshiba Provisor TC200? My TCPCU-1 module keeps showing codes 043,109,111,118 and 119...
Replies
0
Views
334
One of our running machine's DeviceNet Module (1747-SDN) had malfunctioned. So, we replaced it with a new one from spares. We maintained the...
Replies
4
Views
3,121
Back
Top Bottom