Function Blocks

Function blocks are reusable implementation of a specific function or component in an automation system similar to a class in OOP. .The following figure represents a function block

A function block in IEC61499 can be an active or a passive element. A passive element waits for a event to trigger its functionality while an active element is time dependent.The event and data flow in a function block is shown below

To learn more about Function Blocks, Application Model and System Model in IEC61499 please watch this video

Blinking an LED

We will now do a sample application to blink an LED connected to a GPIO in Raspberry Pi. The plan is to build an application in 4DIAC and then download it to Forte RTE running on RPi. To proceed further we need the following.

PC running 4DIAC

Raspberry Pi with Forte

LED

220E Resistor (or equivalent)

Breadboard

Some wires/Jumpers

Please use Firefox/Chromium/Chrome before proceeding. WebM,an open media container,is not natively supported in internet explorer/Safari.The browsers will need third party plugins to play the same.

Building Application

Launch 4DIAC and select your workspace

Create a new system and an application as shown below

Your browser does not support the video tag.

For creating a blink application, we need to set and reset the output channel. For which we can use a SR flipflop FB from 4diac.We will also need E_CYCLE to provide a cycle of events at intervals. Select the function blocks as shown below

Your browser does not support the video tag.

The E_SR Flip Flop requires two event inputs but E_CYCLE generates only one event output hence we will use E_SWITCH FB to switch between S&R inputs of SR flipflop.The selection and connections are shown below

Your browser does not support the video tag.
Quick Tip: Move the mouse over to event or data I/O to more about each Function block inputs and outputs.

Now we will need to interface an output block. We will use QX FB which will serve as a Service Interface Block for the hardware

Your browser does not support the video tag.

Note: While creating applications we are not usually aware of the target PLC/Hardware.The parameters are assigned after defining system configuration.The approach helps us run same application on different PLC's.

Define System Configuration.

Your browser does not support the video tag.

The target machine(Embedded resource) is Raspberry Pi and is connected via ethernet (RJ45/WiFi).Make sure that a local IP address is assigned to Pi for downloading application.Global IP addresses will only work with port forwarding/DDNS.

Map the hardware to the Embedded Resource

Your browser does not support the video tag.

Assign parameters to the Function Blocks.

Your browser does not support the video tag.

DT is assigned a value of 1000ms.E_CYCLE would hence generate events for every 1000ms/1s.

Event input qualifier (QI) is made true.

PARAMS in QX block take the Output Pin (GPIO) Number.In this case its the GPIO of Raspberry Pi.Forte uses SysFS which use BCM Pin Mapping. You can learn about the Pinout from this image or using the command in RPi.

gpio readall

Configure the embedded resource.

Your browser does not support the video tag.

Ensure that RPi Device is defined as a HOLOBLOC.

Your browser does not support the video tag.
Before proceeding any further

Make sure that the work is saved !!

Downloading Application to RPi

Connect LED to GPIO3 (Pin 5) of RPi as shown below

Gain terminal access on Pi or use SSH to login remotely.

More details on Secure Shell (SSH) can be found in my previous RPi tutorial

Start FORTE service as root.

Your browser does not support the video tag.

Launch Deployment Console in 4DIAC and Download the application

Your browser does not support the video tag.

The LED connected to RPi should now start Blinking.The blink rate should be 1000ms/1s, as defined in the application.

Note: Clean device in Deployment perspective to deploy a new application.
Your browser does not support the video tag.

Assignments for Practice.

Change the blink rate.

Change duty cycle of the blink

Multiple LED configuration.

All content on this site is available under the Creative Commons Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0)license.