Member-only story

Towards Industry 4.0 — #7 RNG, Random Number Generator in Siemens S7–1200

Andi Sama
6 min readApr 17, 2023

--

The Digital Transformation Journey to Industry 4.0 starts by understanding Industry 3.0

Andi Sama CIO, Sinergi Wahana Gemilang with Cahyati S. Sangaji

In Summary
- Implement a Random Number Generator using Siemens' LGF (Library of Generic Functions).
- PLC Hardware: Siemens S7-1200 DC/DC/DC.
- Software tools: Siemens TIA Portal on Windows 11.
- Programming `Language: Ladder Logic Diagram.
- This article's supporting files (Siemens S7-1200) are available on Github - https://github.com/andisama/RNG-with-Siemens-PLC-S7-1200

Although it seems trivial in any higher-level programming language such as C++, Java, or Python, the random number generator is not commonly supported in default installation software for Programmable Logic Controllers (PLC). E.g., no available function block for generating random numbers that we can instantly use in the ladder logic diagram.

This article illustrates using the random number generator in Siemens PLC S7–1200 through Siemens TIA Portal (Total Integrated Automation). The function is part of Siemens’ generic functions (LGF) library.

How Does It Work?

When the Start Button is pressed, the program starts. The Blue_Light at digital output address %Q0.0 is energized with a frequency: 2Hz (energized and not energized two times in a second).

Main organization block (OB1), network 1 — activate the program when Start Button is pressed (1 of 2). It shows Blue_Light is OFF, controlled by the Clock_2Hz system clock tag.
Main organization block (OB1), network 1 — activate the program when Start Button is pressed (12of 2). It shows Blue_Light is ON, controlled by the Clock_2Hz system clock tag.

When the “Running tag” at memory address %M3.2 is set, “network 2” within the main organization block (OB1) runs.

Main organization block (OB1), network 2 — the program is running. It shows that the value is not 38 hexadecimal (56 decimal), activating the Green_Light digital output as the current value falls between 50–75.

Result — PLC’s Digital Outputs with Lamps

When the four digital outputs, %Q0.4, %Q0.5, %Q0.6, and %Q0.7, are connected to 24VDC lamps, the result when the program runs is as follows (video).

--

--

Responses (2)

Write a response