[?]: FC92 SHRB function in TIA Portal STEP 7

SIMATIC S7-200/300/400, Step7, PCS7, CFC, SFC, PDM, PLCSIM,
SCL, Graph, SPS-VISU S5/S7, IBHsoftec, LOGO ...
Post Reply
daca2309
Posts: 11
Joined: Sat Sep 15, 2012 5:45 pm

[?]: FC92 SHRB function in TIA Portal STEP 7

Post by daca2309 » Fri Feb 26, 2021 2:52 pm

Hello,
in Simatic Step7 V5.6 I used FC92 function block for shift bits in register.
After that I migrated that aplication in TIA Step7 (for new CPU 1500), and I got error during migration.
After that I read that CPU1500 not support MCR, MCRA, MCRD instruction ant that is reason why the problem exist.
Can someone help me and is there any another function which I can use for shift bits in register for CPU 1500?
Best regards.


FC92 SHRB SHIFT Shift bit in the shift register
from "TI-S7 Converting Blocks" library
Image

MaxS
Posts: 32
Joined: Sat May 17, 2014 1:26 am

Re: [?]: FC92 SHRB function in TIA Portal STEP 7

Post by MaxS » Sat Feb 27, 2021 6:01 am

If it help for you, here is the FC92 original code:
FC92 - "SHRB" (STEP 7 V5.5 + SP3)
Show

Code: Select all

FUNCTION "SHRB" : VOID
TITLE = BIT SHIFT REGISTER
AUTHOR : SEA
FAMILY : SHIFT
NAME : SHRB
VERSION : 2.0


VAR_INPUT
  DATA : BOOL ;	// source data bit
  RESET : BOOL ;	// resets the shift register
  S_BIT : POINTER ;	// points to the start bit in the shift register
  N : WORD ;	// length of shift register (number of bits to be shifted)
END_VAR
VAR_TEMP
  BLKNO : WORD ;	
  SAVBIT : BOOL ;	
  SAVNXT : BOOL ;	
  TMP : BOOL ;	
END_VAR
BEGIN
NETWORK
TITLE =

      L     #N; 
      L     1; 
      <I    ; 
      JC    DONE; 

      SET   ; 
      AN    #RESET; 
      MCR(  ; 

// Open DB and set ptr 
      L     P##S_BIT; 
      LAR1  ; // Addr.Reg1 = Ptr to Src. Table 
      L     W [AR1,P#0.0]; // load Block No. into accum 1
      T     #BLKNO; // scrblk = Block No. 
      OPN   DB [#BLKNO]; // opens 1st Block, DB
      L     D [AR1,P#2.0]; // load Block Area Reference
      LAR1  ; // load Block Addr.(area ref.)into Addr.Reg1

      SET   ; // place DATA into SAVNXT & SAVBIT
      A     #DATA; 
      =     #SAVNXT; 
      =     #SAVBIT; 

      L     #N; 
SHFT: T     #N; 
      MCRA  ; 

      SET   ; 
      A      [AR1,P#0.1]; 
      =     #SAVNXT; // SAVNXT = P#0.1
//-------------------
      SET   ; 
      A      [AR1,P#0.0]; 
      =     #TMP; // TMP    = P#0.0 
//-------------------
      SET   ; 
      A     #SAVBIT; 
      =      [AR1,P#0.0]; // P#0.0  = SAVBIT  
//-------------------
      SET   ; 
      A     #TMP; 
      =     #SAVBIT; // SAVBIT = TMP
//-------------------
      +AR1  P#0.1; // Increment pointer to next bit 

      MCRD  ; 
      L     #N; 
      LOOP  SHFT; 

      )MCR  ; 

DONE: SET   ; 
      SAVE  ; 

END_FUNCTION

daca2309
Posts: 11
Joined: Sat Sep 15, 2012 5:45 pm

Re: [?]: FC92 SHRB function in TIA Portal STEP 7

Post by daca2309 » Sat Feb 27, 2021 9:08 am

Thanks for answer. But, some function is not supported by used CPU (S7 1500). And this code is not useful.
Best regards,

xflash
Posts: 159
Joined: Sat May 21, 2011 3:28 am

Re: [?]: FC92 SHRB function in TIA Portal STEP 7

Post by xflash » Sat Feb 27, 2021 10:27 am

In basic instructions, shift and rotate.
try SHR SHL.

Good luck

MaxS
Posts: 32
Joined: Sat May 17, 2014 1:26 am

Re: [?]: FC92 SHRB function in TIA Portal STEP 7

Post by MaxS » Sun Feb 28, 2021 7:54 am

daca2309 wrote:
Sat Feb 27, 2021 9:08 am
And this code is not useful.
May be SCL code will be more useful for TIA.
The POINTER I changed to 3 INT variables (see picture).
I small checked it with original FC92 they are working identically.

Image
SHRB on SCL V5.3 + SP6
Show

Code: Select all

FUNCTION FC192 : VOID
TITLE = 'BIT SHIFT REGISTER'
AUTHOR : SEA
FAMILY : SHIFT
NAME : SHRB
VERSION : '2.0'
//KNOW_HOW_PROTECT

VAR_INPUT
  DATA : BOOL;    // source data bit
  RESET : BOOL;    // resets the shift register
  DBNo : INT;    // DB number
  sIDX : INT;    // start index in the shift register
  sBIT : INT;    // start bit in the shift register
  N : WORD ;    // length of shift register (number of bits to be shifted)
END_VAR
VAR_TEMP
  BLKNO : WORD;
  SAVBIT : BOOL;
  SAVNXT : BOOL;
  TMP : BOOL;
  STR : DINT;
  END : DINT;
  i : DINT;
  ni : DINT;
  nb : DINT;
  nip : DINT;
  nbp : DINT;
END_VAR

BEGIN
   
    IF WORD_TO_DINT(N) >= 1 THEN
        
        STR := sIDX * 8 + sBIT;
        END := STR + WORD_TO_DINT(N) - 1;
        BLKNO := INT_TO_WORD(DBNo);
        
        SAVNXT := DATA;
        SAVBIT := DATA;

        IF NOT RESET THEN

            FOR i := STR TO END BY 1 DO
                ni := i DIV 8;
                nb := i MOD 8;
                nip := (i+1) DIV 8;
                nbp := (i+1) MOD 8;
                SAVNXT := WORD_TO_BLOCK_DB(BLKNO).DX[nip,nbp];
                TMP := WORD_TO_BLOCK_DB(BLKNO).DX[ni,nb];
                WORD_TO_BLOCK_DB(BLKNO).DX[ni,nb] := SAVBIT;
                SAVBIT := TMP;
            END_FOR;
    
        ELSE
            
            FOR i := STR TO END BY 1 DO
                ni := i DIV 8;
                nb := i MOD 8;
                SAVNXT := FALSE;
                TMP := FALSE;
                WORD_TO_BLOCK_DB(BLKNO).DX[ni,nb] := FALSE;
                SAVBIT := FALSE;
            END_FOR;     
        
        END_IF;
    END_IF;

END_FUNCTION

daca2309
Posts: 11
Joined: Sat Sep 15, 2012 5:45 pm

Re: [?]: FC92 SHRB function in TIA Portal STEP 7

Post by daca2309 » Wed Mar 03, 2021 6:58 am

Thank you a lot! I try it and inform you, of course, confirm that code whether OK or not. I hope it will be!
Thank you again!
BR.

daca2309
Posts: 11
Joined: Sat Sep 15, 2012 5:45 pm

Re: [?]: FC92 SHRB function in TIA Portal STEP 7

Post by daca2309 » Wed Mar 03, 2021 2:29 pm

I tried it. But there is problem using for S7 1500 plc.
WORD_TO_BLOCK_DB(#BLKNO).DX[#nip, #nbp] cannot be used. In Library list, doesnot exist. Maybe for S7300/S7 400 cpu it is possible.
I can't compile it.
BR.

Answers to FAQs
Faq & Info
Faq & Info
Posts: 106
Joined: Thu Oct 13, 2005 6:42 pm
Location: Frequently Asked Questions – Часто Задаваемые Вопросы

Re: [?]: FC92 SHRB function in TIA Portal STEP 7

Post by Answers to FAQs » Thu Mar 04, 2021 7:36 am

try s7canopener viewtopic.php?p=168#p168 for unprotect your blocks after this try migrate

MaxS
Posts: 32
Joined: Sat May 17, 2014 1:26 am

Re: [?]: FC92 SHRB function in TIA Portal STEP 7

Post by MaxS » Fri Mar 05, 2021 5:05 am

You can try to change code with PEEK and POKE instructions:
I have not TIA and can not to check it.

SAVNXT := WORD_TO_BLOCK_DB(BLKNO).DX[nip,nbp];
TMP := WORD_TO_BLOCK_DB(BLKNO).DX[ni,nb];
WORD_TO_BLOCK_DB(BLKNO).DX[ni,nb] := SAVBIT;


SAVNXT := PEEK_BOOL(area := 16#84, dbNumber := DBNo, byteOffset := nip, bitOffset := nbp);
TMP := PEEK_BOOL(area := 16#84, dbNumber := DBNo, byteOffset := ni, bitOffset := nb);
POKE_BOOL(area := 16#84, dbNumber := DBNo, byteOffset := ni, bitOffset := nb, value := SAVBIT);


and

WORD_TO_BLOCK_DB(BLKNO).DX[ni,nb] := FALSE;

POKE_BOOL(area := 16#84, dbNumber := DBNo, byteOffset := ni, bitOffset := nb, value := FALSE);

https://support.industry.siemens.com/cs ... 3&lc=en-AE

daca2309
Posts: 11
Joined: Sat Sep 15, 2012 5:45 pm

Re: [?]: FC92 SHRB function in TIA Portal STEP 7

Post by daca2309 » Tue Mar 23, 2021 6:04 am

Hi,
I want to confirm that suggested instruction in function SHRB work!! I made it, used in my aplication. Done.
Thank you a lot!
Best regards,
(tyou)

Post Reply