Siemens: shifting data within a DB

udtwmc

Member
Join Date
Sep 2005
Location
nottingham
Posts
48
Hello,

Im trying to shift 110 bytes of data down by 10 bytes within the same datablock (data block is actually 110 bytes in size) so im effectively creating a shift register where the bottom 10 bytes will just fall off the end i.e get overwritten.

Whats the best solution?

I've tried using a oneshot to call sfc 20 (also tried sfc21) to move the data once each time, but the whole datablock just gets filled with the top 10 bytes rather than shift everything down by 10 bytes?? ... see attached pics

my example. SFC21/20
source area = p#db402.dbx0.0 byte 110
destination area = p#db402.dbx10.0 byte 100

s7 gv timesstamp fb.jpg s7 gv timesstamp db.jpg
 
I tested the logic you posted and it works fine in my simulator.

What triggers M62.3? Is M62.4 used anywhere else?
 
The best solution is..... do not shift at all!
You have to implement a pointer to first entry in an area which is updating on cyclic basis.
 
Hi guys,

Thanks for the replies. M62.3 and the oneshot m62.4 are not used anywhere else - they are just manual bits at the moment so that I can toggle to test the function. Hmm, strange that it works in yours and not in mine. I naturally assumed this logic should work?? I like the idea of the pointer method but thought this would be a simpler solution for my simple brain... I'll give the pointer method a go. may be back to ask how :-D
 
Code:
FUNCTION FC99 : VOID // BLK_WR

VAR_TEMP
    DATE_TIME   : DT          ;    // date&time of event
    E_DATE      : DATE        ;    // date of event
    E_TIME      : TIME_OF_DAY ;    // time of event
    SFC_ERROR   : INT         ;    // Current return value
END_VAR

VAR_IN_OUT
    S_COUNT     : INT         ;    // pointer (previous entry)
END_VAR



BEGIN
    
    IF S_COUNT > 29 OR S_COUNT < 1 THEN // max count of entry 30
        S_COUNT := 1;
    END_IF;
    
    // write date&time
    SFC_ERROR := READ_CLK(CDT := DATE_TIME);
    E_DATE := DT_DATE(DATE_TIME);
    E_TIME := DT_TOD(DATE_TIME);       
    
    DB4.Status[S_COUNT].EVENT_D := E_DATE;
    DB4.Status[S_COUNT].EVENT_T := E_TIME;    

    // alarm's data

DB4.Status[S_COUNT].E70_B := DB50.DBB70   ;      // ASi modul 8-15"
DB4.Status[S_COUNT].E71_B := DB50.DBB71   ;      // ASi modul 0-7"
DB4.Status[S_COUNT].E72_B := DB50.DBB72   ;      // ASi modul 24-31"
DB4.Status[S_COUNT].E73_B := DB50.DBB73   ;      // ASi modul 16-23"

DB4.Status[S_COUNT].E75_0 := DB50.DBX75.0 ;      // motor safety relay - infeed I11.0"
DB4.Status[S_COUNT].E75_1 := DB50.DBX75.1 ;      // motor safety relay - main drive I11.1"
DB4.Status[S_COUNT].E75_2 := DB50.DBX75.2 ;      // motor safety relay - ZWB I11.4"
DB4.Status[S_COUNT].E75_3 := DB50.DBX75.3 ;      // motor safety relay - pallet transport I11.5"
DB4.Status[S_COUNT].E75_4 := DB50.DBX75.4 ;      // motor safety relay - shift belt conveyor I11.2"
DB4.Status[S_COUNT].E75_5 := DB50.DBX75.5 ;      // motor safety relay - lift I11.3"

DB4.Status[S_COUNT].E76_0 := DB50.DBX76.0 ;      // NOT-AUS button I10.0"
DB4.Status[S_COUNT].E76_1 := DB50.DBX76.1 ;      // NOT-AUS doors on high I10.1"
DB4.Status[S_COUNT].E76_2 := DB50.DBX76.2 ;      // NOT-AUS doors below I10.2"
DB4.Status[S_COUNT].E76_3 := DB50.DBX76.3 ;      // NOT-AUS from WILL I10.3"

DB4.Status[S_COUNT].E77_0 := DB50.DBX77.0 ;      // power or VSD error - infeed I9.4"
DB4.Status[S_COUNT].E77_1 := DB50.DBX77.1 ;      // power or VSD error - lift or table I9.0 I9.1"
DB4.Status[S_COUNT].E77_2 := DB50.DBX77.2 ;      // power or VSD error - ZWB I9.7"
DB4.Status[S_COUNT].E77_3 := DB50.DBX77.3 ;      // power or VSD error - single row I9.2"
DB4.Status[S_COUNT].E77_4 := DB50.DBX77.4 ;      // power or VSD error - layer I9.3"
DB4.Status[S_COUNT].E77_5 := DB50.DBX77.5 ;      // power or VSD error - pallet load I9.5"
DB4.Status[S_COUNT].E77_6 := DB50.DBX77.6 ;      // power or VSD error - pallet unload I9.6"

DB4.Status[S_COUNT].E78_0 := DB50.DBX78.0 ;      // CPU's Batterie Alarm"
DB4.Status[S_COUNT].E78_1 := DB50.DBX78.1 ;      // Box is blocked at infeed I70.0 and Q16.0"
DB4.Status[S_COUNT].E78_2 := DB50.DBX78.2 ;      // infeed press is out of order M40.5"
DB4.Status[S_COUNT].E78_4 := DB50.DBX78.3 ;      // Box is blocked at turning station I69.2 I69.3"
DB4.Status[S_COUNT].E78_5 := DB50.DBX78.4 ;      // Box is blocked at single row pusher I69.3 and Q14.4"

DB4.Status[S_COUNT].E79_0 := DB50.DBX79.0 ;      // Bad air pressure I8.7"
DB4.Status[S_COUNT].E79_1 := DB50.DBX79.1 ;      // Blocking from PNOZ I10.7 I8.0"
DB4.Status[S_COUNT].E79_2 := DB50.DBX79.2 ;      // error - Steckbolzen I10.6"
DB4.Status[S_COUNT].E79_3 := DB50.DBX79.3 ;      // error - Sicherheitslichtchranke I10.4"
DB4.Status[S_COUNT].E79_4 := DB50.DBX79.4 ;      // error - Lift at lower end I66.5"
DB4.Status[S_COUNT].E79_5 := DB50.DBX79.5 ;      // error - Lift at upper end I66.4"
DB4.Status[S_COUNT].E79_6 := DB50.DBX79.6 ;      // error - the cross is blocked T81"

DB4.Status[S_COUNT].E80_0 := DB50.DBX80.0 ;      // Lift is blocked T28"
DB4.Status[S_COUNT].E80_1 := DB50.DBX80.1 ;      // Centering time is out T37"
DB4.Status[S_COUNT].E80_2 := DB50.DBX80.2 ;      // Single row pusher is blocked T44"
DB4.Status[S_COUNT].E80_3 := DB50.DBX80.3 ;      // ZWB is blocked T66"
DB4.Status[S_COUNT].E80_4 := DB50.DBX80.4 ;      // ZWB is blocked T68"
DB4.Status[S_COUNT].E80_5 := DB50.DBX80.5 ;      // Layer pusher is blocked T100"
DB4.Status[S_COUNT].E80_6 := DB50.DBX80.6 ;      // Table error I66.1 and I67.6"

DB4.Status[S_COUNT].E81_0 := DB50.DBX81.0 ;      // BackGate isn't moving (is blocked) I124.0"
DB4.Status[S_COUNT].E81_1 := DB50.DBX81.1 ;      // BackStop isn't moving (is blocked) I124.3"
DB4.Status[S_COUNT].E81_2 := DB50.DBX81.2 ;      // SidePushers isn't moving (is blocked) I124.6"

DB4.Status[S_COUNT].E82_0 := DB50.DBX82.0 ;      // ZWB insertions is out C6 M63.7"
DB4.Status[S_COUNT].E82_1 := DB50.DBX82.1 ;      // ZWB placement error I71.7"
DB4.Status[S_COUNT].E82_2 := DB50.DBX82.2 ;      // ZWB insertion drop down M60.3"
DB4.Status[S_COUNT].E82_3 := DB50.DBX82.3 ;      // ZWB arm end switch I71.6"
DB4.Status[S_COUNT].E82_6 := DB50.DBX82.6 ;      // Pallet transport error in empty pos. M45.1"
DB4.Status[S_COUNT].E82_7 := DB50.DBX82.7 ;      // Pallet transport error in loading pos. M45.0"

DB4.Status[S_COUNT].E83_0 := DB50.DBX83.0 ;      // Pallet transport is blocked T106"

DB4.Status[S_COUNT].E85_0 := DB50.DBX85.0 ;      // Pallet transport full pallet is blocked T46"

DB4.Status[S_COUNT].E86_4 := DB50.DBX86.4 ;      // Palletizer is not ready M28.0"
DB4.Status[S_COUNT].E86_5 := DB50.DBX86.5 ;      // poddon line is not ready I65.1 and I65.2"
DB4.Status[S_COUNT].E86_6 := DB50.DBX86.6 ;      // selected program isn't in memory M90.4"
DB4.Status[S_COUNT].E86_7 := DB50.DBX86.7 ;      // program change event M13.7"

DB4.Status[S_COUNT].E87_0 := DB50.DBX87.0 ;      // total reset M14.0"
DB4.Status[S_COUNT].E87_1 := DB50.DBX87.1 ;      // layer reset M14.1"

DB4.Status[S_COUNT].E88_2 := DB50.DBX88.2 ;      // Palletizer is not in home position"

    // а теперь данные о том на какам шаге был какой механизм

DB4.Status[S_COUNT].E240 := DB50.DBW240   ;      // Number of program DB50.DBW240
DB4.Status[S_COUNT].E266 := DB50.DBW266   ;      // current layer DB50.DBW266
     
DB4.Status[S_COUNT].E_C1 := DB13.DBW2     ;      // Counter1 DB13.DBW2
DB4.Status[S_COUNT].E_C2 := DB13.DBW4     ;      // Counter2 DB13.DBW4
DB4.Status[S_COUNT].E_C3 := DB13.DBW6     ;      // Counter3 DB13.DBW6
    
DB4.Status[S_COUNT].E_CR := MW70          ;      // Cross status MW70

DB4.Status[S_COUNT].E_SS := QB76          ;      // Stops status QB76    
    
DB4.Status[S_COUNT].E_SR := MW50          ;      // Single row pusher status MW50    
    
DB4.Status[S_COUNT].E_LS := MB38          ;      // Layer pusher MB38
    
DB4.Status[S_COUNT].E_LT := MW20          ;      // Lift and table status MW20    


    // inc of pointer
    S_COUNT := S_COUNT + 1 ;
      
END_FUNCTION

DB4 is area which consist 30 UDT
 
Hello,

I've tried using a oneshot to call sfc 20 (also tried sfc21) to move the data once each time, but the whole datablock just gets filled with the top 10 bytes rather than shift everything down by 10 bytes?? ... see attached pics

You cannot use SFC20/21 (as shown in your pictures) to do what you want - see help file from S7
Source and destination fields cannot overlap

conditions.jpg
 
Last edited:
Woah, thanks Zova ... will take a look when i get time, though looks a pretty complex solution to me?!? clever though :)

Moggie, I hear you, only my destination file is smaller than the source (by 10 bytes) so by siemens rules (the pic you sent), shouldn't it just copy the first 100 bytes and copy it to p#db402.dbx10.0?? or is it because, like you say, the two data areas overlap? (which isn't explained in the pic you sent)

edit* doh, it does say they mustnt overlap. sorry brain didn't want to read that sentence ... which is quite poor cos I can do it this way with Allen bradley, siemens, pah!
 
Last edited:
At rising edge move 10 bytes data down.
Example:
Code:
      L     P#0.0
      T     #Source
      L     P#10.0
      T     #Destination

      LAR1  #Source
      LAR2  #Destination

      A     M   1000.0
      FP    M   1000.1
      JCN   YB00

      L     5
RPT:  T     #Count
      OPN   DB402
      L     DBW [AR1,P#0.0]
      T     DBW [AR2,P#0.0]
      +AR1  P#2.0
      +AR2  P#2.0
      L     #Count
      LOOP  RPT

YB00: NOP   0
 
I would normally create a dump area (TEMP) and then use two SFC20 calls.

The TEMP area would need to be the previous block temp area, otherwise it would end up in SFC20's temp area.

Then call SFC20 twice, the first to move the source to the temp, the second to move the temp to the destination.

The reason as mentioned above, source destination cannot overlap.

If its too many words for the temp area, then a dummy DB just as a storage area.
 
You cannot use SFC20/21 (as shown in your pictures) to do what you want - see help file from S7
Source and destination fields cannot overlap

That is what I thought. I was actually amazed that it worked in my simulator.
 
i would normally create a dump area (temp) and then use two sfc20 calls.

The temp area would need to be the previous block temp area, otherwise it would end up in sfc20's temp area.

Then call sfc20 twice, the first to move the source to the temp, the second to move the temp to the destination.

The reason as mentioned above, source destination cannot overlap.

If its too many words for the temp area, then a dummy db just as a storage area.

+1
 
Ok, created a TEMP dump area and it is now working how I want it to. Simple and effective. Thanks, you're all brilliant people. However, see pic of logic as I didn't use "previous block's temp area" as suggested - how would I do that btw? And am I potentially cuasing a problem with the way I'm doing it? (using 108 bytes in local TEMP area: in a CPU315-2dp)

s7 DT timestamp.JPG
 
A potential problem is that you have assigned L data via absolute addressing.
If on a later time you modify the declaration area of your FC, and you forget to check all the code, you may inadvertently mix new and old data together.
I would put a comment about the absolute access to the L (TEMP) data at the very first network in the FC.
 
However, see pic of logic as I didn't use "previous block's temp area" as suggested - how would I do that btw?

If you use hard coded addresses in the call to SFC20 (which you have), "the previous blocks temp area" comment does not apply, it only applies when you generate the any pointer for SFC20 parameters at run time.
 
Last edited:

Similar Topics

Good morning fellow sea captains and wizards, I am being asked to do the above and obtain 4 values from each slave, I know about the MRX and MWX...
Replies
20
Views
221
Hi everyone, I am an omron plc tec , lately I came across a siemens s7 200 cn plc . Can someone help me regarding the software required and...
Replies
26
Views
465
This is the first time I am working with Simatic Manager Step7 as I started my siemens journey with TIA which is pretty easy and do a lot of stuff...
Replies
3
Views
117
Hi, I have PLC S7-1200 and switch XC-208 and Iam trying to implement this SNMP library: SIOS I am not sure, what I am doing wrong, but there is...
Replies
3
Views
122
Hi all, i am the new controls guy at the plant and i have inherited a pc from the previous controls guy with Siemens tia portal version 16 and 17...
Replies
20
Views
731
Back
Top Bottom