September 28, 2018SIMATIC S7
SIEMENS LTD EGYPT
1/15
FUNCTION BLOCKFUNCTION BLOCK
&&
ORGANIZATION BLOCKORGANIZATION BLOCK
SIEMENS
SIEMENS
September 28, 2018SIMATIC S7
SIEMENS LTD EGYPT
2/15
SIEMENS
Objectives
- How To Create FB & Its Instant DB.
- Know What Is OB & What Is Available.
- What Is The Difference Between Complete Reset & Warm Reset.
- Understand The Interrupt Processing.
September 28, 2018SIMATIC S7
SIEMENS LTD EGYPT
3/15
Function Block
DB 20
FB 20
EN
Fault
Ack Display
Frequency ENO
SIEMENS
September 28, 2018SIMATIC S7
SIEMENS LTD EGYPT
4/15
Function Block
Declaration Table
For Function Block
Program
SIEMENS
September 28, 2018SIMATIC S7
SIEMENS LTD EGYPT
5/15
Creating Instant DB For FB
SIEMENS
September 28, 2018SIMATIC S7
SIEMENS LTD EGYPT
6/15
Another Way For Creating Instant DB For FB
SIEMENS
September 28, 2018SIMATIC S7
SIEMENS LTD EGYPT
7/15
Organaization Blocks
OB 1
3
Time-of-day interrupt
Cyclic interrupt
1
16
Error handling
Cyclic program
Hardware interrupt
2
12
26 / 28
OB 20
OB 40
OB 10
OB 35
OB 82
OB No.
OB Type Priority
Time-delay interrupt
SIEMENS
September 28, 2018SIMATIC S7
SIEMENS LTD EGYPT
8/15
Read in PII
Execute OB1
Output PIQ
Delete the process images,
non-retentive M, T, C
Execute OB 100
Output PIQ
Enable outputs
C
Y
C
L
E
Output PIQ
Enable outputs
Delete PIQ (parameter-assignable)
Process residual scan cycle
Execute OB 101
Output PIQ
Warm Restart
CPU in the STOP state
(Peripheral modules have switched all outputs to the safe state)
Completer Restart
Execute OB1
Read in PII
C
Y
C
L
E
Complete Restart
The complete restart type of startup deletes the
process images (PII, PIQ) and all non-retentive
bit memories, timers and counters. Retentive
bit memories, timers and counters as well as
the data blocks‘ current values are retained.
The program stored in OB 100 is executed
once and then cyclic program execution
begins.
Warm Restart
The restart type of startup retains the states of
all addresses (bit memories, timers, counters,
process images, the data blocks‘ current
values). The program stored in OB 101 is
executed once.
Then, program execution resumes from the
point where the interruption occurred (power
off, CPU STOP). After this "residual cycle" has
been executed, the cyclic program execution
begins.
Cold Restart
The only difference between a cold restart and
a complete restart is that in addition to the
process images, all bit memories, timers and
counters (even the retentive ones!) are deleted.
As well, the data blocks‘ current values are
overwritten with the current values stored in
the load memory or with those that were
originally downloaded with the data blocks to
the CPU.
SIEMENS
September 28, 2018SIMATIC S7
SIEMENS LTD EGYPT
9/15
OB1
Executed
Continuously
OB82(Prio.26) =
Error handling.
Executed in
event of wire break
at a analog input
PIW 352
OB10 (Prio.2) =
Time-of-
day interrupt.
Executed once a
minute from 9:30
OB 1
3
Time-of-day interrupt
Cyclic interrupt
1
16
Error handling
Cyclic program
Time-delay interrupt
Hardware interrupt
2
12
26 / 28
OB 20
OB 40
OB 10
OB 35
OB 82
OB No. OB Type Priority
OB Calls
Organization blocks (OBs) are the
interface between the CPU’s operating
system and the user program.
The operating system calls the
organization blocks exclusively.
Interrupting the Cyclic Program
When the operating system calls another
OB, it interrupts the cyclic program
execution because OB1 has the lowest
priority. Any other OB can therefore
interrupt the main program and execute
its own program. Afterwards, OB1
resumes execution at the point of
interruption.
If an OB with a higher priority than the one
currently being executed is called, the
lower priority OB is interrupted after the
current statement has been completed.
The operating system then saves the
entire register stack for the interrupted
block.
Priorities
Every OB program execution can be
interrupted by a higher priority event (OB)
at command boundaries. Priorities are
graduated from 0 to 27, whereby 0 has the
lowest priority and 28 has the highest
priority.
OBs of the same priority do not interrupt
each other, but are started one after the
other in the sequence they are
recognized.
SIEMENS
September 28, 2018SIMATIC S7
SIEMENS LTD EGYPT
10/15
Time-of-Day Interrupt (OB10)
SIEMENS
September 28, 2018SIMATIC S7
SIEMENS LTD EGYPT
11/15
Cyclic Interrupt (OB35)
SIEMENS
September 28, 2018SIMATIC S7
SIEMENS LTD EGYPT
12/15
Hardware Interrupt (OB40)
SIEMENS
September 28, 2018SIMATIC S7
SIEMENS LTD EGYPT
13/15
Diagnostic Interrupt and Error Interrupt (OB81 to 87)
SIEMENS
September 28, 2018SIMATIC S7
SIEMENS LTD EGYPT
14/15
Synchronous & Asynchronous Errors OBs
SIEMENS

Function Block & Organization Block

  • 1.
    September 28, 2018SIMATICS7 SIEMENS LTD EGYPT 1/15 FUNCTION BLOCKFUNCTION BLOCK && ORGANIZATION BLOCKORGANIZATION BLOCK SIEMENS SIEMENS
  • 2.
    September 28, 2018SIMATICS7 SIEMENS LTD EGYPT 2/15 SIEMENS Objectives - How To Create FB & Its Instant DB. - Know What Is OB & What Is Available. - What Is The Difference Between Complete Reset & Warm Reset. - Understand The Interrupt Processing.
  • 3.
    September 28, 2018SIMATICS7 SIEMENS LTD EGYPT 3/15 Function Block DB 20 FB 20 EN Fault Ack Display Frequency ENO SIEMENS
  • 4.
    September 28, 2018SIMATICS7 SIEMENS LTD EGYPT 4/15 Function Block Declaration Table For Function Block Program SIEMENS
  • 5.
    September 28, 2018SIMATICS7 SIEMENS LTD EGYPT 5/15 Creating Instant DB For FB SIEMENS
  • 6.
    September 28, 2018SIMATICS7 SIEMENS LTD EGYPT 6/15 Another Way For Creating Instant DB For FB SIEMENS
  • 7.
    September 28, 2018SIMATICS7 SIEMENS LTD EGYPT 7/15 Organaization Blocks OB 1 3 Time-of-day interrupt Cyclic interrupt 1 16 Error handling Cyclic program Hardware interrupt 2 12 26 / 28 OB 20 OB 40 OB 10 OB 35 OB 82 OB No. OB Type Priority Time-delay interrupt SIEMENS
  • 8.
    September 28, 2018SIMATICS7 SIEMENS LTD EGYPT 8/15 Read in PII Execute OB1 Output PIQ Delete the process images, non-retentive M, T, C Execute OB 100 Output PIQ Enable outputs C Y C L E Output PIQ Enable outputs Delete PIQ (parameter-assignable) Process residual scan cycle Execute OB 101 Output PIQ Warm Restart CPU in the STOP state (Peripheral modules have switched all outputs to the safe state) Completer Restart Execute OB1 Read in PII C Y C L E Complete Restart The complete restart type of startup deletes the process images (PII, PIQ) and all non-retentive bit memories, timers and counters. Retentive bit memories, timers and counters as well as the data blocks‘ current values are retained. The program stored in OB 100 is executed once and then cyclic program execution begins. Warm Restart The restart type of startup retains the states of all addresses (bit memories, timers, counters, process images, the data blocks‘ current values). The program stored in OB 101 is executed once. Then, program execution resumes from the point where the interruption occurred (power off, CPU STOP). After this "residual cycle" has been executed, the cyclic program execution begins. Cold Restart The only difference between a cold restart and a complete restart is that in addition to the process images, all bit memories, timers and counters (even the retentive ones!) are deleted. As well, the data blocks‘ current values are overwritten with the current values stored in the load memory or with those that were originally downloaded with the data blocks to the CPU. SIEMENS
  • 9.
    September 28, 2018SIMATICS7 SIEMENS LTD EGYPT 9/15 OB1 Executed Continuously OB82(Prio.26) = Error handling. Executed in event of wire break at a analog input PIW 352 OB10 (Prio.2) = Time-of- day interrupt. Executed once a minute from 9:30 OB 1 3 Time-of-day interrupt Cyclic interrupt 1 16 Error handling Cyclic program Time-delay interrupt Hardware interrupt 2 12 26 / 28 OB 20 OB 40 OB 10 OB 35 OB 82 OB No. OB Type Priority OB Calls Organization blocks (OBs) are the interface between the CPU’s operating system and the user program. The operating system calls the organization blocks exclusively. Interrupting the Cyclic Program When the operating system calls another OB, it interrupts the cyclic program execution because OB1 has the lowest priority. Any other OB can therefore interrupt the main program and execute its own program. Afterwards, OB1 resumes execution at the point of interruption. If an OB with a higher priority than the one currently being executed is called, the lower priority OB is interrupted after the current statement has been completed. The operating system then saves the entire register stack for the interrupted block. Priorities Every OB program execution can be interrupted by a higher priority event (OB) at command boundaries. Priorities are graduated from 0 to 27, whereby 0 has the lowest priority and 28 has the highest priority. OBs of the same priority do not interrupt each other, but are started one after the other in the sequence they are recognized. SIEMENS
  • 10.
    September 28, 2018SIMATICS7 SIEMENS LTD EGYPT 10/15 Time-of-Day Interrupt (OB10) SIEMENS
  • 11.
    September 28, 2018SIMATICS7 SIEMENS LTD EGYPT 11/15 Cyclic Interrupt (OB35) SIEMENS
  • 12.
    September 28, 2018SIMATICS7 SIEMENS LTD EGYPT 12/15 Hardware Interrupt (OB40) SIEMENS
  • 13.
    September 28, 2018SIMATICS7 SIEMENS LTD EGYPT 13/15 Diagnostic Interrupt and Error Interrupt (OB81 to 87) SIEMENS
  • 14.
    September 28, 2018SIMATICS7 SIEMENS LTD EGYPT 14/15 Synchronous & Asynchronous Errors OBs SIEMENS

Editor's Notes

  • #4 Features of FBs Unlike functions (FCs), function blocks (FBs) have a (recall) memory. That means that a local data block is assigned to the function block, the so-called instance data block. When you call an FB, you also have to specify the number of the instance DB, which is automatically opened. An instance DB is used to save static variables. When the function block is called, the values of the actual parameter are stored in the instance data block. FB Advantages • When you write a program for an FC, you must search for empty bit memory address areas or data areas and you must maintain them yourself. The static variables of an FB, on the other hand, are maintained by the STEP 7 software. • When you use static variables you avoid the risk of assigning bit memory address areas or data areas twice. • Instead of the formal parameters "Report memory" and "Edge memory bit" of the FC20, you use the static variables "Stored_Fault" and "Edge_Memory" in the FB. This makes the block call simpler since the two formal parameters are dropped.
  • #8 Cyclic Execution The program that is to be continuously executed is stored in the Organization Block OB 1. After the user program has been completely executed in OB 1, a new cycle begins with the updating of the process images and the processing of the first statement in OB 1. The scan cycle time and the response time of the system is a result of these operations. Periodic Execution With periodic program execution, you can interrupt the cyclic program execution at fixed intervals. With cyclic interrupts, an OB 30 to OB 37 organization block is executed after a preset timing code has run out, every 100 ms for example. Event Execution The hardware interrupt can be used to respond quickly to a process event. After the event occurs, the cycle is immediately interrupted and an interrupt program is carried out.
  • #11 Time-of-Day Interrupts Time-of-day interrupts are used for executing a certain program called in OB 10 either once only at a certain time or periodically (once a minute, hourly, daily, weekly, monthly, yearly) starting at that time.
  • #12 Cyclic Interrupt Cyclic interrupts are used for executing blocks at fixed intervals. The cyclic interrupt OB for the S7-300 is OB 35. The default call interval for OB 35 is 100ms. You can change this to a value within the permitted range of 1ms to 1 minute.
  • #13 Hardware Interrupt The program in a hardware interrupt OB (OB40) is executed as soon as a certain event occurs. Various module-specific signals can trigger hardware interrupts, For parameter-assignable signal modules (DI, DO, AI, AO) you use the "HW Config" tool to specify the signal that is to trigger a hardware interrupt. suitable limit values have been configured for an analog input module. If the measured value exceeds the limit, OB40 is called. You can use the program in OB40 for interrupt generation or for process control.
  • #14 The Diagnostic Interrupt If a fault is detected in RUN mode and the relevant error OB has been programmed, the OB is called and the program in it is executed. This program could, for example, contain: • instructions for switching on a siren • instructions for data backup, followed by a STOP instruction • a program for recording the frequency with which the fault occurs, without causing the CPU to go into STOP mode. Example: Error interrupt OB82 is called in the following situations, for example: • Wire break on a module with diagnostic capability • Failure of the power supply to an analog input module • Measuring range of an analog input module exceeded