Siemens PLC Programming Blocks | How to use it?

Hi! Programmers! How are you? I hope you will here to gain more knowledge about PLC programming.

Today we are going to see how an experienced programmer divides its logic or structure its logic into different plc programming blocks.

So further not waste more time and let’s dive into this.


PLC Programming Blocks

Now imagine that you are preparing a program for the entire plant. So you must be divided your logic for different equipment or machinery and stored into several blocks like,

  • Starters
  • Closed-loop or PID functions
  • Mathematical calculations like Flow calculation, Pressure or Temperature conversion, Rate calculation, Equipment running hours, etc.
  • Data logging
  • Damper open/close operation, Valve open/close operation, etc.
  • Hooter, Alarm or Siren ON/OFF management, etc.

These are the few examples of different logics that are primarily used in the industries, which users can divide and stored into several blocks. In the Siemens PLC programming software, these blocks are as follow:

  • Organization Block(OB)
  • Function Block(FB)
  • Function(FC)
  • Data Block(DB)

At the end of this article, you will gain detailed information about these PLC Programming blocks.

PLC Programming Blocks
Siemens PLC Programming Blocks Structure

Organization Blocks(OBs)

Organization blocks(OBs) determine the structure of the user program. The entire user program is cyclically called from the OB1.

There are many different OBs which are executing as per the different conditions and priority.

Startup OBs ⇒

Startup Types Related OB
Hot Restart OB101
Restart(Warm Restart) OB100
Cold Restart OB102

When these startup OBs are executed?

Users can define startup OB and the parameter in the hardware configuration. There are certain events when this startup OB is executed like,

  • After power-up
  • After the switch transaction from STOP to RUN/RUN-P
  • After a request from a communication function
  • After synchronizing in multi computing mode
  • In an H system after link-up

PLC Programming Blocks

 

Cyclic Program OB 

The PLC operating system called OB1 cyclically or periodically with this it starts cyclic execution of the user program.

This cyclic execution of the user program can be interrupted by the following user events like,

  • An Interrupt
  • A STOP command
  • A power outage
  • The occurrence of a fault of the program error

 

Periodic Program OBs

The PLC CPU has many different OBs which is executed as per the different condition and period defined in the CPU object properties.

Time of Day Interrupt OBs ⇒

There are a total of eight TOD interrupt OBs(OB10 to OB17) which can be run once or periodically. User can assign the parameter for CPU using STEP7 parameter or SFCs so that these OBs are processed at the following intervals:

  • Once
  • Every Minute
  • Every Hour
  • Every Day
  • Every Week
  • Every Month
  • End of Every Month
  • Every Year

PLC Programming Blocks

 

Cyclic Interrupt OBs

There are a total of nine cyclic interrupt OBs(OB30 to OB38) which can be run cyclically at different time intervals. The below table shows you the default intervals for the cyclic interrupt OBs.

  • OB30 – 5s
  • OB31 – 2s
  • OB32 – 1s
  • OB33 – 500ms
  • OB34 – 200ms
  • OB35 – 100ms
  • OB36 – 50ms
  • OB37 – 20ms
  • OB38 – 10ms

PLC Programming Blocks

 

Event-Driven Program OBs ⇒

Time Delay Interrupt

The part of the user program can be delayed by a specific time using this time-delay interrupt OBs. There are mainly four OBs(OB20 to OB23). Users can assign the parameter for this Time Delay Interrupt with the SFC32(Start Time Delay Interrupt), SFC33(Cancel Time Delay Interrupt), SFC34(Status of Time Delay Interrupt).

Hardware Interrupt

Hardware interrupt OBs will interrupt the user program when a specified event occurs in the process image partition. There are eight blocks(OB40 to OB47) of a hardware interrupt. Users can define this event in the hardware of the PLC CPU object properties section.

PLC Programming Blocks

Asynchronous Error

When there is any fault like hardware failure, Rack failure, Power failure, Communication failure then these OBs will execute and Users can get a message on the diagnostic to find the fault. This will reduce a sufficient amount of time and helps the user to get the fault.

Type of Error Fault Description Related OB
Time Error When CPU exceeding the maximum cycle execution time OB80
Power Supply Error Fault related to Power Supply or Backup-battery failure OB81
Diagnostic Interrupt Changes its Diagnostic Status OB82
Insert/Remove Module Interrupt Each time when user insert/remove a module OB83
CPU Hardware Fault Memory Errors, Redundancy Error OB84
Priority Class Error I/O Access Error, Module Access Error OB85
Rack Failure Failure of Central Expansion Unit, DP Master Failure, Profibus or Profinet Error OB86
Communication Error Error in reading message frame OB87

Programming Error

When there is a programming type of error or access error is coming in terms of addressing that would be programming error and in that case, we can use these OBs as per below.

Type of Error Fault Description Related OB
Programming Error When CPU calls a block that is not present in the programming section OB121
Access Error When CPU tries to access a module that is either a faulty or not present physically on the station or hardware OB122

Function (FCs)

Users can create a part of the logic in the Function(FC) block of the PLC. These are some common examples of Function(FC) like,

PLC Programming Blocks


Function Block (FBs)

Generally, Function Block(FBs) have the same functionality as Function(FC), In addition, Function Block(FB) have their own memory. Each time when the user creates a Function Block(FB), an Instance Data Block(DB) is generated.

When the operation is very complex and requires its own memory, in that case, Function Block(FB) becomes useful. Some common examples where FB is used,

  • Closed-loop or PID operations
  • Complex mathematical calculation and conversion
  • Data Logging, etc.

PLC Programming Blocks


Data Block(DBs)

Data Block(DBs) contains memory areas and used to store the data of the user program in the CPU.

There are two types of Data Blocks,

Shared Data Block OR Shared DB ⇒

Shared Data Blocks are accessible for all types of blocks like FCs, FBs, OBs. All the blocks(FCs, FBs, OBs) can read data from the Shared DB and even write in that.

PLC Programming Blocks

Instance Data Block or Instance DB

Instance Data Blocks are assigned with a particular Function Block(FB).

PLC Programming Blocks


Now I hope you have gained complete information about Siemens PLC programming blocks. How to use it and the difference between them.

If you want more information and tutorial then please comment down below, each comment matter for me and motivates me to share my knowledge with you all. Thanks!


Programmable Logic Controller (PLC) related more articles ⇒

SHARE THIS BLOG,

Leave a Comment