This documentation is out of date.

The new version of the documentation is here: https://cannylogic.com/docs

Difference between revisions of "CFD Language"

From CANNY Wiki
Jump to: navigation, search
[unchecked revision][unchecked revision]
(Network)
(Initial edit)
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
Canny Lab IDE uses programming language-Canny Function Diagram (CFD) to program Canny 7 controller. During its development, the goal was set to create a tool which best suits the capabilities of the controller, while at the same time maintaining industry standard. Function Block Diagram (FBD) Language is taken as the basis for the development of the CFD. It is perhaps one of the most balanced among the five languages approved by the International Electrotechnical Commission to create user programs for PLC within IEC 61131-3 standard.
+
Canny Function Diagram (CFD) is the programming language used to program the Canny 7 controller within CannyLab IDE. During the development of the language, the goal was to create a tool which best suits the capabilities of the controller, while at the same time maintaining industry standard. Function Block Diagram (FBD) Language was used as the basis for the development of CFD. It’s fair to say that FBD is a contender for the most well-balanced among the five languages approved by the International Electrotechnical Commission for the purposes of creating user programs for PLC within the IEC 61131-3 standard.
  
As a graphical programming language, CFD has a high clarity comparable to wiring diagrams, but is at a higher level of abstraction, which allows to hide  irrelevant implementation details.
+
As a graphical programming language, CFD has a high visual clarity comparable to wiring diagrams, but is at a higher level of abstraction, which lets largely irrelevant algorithm implementation details remain hidden.
  
=== Functional Diagram ===
+
=== Function Diagram ===
  
The program in CFD language represents a draught (scheme), depicting the functional blocks, linking to one another with connecting lines (network), and support functional block elements.
+
A program in the CFD language is called a function diagram. It’s a draft (scheme) containing the function blocks, the connection lines (networks) linking those function blocks to each other, and miscellaneous supporting elements.
  
The program implementation in CFD language can be described as successively, usually from the left to the right, calculation of each functional block, with the result transferring to the next associated function block. Such algorithms will be called a thread of execution.
+
The algorithm of executing a program in the CFD language can be best described as successive (usually from the left to the right) calculation of each function block’s values, with the result transferring to the next connected function block for further calculations. We will refer to such an algorithm as a thread of execution.
  
 
[[File:3_1_1.png]]
 
[[File:3_1_1.png]]
  
Presentation of the program in this way makes it easy to trace the process of its implementation, just looking at the picture, moving eyes from block to block on the trunk.
+
Presenting the program this way makes it easy to trace the thread of execution, just by looking at the picture and following connection lines from block to block.
  
In CFD language, the relative position of the blocks in the acyclic diagram does not affect their execution order. Functional block order of execution of such a diagram is automatically calculated by the following rule: each functional block is executed when all the inputs are calculated.
+
In the CFD language, the relative position of blocks in an acyclic diagram, which in this context means a diagram without a feedback loop, does not affect their execution order. Function block order of execution of such a diagram is automatically determined by the following rule: each function block is executed when all of its inputs are calculated.
  
In determining the order of execution of the cyclic, that is, having a feedback diagram, functional blocks involved in the feedback loop executed in such order, that latest is executed the function block located to the right of all other blocks involved in the cycle.
+
When determining the order of execution of a cyclic diagram, which in this context means a diagram with a feedback loop, function blocks involved in the feedback loop are executed in such order, that the rightmost function block is always the last one to be executed.  
  
 
[[File:3_1_2.png]]
 
[[File:3_1_2.png]]
  
=== Functional Block ===
+
=== Function Block ===
  
The function block is a graphical element in the functional diagram indicating the function, algorithm or mathematical expression,produces calculation of its output data depending on the input data received from the outside. On the function block image, its inputs disposed on the left and outputs on the right .
+
The function block is a graphical element in the function diagram indicating a function, algorithm or mathematical expression. The function block produces calculation of its output data depending on the input data received from the outside. On the function block image, the inputs are positioned on the left and outputs on the right.
  
 
[[File:3_2_1.png|900px]]
 
[[File:3_2_1.png|900px]]
  
[[Built-in Function Blocks | Стандартная библиотека функциональных блоков языка CFD]] includes both simple blocks that perform basic logic transformation on their input data - such AND, OR, NOT, and more complex function: triggers, generators, switches.
+
[[Built-in Function Blocks | Built-in Function Blocks of CFD-language]] includes both simple blocks that perform basic logic transformation on their input data such as AND, OR, NOT – along side more complex function: triggers, generators, switches.
  
Function block depending on its type, may have several inputs and several outputs, for computing can use its own memory as well as access the controller operating system resources, such as timers and use the data in its calculations of output values.
+
A function block, depending on its type, may have several inputs and several outputs, use its own memory as well as access the controller operating system resources for computations. For example, a function block can read data from a timer and use it for calculating the output values.
  
 
[[File:3_2_2.png]]
 
[[File:3_2_2.png]]
  
In CannyLab environment, sources of input data for a function block can be functional blocks of whose output is bound with connecting lines (networks), numeric constants entered by the user or selected from the directory or date from controller service memory registers.
+
In the CannyLab environment, valid sources of input data for a function block are: other function blocks whose output output is connected to the block’s input via connection lines (networks); numeric constants entered by the user or selected from the directory; data from controller service memory registers.
  
Any function block input or output can be inverted. In the case of an input inversion, as input data to function block will be given a value that results from the operation of "Logical NOT" on actual input data. In case of output inversion, "Logical NOT" operation will be applied to the data before sending the calculation result of the function block to its "out".
+
Any input or output of a function block can be inverted. In the case of an input inversion, the new value of input data is equivalent to the value that results from performing the operation "Logical NOT" on the real input data. In case of output inversion, the "Logical NOT" operation will be applied to the data before sending the calculation result of the function block to the next function block or supporting element.
  
 
=== Network ===
 
=== Network ===
  
The line connecting data source to one or more recipients of the data on the functional diagram, is called a network. In CFD language, the data source is usually the output of a function block, a recipient is an input of another function block. In CFD language any network can have only one data source.
+
The line connecting a data source to one or more recipients of data on the function diagram, is called a network . In the CFD language, the data source is usually the output of a function block, a recipient is an input of another function block. In the CFD language any network can have only one data source.
  
In programming languages terms, the network is "variable" data storage place. The function block at the end of the calculations, writes its output value in the network, then  functional blocks whose inputs connected to this network after it is read from the network stored in it value and use it in their calculations as input values.
+
In programming language terms, the network is a "variable", a place where specific data is stored. After a function block finishes its calculations, writes its output value into the network as the network value. The function blocks whose inputs are connected to this network read the data stored in the network and use it in their calculations as input values.
Along with the use of anonymous networks, in CannyLab networks can assign names to be displayed on the diagram. Logically unified network, for which a name is assigned, it is possible to separate into several visually unrelated segments for easier composition. For example, two segments of "Tyre pressure, kPa" (on the figure below) represent the same network, and have the same value at each point in time, though not visually connected.
+
  
[[File:3_3_1.png]]
+
An unbroken connection line from one function block to another is a network segment. Network segments can have any number of branches(or none at all), the important part is the connection line being unbroken. This means that the networks described above consist of only one segment and can be referred to as anonymous networks.
  
 +
Alongside anonymous networks, CannyLab has named networks, which are created by assigning a display name to an existing network on the diagram. Named networks are logically unified, meaning that it is possible to separate the network into several visually unrelated segments for easier composition. For example, the two segments of "Tyre pressure, kPa" (on the figure below) represent the same network, and have the same value at each point in time, despite not being visually connected.
 +
 +
[[File:3_3_1.png]]
 
=== Data ===
 
=== Data ===
  
In CFD language, all the data used are 16-bit non-negative integer numbers in the range of 0 to 65535. The result of arithmetic operation is a numeric value of the specified range, and logical operations results are "1" (true) and "0" (false).
+
In the CFD language, all the data used is 16-bit non-negative integer numbers in the range of 0 to 65535. The result of an arithmetic operation is always a numeric value from the specified range, and logical operations results are "1" (true) and "0" (false).
  
During functional diagram execution, where necessary, data conversion from Boolean to Numeric data and vice versa is performed automatically using the following rules:
+
During function diagram execution, where necessary, data conversion from boolean to numeric data and vice versa is performed automatically using the following rules:
  
* When converting a number to a boolean value, zero is converted to a value of "false", any number other than zero - set to "true".
+
* When converting a number to a boolean value, zero is converted to a value of "false", any number other than zero is converted to "true".
  
* The arithmetic logic value of "false" and "truth" are provided as the numbers 0 and 1, respectively.
+
* In arithmetic operation, the logic values of "false" and "truth" are used as the numbers 0 and 1, respectively.
  
* Inversion at the input or output of any block, automatically converts the data to a Boolean.
+
* Inversion at the input or output of any block, automatically converts data to a boolean.
  
 
[[File:3_4_1.png]]
 
[[File:3_4_1.png]]
  
The results of arithmetic operations are taken modulo 65535. This means that if the operation result exceeds 65,535, then it is automatically deducted 65536. And if the result was less than zero, then it is added to the 65535 and another "1".
+
The results of arithmetic operations are taken modulo 65535. This means that if the operation result exceeds 65535, then 65536 is automatically deducted from the result, creating the final value. And if the result was less than 0, then 65536 is added to the result, creating the final value.
  
 
{|
 
{|
Line 80: Line 82:
 
=== Controller Resources Management ===
 
=== Controller Resources Management ===
  
To functional diagram designed by the user could use the controller's physical input data and to change the status of the physical outputs, to receive and transmit data on the data interfaces, or just to change the status of the built-in LED, diagram and controller resources must be linked to each other.
+
In order for the function diagram to use the controller's physical input data, change the status of the physical outputs, receive and transmit data on the data interfaces or even simply change the status of the built-in LED, the diagram and controller resources have to be linked to each other. In other words, they need to communicate somehow.
  
In CANNY7 controller, access to hardware resources from the user application, implemented in the form of data read and write from specific addresses (registers) reflecting the status of these resources.
+
In the CANNY7 controller, the access to hardware resources from the user application is implemented in the form of data reads and writes from/to specific registers (addresses) reflecting the status of these resources.
  
Controller resources require a specific order of access. For example, in the simplest case, to turn on embedded LED is enough send "1" to a particular address and "0" to turn it off . But in order to use universal external channel for relay control, it must be initialized first, writing its specific operation mode value of the address of its configuration. Only then it is possible, by setting a "1" or "0" to the address of a channel output value, control the electric potential on the channel.
+
Controller resources require a specific order of access. For example, in the simplest possible case, to turn on the embedded controller LED it is enough to send "1" to a particular register and "0" to turn it off. But in order to use, say, a universal external channel for relay control, it must first be initialized, by writing its specific operating mode value into the relevant configuration register. Only then it is possible to control the electric potential on the channel by sending a "1" or "0" to the channel’s output value register.
  
So it will look like given below diagram to control railway crossing traffic lights, after binding to controller resources . Such a diagram is completely suitable for uploading in the PLC and control actual hardware.
+
As an example, the diagram below is used to control railway crossing traffic lights. Notice the three controller resource bindings in the top of the diagram. This diagram is perfectly suitable for uploading into the PLC and controlling actual hardware.
  
 
[[File:3_5_1.png]]
 
[[File:3_5_1.png]]
  
The list of addresses of all the resources available to the user of the controller is in CannyLab address directory, which is available to the user via the context menu during assignment of the inputs and outputs "Address" type of function blocks.
+
The list of registers of all the resources available to the user of the controller is in the CannyLab controller register directory, which is available to the user via the context menu when assigning registers as inputs and outputs in CannyLab.
 
+
The configuration of controller certain resources  require the use of special constants, they are named and arranged in CannyLab constants list, which is available to the user during assignment inputs "Constant" type of the function blocks.
+
  
 +
The configuration of certain controller resources requires the use of special named constants that can be found in the CannyLab named constant list, which is available to the user during when assigning a constant as an input.
 +
For more information on the UI and how to access these lists, read [[CANNY Lab Functional Diagram Editor]].
 
Detailed description CANNY 7 resources and the access procedure to them, is described in [[CANNY 7| CANNY 7 Reference Manual]].
 
Detailed description CANNY 7 resources and the access procedure to them, is described in [[CANNY 7| CANNY 7 Reference Manual]].

Latest revision as of 15:21, 11 December 2020

Canny Function Diagram (CFD) is the programming language used to program the Canny 7 controller within CannyLab IDE. During the development of the language, the goal was to create a tool which best suits the capabilities of the controller, while at the same time maintaining industry standard. Function Block Diagram (FBD) Language was used as the basis for the development of CFD. It’s fair to say that FBD is a contender for the most well-balanced among the five languages approved by the International Electrotechnical Commission for the purposes of creating user programs for PLC within the IEC 61131-3 standard.

As a graphical programming language, CFD has a high visual clarity comparable to wiring diagrams, but is at a higher level of abstraction, which lets largely irrelevant algorithm implementation details remain hidden.

Function Diagram

A program in the CFD language is called a function diagram. It’s a draft (scheme) containing the function blocks, the connection lines (networks) linking those function blocks to each other, and miscellaneous supporting elements.

The algorithm of executing a program in the CFD language can be best described as successive (usually from the left to the right) calculation of each function block’s values, with the result transferring to the next connected function block for further calculations. We will refer to such an algorithm as a thread of execution.

3 1 1.png

Presenting the program this way makes it easy to trace the thread of execution, just by looking at the picture and following connection lines from block to block.

In the CFD language, the relative position of blocks in an acyclic diagram, which in this context means a diagram without a feedback loop, does not affect their execution order. Function block order of execution of such a diagram is automatically determined by the following rule: each function block is executed when all of its inputs are calculated.

When determining the order of execution of a cyclic diagram, which in this context means a diagram with a feedback loop, function blocks involved in the feedback loop are executed in such order, that the rightmost function block is always the last one to be executed.

3 1 2.png

Function Block

The function block is a graphical element in the function diagram indicating a function, algorithm or mathematical expression. The function block produces calculation of its output data depending on the input data received from the outside. On the function block image, the inputs are positioned on the left and outputs on the right.

3 2 1.png

Built-in Function Blocks of CFD-language includes both simple blocks that perform basic logic transformation on their input data – such as AND, OR, NOT – along side more complex function: triggers, generators, switches.

A function block, depending on its type, may have several inputs and several outputs, use its own memory as well as access the controller operating system resources for computations. For example, a function block can read data from a timer and use it for calculating the output values.

3 2 2.png

In the CannyLab environment, valid sources of input data for a function block are: other function blocks whose output output is connected to the block’s input via connection lines (networks); numeric constants entered by the user or selected from the directory; data from controller service memory registers.

Any input or output of a function block can be inverted. In the case of an input inversion, the new value of input data is equivalent to the value that results from performing the operation "Logical NOT" on the real input data. In case of output inversion, the "Logical NOT" operation will be applied to the data before sending the calculation result of the function block to the next function block or supporting element.

Network

The line connecting a data source to one or more recipients of data on the function diagram, is called a network . In the CFD language, the data source is usually the output of a function block, a recipient is an input of another function block. In the CFD language any network can have only one data source.

In programming language terms, the network is a "variable", a place where specific data is stored. After a function block finishes its calculations, writes its output value into the network as the network value. The function blocks whose inputs are connected to this network read the data stored in the network and use it in their calculations as input values.

An unbroken connection line from one function block to another is a network segment. Network segments can have any number of branches(or none at all), the important part is the connection line being unbroken. This means that the networks described above consist of only one segment and can be referred to as anonymous networks.

Alongside anonymous networks, CannyLab has named networks, which are created by assigning a display name to an existing network on the diagram. Named networks are logically unified, meaning that it is possible to separate the network into several visually unrelated segments for easier composition. For example, the two segments of "Tyre pressure, kPa" (on the figure below) represent the same network, and have the same value at each point in time, despite not being visually connected.

3 3 1.png

Data

In the CFD language, all the data used is 16-bit non-negative integer numbers in the range of 0 to 65535. The result of an arithmetic operation is always a numeric value from the specified range, and logical operations results are "1" (true) and "0" (false).

During function diagram execution, where necessary, data conversion from boolean to numeric data and vice versa is performed automatically using the following rules:

  • When converting a number to a boolean value, zero is converted to a value of "false", any number other than zero is converted to "true".
  • In arithmetic operation, the logic values of "false" and "truth" are used as the numbers 0 and 1, respectively.
  • Inversion at the input or output of any block, automatically converts data to a boolean.

3 4 1.png

The results of arithmetic operations are taken modulo 65535. This means that if the operation result exceeds 65535, then 65536 is automatically deducted from the result, creating the final value. And if the result was less than 0, then 65536 is added to the result, creating the final value.

For example: 65535 + 1 = 0   1 – 2 = 65535
65535 + 2 = 1   1 – 3 = 65534
65500 + 122 = 86   117 – 259 = 65294

Controller Resources Management

In order for the function diagram to use the controller's physical input data, change the status of the physical outputs, receive and transmit data on the data interfaces or even simply change the status of the built-in LED, the diagram and controller resources have to be linked to each other. In other words, they need to communicate somehow.

In the CANNY7 controller, the access to hardware resources from the user application is implemented in the form of data reads and writes from/to specific registers (addresses) reflecting the status of these resources.

Controller resources require a specific order of access. For example, in the simplest possible case, to turn on the embedded controller LED it is enough to send "1" to a particular register and "0" to turn it off. But in order to use, say, a universal external channel for relay control, it must first be initialized, by writing its specific operating mode value into the relevant configuration register. Only then it is possible to control the electric potential on the channel by sending a "1" or "0" to the channel’s output value register.

As an example, the diagram below is used to control railway crossing traffic lights. Notice the three controller resource bindings in the top of the diagram. This diagram is perfectly suitable for uploading into the PLC and controlling actual hardware.

3 5 1.png

The list of registers of all the resources available to the user of the controller is in the CannyLab controller register directory, which is available to the user via the context menu when assigning registers as inputs and outputs in CannyLab.

The configuration of certain controller resources requires the use of special named constants that can be found in the CannyLab named constant list, which is available to the user during when assigning a constant as an input. For more information on the UI and how to access these lists, read CANNY Lab Functional Diagram Editor. Detailed description CANNY 7 resources and the access procedure to them, is described in CANNY 7 Reference Manual.