Siemens S7, best way to copy PIB to DB

Werner

Member
Join Date
Apr 2005
Location
IJsselstein
Posts
336
Hi there!

Does any of you have a program available for copying PIB data to a DB.

What I need is:

L PIB 512
T DB201.DBB0
L PIB 513
T DB201.DBB4
L PIB 514
T DB201.DBB8

etc.

I would like the start address to be adjustable (in this case 512 with a adjustable number of repititions after that ranging from 1 to 16)

Any cleaver ideas on how to do this in a way that is not increasing the PLC cycle time to much? Other wise I might be better of by typing it all.

(7x16 Byte transfers for the inputs and 7x16 Byte transfer for the outputs so that's 448 lines of code.....Which I might be able to generate in a source file but still a lot of work)
 
Source code for a block below. If the DB number doesn't change then remove it as a parameter and hard code the open DB in the FC instead.

Code:
FUNCTION FC 1 : VOID
TITLE =
VERSION : 0.1

VAR_INPUT
  iPeripheralBaseAddress : INT ; 
  iDBNumber : INT ; 
  iDBByteOffset : INT ; 
  iByteCount : INT ; 
END_VAR
VAR_TEMP
  iDB : INT ; 
  iLoopCount : INT ; 
END_VAR
BEGIN
NETWORK
TITLE =
      LAR1  P#P  0.0; 
      L     #iPeripheralBaseAddress; 
      SLD   3; 
      +AR1  ; 
      LAR2  P#DBX 0.0; 
      L     #iDBByteOffset; 
      SLD   3; 
      +AR2  ; 
      L     #iDBNumber; 
      T     #iDB; 
      OPN   DB [#iDB]; 
      L     #iByteCount; 
LP:   T     #iLoopCount; 
      L     B [AR1,P#0.0]; 
      T     B [AR2,P#0.0]; 
      +AR1  P#1.0; 
      +AR2  P#4.0; 
      L     #iLoopCount; 
      LOOP  LP; 
      SET   ; 
      SAVE  ; 
END_FUNCTION
 
Thanks!

I don't need the DB to be adjustable. So for the cross reference part I think it would be nice to skip that part. I will give it a try!

Thanks again!
 
If I want to use a simulare routine to copy from DB to outputs (PQB) can I then use the same code and just reverse the L and T line?

Code:
LP:   T     #tLoopCount
      L     B [AR2,P#0.0] // B [AR1, P#0.0]
      T     B [AR1,P#0.0] // B [AR2, P#0.0]
 
Yep - that will work.

Here's another version that is slightly bigger but is quicker and will only deal with up to 16 bytes to copy.

Code:
FUNCTION FC 11 : VOID
TITLE =
VERSION : 0.1
 
VAR_INPUT
  iPeripheralBaseAddress : INT ; 
  iDBByteOffset : INT ; 
  iByteCount : INT ; 
END_VAR
BEGIN
NETWORK
TITLE =
      LAR1  P#P  0.0; 
      L     #iPeripheralBaseAddress; 
      SLD   3; 
      +AR1  ; 
      LAR2  P#DBX 0.0; 
      L     #iDBByteOffset; 
      SLD   3; 
      +AR2  ; 
      OPN   DB   201; 
      L     #iByteCount; 
      JL    cop; 
      JU    c0; 
      JU    c1; 
      JU    c2; 
      JU    c3; 
      JU    c4; 
      JU    c5; 
      JU    c6; 
      JU    c7; 
      JU    c8; 
      JU    c9; 
      JU    c10; 
      JU    c11; 
      JU    c12; 
      JU    c13; 
      JU    c14; 
      JU    c15; 
      JU    c16; 
cop:  JU    exit; 
c16:  L     B [AR1,P#15.0]; 
      T     B [AR2,P#60.0]; 
c15:  L     B [AR1,P#14.0]; 
      T     B [AR2,P#56.0]; 
c14:  L     B [AR1,P#13.0]; 
      T     B [AR2,P#52.0]; 
c13:  L     B [AR1,P#12.0]; 
      T     B [AR2,P#48.0]; 
c12:  L     B [AR1,P#11.0]; 
      T     B [AR2,P#44.0]; 
c11:  L     B [AR1,P#10.0]; 
      T     B [AR2,P#40.0]; 
c10:  L     B [AR1,P#9.0]; 
      T     B [AR2,P#36.0]; 
c9:   L     B [AR1,P#8.0]; 
      T     B [AR2,P#32.0]; 
c8:   L     B [AR1,P#7.0]; 
      T     B [AR2,P#28.0]; 
c7:   L     B [AR1,P#6.0]; 
      T     B [AR2,P#24.0]; 
c6:   L     B [AR1,P#5.0]; 
      T     B [AR2,P#20.0]; 
c5:   L     B [AR1,P#4.0]; 
      T     B [AR2,P#16.0]; 
c4:   L     B [AR1,P#3.0]; 
      T     B [AR2,P#12.0]; 
c3:   L     B [AR1,P#2.0]; 
      T     B [AR2,P#8.0]; 
c2:   L     B [AR1,P#1.0]; 
      T     B [AR2,P#4.0]; 
c1:   L     B [AR1,P#0.0]; 
      T     B [AR2,P#0.0]; 
c0:   NOP   0; 
exit: SET   ; 
      SAVE  ; 
END_FUNCTION
 
Last edited:
You got me there! I was already implementing version 1. But I will skip that now and go for version 2!

Thanks for the time you put into this :)
 
Argh. When AR2 is (mis)used it should *always* be saved and restored. Not doing so can cause very hard to find bugs.


Backup_AR2: DWord;


TAR2 Backup_AR2;
.
.
'CODE'
.
.
LAR2 Backup_AR2;
 
If you call an FC from an FB, AR2 is automatically saved for you by code generated by the editor. See the following example below where AR2 is DB 7.0 at the end of FC11, but has reverted to the correct value of DB 0.0 in FB1

ar2009009.jpg
 

Similar Topics

Hello everyone, I've been doing projects with Siemens and Rockwell PLC's for a couple of years now, and some softwares really helped me alot in...
Replies
10
Views
2,638
Any manufacture recommendation for remote I/O for Siemens PLC.
Replies
10
Views
2,913
Hello, I'm used to using Allen Bradley RIO options for putting filed IO out in the field and running my safety back to it. Of course I have to...
Replies
5
Views
2,831
Hi, I have a new project using Siemens ET200 distributed I/O, I have 40 channels of 4-20mA inputs in total. I need to build in a calibration...
Replies
13
Views
2,843
I've been doing PLC programming for about 15 years now but all of my experience has been with Allen-Bradley PLC's. A few months ago I started a...
Replies
5
Views
3,165
Back
Top Bottom