In this article, the BLINK Function Block in the Codesys Util library is used to generate a blinking signal that turns on and off for a specific period of time, and the Trace function of Codesys is used to display the waveform. The article also uses Berghof’s Codesys Controller.
Let’s enjoy FA.
BLINK
The BLINK function can be used to simulate the behavior of a flashing signal turning on and off for a specific period of time.
VAR_INPUT
Variable Name | Type | Description |
ENABLE | BOOL | True=Start to Flash. |
TIMELOW | TIME | Time for OUT to become FALSE |
TIMEHIGH | TIME | Time for OUT to become TRUE |
VAR_OUTPUT
Variable Name | Type | Description |
OUT | BOOL | Output value, starting with FALSE and toggling between TRUE and FALSE for the specified high and low times. |
Implementation
Add library
Add the BLINK library from the Library Manager.
Click Add Library.
Search for Blink and add the Util library.
Program
次はプログラムを作成します。
VAR
Create an Instance of FB_Blink and set the LowTime and HighTime to Default values.
PROGRAM pOB132 VAR FB_Blink:Util.BLINK; xBlinkEnable:BOOL; tBlinkTimeLow:TIME:=T#1S; tBlinkTimeHigh:TIME:=T#2S; xBlinkOut:BOOL; END_VAR |
Add Block
The program in this article is created in LD2, and “Block” is added from the Toolbox.
Enter the FB or FC name at the ??? Field.
BLINK will be used in this article.
Done!
Next, Select the ??? Field on the Function Block and enter the Instance.
Enter the FB_Blink declared earlier.
Done!
Result
Finally we just link the Instance “FB_Blink” to the Function Block.
Result
Set xBlinkEnable to True and check the results of FB execution.
Done!xBlinkOut will be switched On/Off.
Implementation2
Next, we will introduce Codesys’ Trace function.
Program
VAR
Add iBlinkTrace variable for Trace display.
PROGRAM pOB132 VAR FB_Blink:Util.BLINK; xBlinkEnable:BOOL; tBlinkTimeLow:TIME:=T#1S; tBlinkTimeHigh:TIME:=T#2S; xBlinkOut:BOOL; iBlinkTrace:INT; END_VAR |
Program
Next, write iBlinkTrace to 1 only if xBlinkOut is True in the program
Add Trace
To add Trace, click Application>Add Object>Trace.
Add Trace into your project.
This is the Trace settings and Monitor screen.
Configuration
Click Configuration to configure Trace settings.
This is the Trace settings screen. There are no special settings in this case.
Variables
Next, click Add Variables to add the variables you want to monitor in Trace.
This is the Trace variable setting screen.
Configure Trace Variables
Click Variable and add the variable you want to monitor to Trace.
Done!
Graph Color
Graph Colour allows you to change the display colour of the relevant variable.
Download Trace
Finally, right-click on Trace>Download Trace to download the Trace data to the Codesys Runtime.
OK to proceed.
Done!The current value of a variable could be monitored in Graph with Trace.
Online List
Click Online List to see Trace currently stored in Codesys Runtime.
Done!
Stop Trace
You can stop the Trace by clicking Stop Trace.
Save Trace
The Trace waveform can also be saved by clicking Save Trace.
Load Trace
Finally, import the waveform data exported in ‘Load Trace’.
Done!