PLC: Learning Note (Siemens) 4

Source: Internet
Author: User
Tags cos integer division natural logarithm time and date


Functional directives and Applications (S7-200)
• Transfer class Instructions
• Operational instructions
• Sub-Program
• Clock Instructions
• Interrupts
· PID Instruction
• Communication Instructions

I. Transfer, SHIFT, fill instructions
1. Transmission class
1-1: Single Transfer (MOVE): Instruction Format (mov* in,out//*:b, W, DW (LAD) D (STL), R) function Description: When the Enable input is valid, the data is transmitted from in to the storage cell data type referred to out: the input/output is consistent
1-2: Block Move: Instruction format (bm* in,out,n//*:b, W, DW (LAD) D (STL), R;  n<=255) Function statement: When the enable end is valid, the N-character storage unit that starts from in to N is transferred to the start of an out. Data type: input/output same
1-3: Byte transfer immediately (Move Immediate):
Bytes Read now: BIR in,out
Byte write now: BIW in,out
Example:
LD I0.0
EU
Movb vb100,vb200
MOVW vw110,vw210
Movd vd120,vd120
BMB vb130,vb230,4//Transfer 4 bytes
VMW vw140,vw240
BIR ib1,vb270//from the I1 physical input status immediately sent to the VB270, not affected by the scanning cycle
BIW vb270,qb0//The data in the VB270 is immediately output from the Q0, unaffected by the scan cycle

2. Shift and cycle instructions
Type: Left shift, right shift, left loop, right loop
2-1: Shift Instruction (SHIFT)
The removable data storage unit is connected to the SM1.1 (overflow).
The number of shifts is related to the length of the shift data, the number of times exceeded is invalid (for example, the word left 20 times, actually only 16 times)
If the shift operation makes the final data 0, the 0 memory flag bit (SM1.0) automatically resets
Shift Left: sl* out,n
Shift Right: sr* out,n
Note: The input/output position can be different in lad, but the same in STL
Example:
LD I0.0
EU
SLB vb0,2
SRW vw10,3

2-2: Cyclic shift Instruction (Route)
The moving-out end is connected to the other end, but also to the SM1.0 (overflow)
The number of shifts is related to the length of the data, if the set value is greater than the data length, the remainder is taken as the shift length
Shift Left: rl* out,n
Shift Right: rr* out,n
Note: The input/output position can be different in lad, but the same in STL
Example:
LD I0.0
EU
RRW vw0,3

2-3: Register shift Instruction (shift register)
When the enable end is active, each scan cycle shifts once, note: Do not use edge jump to control the state of the enable end, or lose the application significance
The removal end is connected to the SM1.1 (overflow). When shifting, one end enters the SM1.1 and the other end automatically complements the data into the low
The shift is divided into forward and reverse:
Forward: n>0 minimum byte minimum displacement, highest byte maximum displacement out
Reverse: Opposite
Example:
LD I0.0
EU
SHRB i0.5,v20.0,5

3. Byte Exchange instruction
Function statement: High-byte and low-byte exchange
Data type: input as Word
Example:
LD I0.0
EU
SWAP VW10

4. Fill instruction (Memory fill)
Function Description: Fills the "word" type input data in the N storage cells beginning with the cells that the output out refers to
Example:
LD SM0.1
Fill 10,vw100,12//fills 10 into 12 bytes after vw100


Ii. Operational and mathematical directives
Note: The difference between lad and STL is that the STL is in the same address storage unit as IN1 and IN2. And in lad it can be different.
So!!!! : It is recommended to use Lad to program arithmetic and mathematical instructions.
1. Addition instruction:
Function Description: lad:in1+in2=out; Stl:in+out=out
Data type: input and Output Same (I DI R)
STL says: +* in1,out
2. Subtraction instruction:
Function Description: lad:in1-in2=out; Stl:out-in1=out
Data type: input and Output Same (I DI R)
STL says:-* in1,out
3. Multiplication instruction
3-1: General multiplication Instructions
Lad:in1*in2=out
Stl:in1*out=out
Data type: input and Output Same (I DI R)
3-2: Full integer multiplication:
Lad:in1*in2=out
Stl:in1*out=out
Data type: input as int output to dint
4. Division Instruction
4-1: General Division Instruction (Divide)
Lad:in1/in2=out
Stl:out/in1=out
Data type: input/output same, not preserving remainder (I DI R)
4-2: Full integer division (Divide integer to double integer)
Two 16-bit signed integers divide, producing a 32 result, a low 16-bit quotient, and a high 16-bit remainder.
Lad:in1/in2=out
Stl:out/in1=out
Example:
LD I0.0
EU
MOVW VW10,VW16
+i VW12,VW16
MOVW VW10,VW18
-I. VW12,VW18
MOVW Vw10,vw22
MUL VW12,VD20//Full multiplication
MOVW vw10,vw24
/I Vw12,vw24
MOVW Vw10,vw32
DIV vw12,vd32

5. Mathematical function Instruction
Includes: square root, natural logarithm, exponent, sine, cosine, sine
5-1: Square root command (square rooted)
Function Description: Twin long (32) in open square, fed out (32)
Data type: input/Output real
5-2: Natural logarithm instruction (natural logarithm)
Function Description: A Gemini long (32) of the real number in the natural logarithm is sent to the out (32)
Data type: input/output is real
Example:
LD I0.0
EU
LN VD0,AC0
LN 10.0,vd100
/R VD100,AC0

5-3: index directive (natural exponential)
Function Description: The real number of a Gemini (32) is taken at the base of E and sent to the out (32)
Data type: input/output is real
5-4: Sine (Sine), cosine (Cos), Tangent (Tan): note: input is "Radian value"
Function Description: Sends a real number of a Gemini (32) in sine, cosine, tangent to out (32)
Data type: input/output is real
Example:
LD I0.0
EU
MOVR 3.14159,AC0
/R 180.0,AC0
*r 10.0,AC0
COS AC0,AC1
MOVR 3.14159,AC2
/R 180.0,AC2
MOVR 120.0,AC3
*r AC2,AC3
SIN AC3,AC3
+r AC1,AC3//sin120°+cos10°

6. Increase/Decrease Directive
Also known as self-increment/self-reduction directives. Self-add 1 or minus 1 for unsigned or signed integers
6-1: Add directive (Increment)
Data type: Byte, INT, DINT
inc* out
6-2: Minus instruction (decrement)
dec* out
Example:
LD I0.0
EU
MOVW ac0,vw50
INCW VW50
Movd vd100,vd110
INCD VD110

7. Logic Operation Instruction
Include: logical and, logical OR, logical XOR, reverse. The operations involved can be: Byte, Word, double word
7-1: Logic with (Logic and): and* in1,out
7-1: Logic or (logic or): or* in1,out
7-3: Logic xor (Logic exclusive OR): xor* in1,out
7-4: Take Back (logic invert): inv* out
Example:
LD I0.0
EU
Andb VB0,AC1
ORB VB0,AC0
Xorv VB0,AC2
INVB VB10

Third, table function instruction
One table: Table address (first address of table) + Maximum number of forms (TL) + actual fill (EC)/! Up to 100 (word) filling data!!
TL is stored in the table address point to the storage unit, the second word address corresponding to the storage unit of the EC
The table is stored as "word"
1. Number of table memory instructions (add to table)
Lad:at_t_tbl
Stl:att data,tbl (DATA font, TBL int) font: unsigned; int: signed.
Added to the table after the last valid data, and ec+1;
2, the table takes the number instruction
Two ways: first-in-one, LIFO-first
EC-1 after removal
If you attempt to fetch a data from an empty table, the special flag register SM1.5 the position
2-1: First-out (FIFO)
FIFO Tbl,data


LD I0.0
EU
FIFO VW100,AC0
2-2: Last in, first out (LIFO)
LIFO Tbl,data


LD I0.0
EU
LIFO VW200,AC0

3, table find command (table find)
  Remove the table label from the data table that matches the criteria data, number range 0~99
   STL format:
&NBSP;FND=&NBSP;TBL,PTN, indx  (Find condition =PTN)
 FND<> TBL,PTN,INDX  ()
 fnd< tbl,ptn,indx
 fnd> tbl,ptn,indx
   Function Description:
 tbl: The first address of the visited table
&NBSP;PTN: Data that describes the comparison when the table condition is checked
 cmd: comparison operator "? The number encoded as 1~4 (for =,<>,<,> respectively)
   instruction before execution: first clear 0 for indx content. Search table TBL starting from indx to find data that conforms to the conditions determined by PTN and CMP. If not found, the final indx is EC; If a qualifying data is found, the address here is stored in indx
Example:
ld i0.0
EU
fnd> vw100,vw300,ac0


Three, conversion directives
include: data type conversion, code type conversion, data and code type conversion
1, Data conversion Directives
Type: Byte, Integer, double integer, real number
Main code: BCD Code, ASCII code, decimal number, hexadecimal count.
Purpose: To perform mathematical operations between different data types, you need to convert both to the same type
1-1: bytes and integers
 1-1-1: bytes to integers
  lad:b_i  stl: Bti in,out
   Function Description: The in of the byte input is converted to an integer type and sent to the out. BYTE type (unsigned), so no symbol extension bit
   data type: Input as byte, output int
 1-1-2: integer to byte
  LAD:I_B   Stl:itb in,out
   Function Description: integer input in converted into byte type. and send the results to out.!! Overflow occurs when the number of inputs exceeds 255
   data type: input is int, output is byte
1-2: Integer and Double integer
 1-2-1: Double integer to Integer
  lad:di_i  stl:dti in,out
   Function Description: Double integer input in converted to integer type, and on out output
   
1-3: Double integer and real number
1-3-1: Real to double integer
  Two instruction Round trunc
 ROUND IN,OUT  (Fractional rounding)
 trunc in, Out (fractional part)
1-3-2: Double integer to real number
 dtr in,out
1-3-3: Integer to real number
  No fixed instruction, first use ITD again with DTR instruction
(!!). @@ bytes--integer--double integer--real, connected in order with specific transfer instructions, others need to be converted in order)

1-4 integers and BCD
The BCD binary code decimal is a binary representation of decimal within a computer.
Range 0~9999 (font)
1-4-1:BCD to integers
BCDI out STL uses the same storage location in and out, lad can be different
1-4-2: Integer to BCD
IBCD out

2. Coding and decoding instructions
2-1 Coding Instructions (encode)
Function Description: Outputs the bit number of the least significant bit of the "word" data in (a bit with a value of 1) to the lower 4 bits of the byte cell specified by the out, that is, the half byte is used to encode the "1" bit significant bit in the 16 bits of a font data
LD I0.0
EU
Enco VW0,VB10

2-2: Decoding instruction (decode)
Function Description: The bit number represented by the low 4 bits of the byte input data in is the corresponding position of the word cell specified by the out, 1, and the other position 0. That is, a half-byte encoding is used for decoding.
LD I0.0
EU
DECO VB0,VW10

3. Segment Code Instruction
Function Description: The low 4-bit valid number of byte-type in is generated corresponding seven segment code, output to the byte cell specified by out.
LD I0.0
EU
SEG vb10,qb0


4. ASCII Code conversion instruction
One byte storage, 0-127 different symbols stored
4-1:ascii converted to 16 binary
Function Description: The 16-bit length of Len starting from in is converted to ASCII, and the result is sent to the byte output starting from out. Len Max is 255
Data type: In, LEN, out are byte-type
LD I0.0
EU
HTA vb10,vb20,4

4-2:16 conversion into ASCII
Function Description: The length of Len from the beginning of the ASCII code converted to 16 binary number, and the result is sent to the output of the bytes, the maximum length of Len is 255
LD I0.0
EU
ATH vb30,vb40,3

4-3: integer converted to ASCII code directive
Function Description: Integer in is converted to an ASCII code string. Format FMT Specifies the loop precision to the right of the decimal point and the decimal point with a comma or dot number. The result of the conversion is placed in the contiguous bytes specified by the out.
ITA in,out,fmt
(!! The low three bits of the FMT are 0-5 of the digits to the right of the decimal point. Low fourth digit means comma (1), dot (0) denotes decimal point)
LD I0.0
EU
ITA vw10,vb20,16#0b

4-4: Double integer conversion to ASCII
Function Description: The double integer in is converted to an ASCII string. Format FMT Ibid. Contiguous 12 bytes out storage
DTA in,out,fmt
4-5: Real numbers are converted to ASCII
Function Description: Real in turns into an ASCII string. FMT as above. Results in out of 3-15 bytes
RTA in,out,fmt
LD I0.0
EU
RTA VD10,VB20,16#A3

5. String conversion Instructions
Its in,fmt,out
DTS In,fmt,out
RTS In,fmt,out
STI In,indx,out
STD In,indx,out
STR In,indx,out


Five, string instruction
1. String length instruction: Slen in,out
2. String copy instruction: scpy in,out
3. String link instruction: SCAT in,out
4. Copying a string from a string: sscpy in,indx,n,out N from INDX
5. String search instruction: Sfnd in1,in2,out (search from in1 for in2 string, out for index start position, and finally search string for first character position!! )
6, Character search command: Cfnd in1,in2,out
LD I0.0
EU
Movb 1,AC0
Movb 1,AC1
SFND VB0,VB10,AC0
CFND VB0,VB30,AC1
STR vb0,ac1,vd100


Vi. Sub-procedures
Include: Create subroutine, subroutine call, return
1, the establishment of sub-procedures:
Programming software, editing, inserting subroutines
2. Call of Sub-program
2-1: subroutine Invoke command (call)
Lad:en-(RET)-When enabling subroutines to enter subroutine name
Stl:call subroutine name return: Cret
Note: 1. When the subroutine is called, the stack is automatically saved, the stack is top 1, and the other value is 0.
2. The accumulator can be passed freely between the calling program and the calling subroutine.
3. Subroutine calls with parameters
A subroutine can pass up to 16 parameters. Parameters are defined in the local variables table of the subroutine.
Local Variables Table: variable name, variable type, data type
Rule: 1, the constant parameter must declare the type. such as: dw#223
2, input or output parameters do not have automatic data type function.
3. Parameters must be arranged in a certain order when they are called
(!!??? The data in the parameter table can be input/output. So the call Program name parameter ... Input/Output available)

The


Seven, the clock instruction
uses the clock instruction can realize the call system real-time clock or sets the clock according to the need, for the control system operation monitoring, the operation record and all related real time control is very convenient.
1, read real-time clock instruction
  instruction Description: reads the current time and date, and loads it into a 8-byte buffer, the operand T is used to specify the address of the 8-byte buffer
 todr t
2, set the real-time clock command
  Instruction Description: Includes the time and date of the 8-byte buffer loaded into the PLC's clock to go. T is 8 bytes In fact address
 todw t
Note: 1, no use of the clock Instruction plc, before use, in the programming software in the "PLC" column of the PLC clock set.
   2, all date and time values are in BCD
   3, the system does not check that the real-time clock values are correct. such as February 31
   4, cannot simultaneously use the read-write clock instruction in the main program and the interrupt program, otherwise there will be fatal error, the interrupt program's real-time clock instruction will not be executed
   5, cpu224 above the hardware clock


Eight, interrupt
can be very important in real-time processing, motion control, network communication
1, several basic concepts:
1-1, interrupt source and kind (interrupt request source   Each interrupt source assigned a number to identify, called interrupt event number)
  Communication interruption: Communication can be controlled with data receive and send interrupts
  input/output interrupts: External input interrupt (interrupts with rising or falling edge of i0.0-i0.3), high-speed counter interrupt (response current value equals preset, technology direction change, Interrupts caused by events such as external reset of counters), burst output interrupts (interrupts due to the completion of a given number of pulse outputs, commonly used in stepper motor control)
  time-based interrupts: Includes timed interrupts and timer interrupts
    Timed interrupts: Can be used to support a recurring activity, cycle time in 1ms as the unit of measure, the period can be 1-255ms
  Timer interrupt: Using the timer to a specified time period to interrupt, (!!! Can only be implemented with timers T32 and T96 with resolution 1MS)
1-2, interrupt priority
  Interrupt priority: Communication interrupt, input/output interrupt, timing interrupt
  NOTE:!! The PLC in accordance with the principle of first-come-first service execution interrupt program, interrupt execution, will not be interrupted by other higher interrupts.! When execution is interrupted, new interrupt requests are queued at high and low priority levels.

2. Interrupt Instruction
The logical stack, accumulator, and some special flag register bits are saved automatically when interrupt execution, protecting the scene.
2-1: Interrupt Connection instruction (attach interrupt)
Function Description: Establish a connection between an interrupt event and an interrupt program, and allow this interrupt event
Data type: Interrupt program number int and interrupt event number evnt are "byte-type".
2-2: Interrupt Separation Instruction (detach interrupt)
Function Description: Segment an interrupt event and all program connections, thereby prohibiting the interrupt event.
2-3: Open Interrupt Command (enable interrupt), off interrupt command (disable interrupt)
ENI: Open interrupt Instruction (interrupt allow command). All connected interrupt events are opened globally.
DISI: Off interrupt instruction.
2-4: Purge Interrupt Event Instruction (clear event)
Function Description: The interrupt event of all event types can be clearly understood from the interrupt queue. Eliminate unwanted interrupt events in the queue.
2-5: Interrupt condition return (Creti)
Function Description: Conditional return instruction, which can be returned from the interrupt program based on the conditions of the preceding logical operation.
Note: 1, multiple events can call an interrupt program, but an event cannot invoke multiple interrupt programs.
2. When the system switches from other mode to run, all interrupts are automatically closed
3, can be programmed in the run mode, with Eni open all interrupts
4, Special: Use interrupts in one program, at least one EMI command
LD I0.0
Movb 200,smb34
Atch int_ex,10
ENI

Int_ex
LD SM0.0
MOVW aiw0,vw200

PLC: Learning Note (Siemens) 4

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.