FLProg – Lesson two: Working with analogue signals
In the previous lesson , was told the basic principles of working with the program FLProg and work with discrete signals. In this lesson you will learn the possibilities FLProg to work with analog signals. During the lesson, you will create the program control led indicator shows and adjusts the brightness of the led using PWM output. Scheme of the test stand.
As in the last tutorial, the project will create in two languages FBD and LAD. Only now it will be done in parallel.
Create a new project.
For language LAD
The first way is dragged onto the diagram the analog input A0 of the tree of the installed equipment
The second way — drag a block "Analog input controller" from the library of elements, then making the new block double click, tie him to a zero analog input Board
Language FBD creating a new analog input by double-clicking on the "Add entry" tree tags or clicking the appropriate button
In the properties window, login to enter your login, choose the analog type and contact number 0
Then drag a new entrance from the tree tag to the diagram pane.
The analog input block in FLProg on the give magnitude is proportional to the voltage attached to them real entrance fee. With 0V on the input port, the output block is 0, while 5V on the Board input, the output block will be the value 1023.
Then create the analog output.
For the language of the LAD drag a block "Analog controller outputs" from the library blocks, and in the properties editor, block (double click on the block) attach it to the output Board D3
In FBD to create the analog output you need to double-click an "Add output" tree tags or click the corresponding button.
In the properties window, output fill output name, select the type of PWM and the number of D3
Then drag the new entry into the scheme.
In fact, the real Arduino boards have analog outputs (not counting the Arduino Duo, but while these boards FLProg program are not supported). Analog outputs Board working in PWM mode
Pulse width modulation (PWM, eng. pulse-width modulation (PWM)) is the process of controlling the power fed to the load by varying the duty cycle of pulses at a constant frequency. For example, the load use led.
Frequency is the number of periods in one second. Duty cycle — ratio of pulse duration to the duration of the period. You can change both, but to control the LEDs, it is sufficient to control the duty cycle. In the picture above we see a PWM signal with a duty ratio of 50 %, as the pulse duration (pulse width) is exactly half of the period. Accordingly, the led light will be exactly half the time on half off.The PWM frequency is very large and the eye will not notice the flickering of the led due to persistence of our vision, so we may feel that the led glows at half brightness. If we change the duty cycle to 75%, the brightness of the led will be 3 quarters full, and the graph will look like this:
It turns out that we can adjust the brightness of the led from 0 to 100 %. Now let's talk about the setting of the PWM as a solution. The resolution is the number of gradations (steps) adjust the duty cycle. In the Arduino resolution is 256 steps. The program FLProg unit analog output controls the duty cycle of the PWM attached to it of output. When applying to the input sides of the value 0 at the output of PATA, the duty cycle will be 0%, and when applying the values 255 – 100%. Based on the fact that the limits of the output signal of the analog input block of the controller is 0 — 1023 and the limits of the input signal unit analog output of the controller is 0 – 255 raises the question about the necessity of bringing them to the same values. This will help the unit scale.
In the language of the LAD he is in the folder "Analog" library elements.
In FBD the same unit located in the folder "Special blocks" of the library elements.
The power scaling in proportion to the value of transfers received on the entry in another range of values and outputs this value to the output. Parameters of input and output ranges are set in the properties block. Double-clicking on the block, we can open the editor settings block and set these values.
The calculation in the block is performed according to the following formula Q = (I – I_min)*(Q_max – Q_min)/(I_max – I_min)+Q_min Where:
Q – value output unit
I – value input block
I_max – the upper limit of the input value
I_min – the lower limit of the input value
Q_max is the upper limit of the output value
Q_min – lower limit output value
The result is shown in the screenshot of the block settings when you change the value on the input unit from 0 to 1023, the output value will be proportional to vary from 0 to 255. Now you must connect all of the blocks in accordance with the scheme.
The first Board is almost ready. Let's call it "brightness Control" and create new, once calling it a "level Indicator" The second Board we also need the value from controller input. In principle, it is possible to remove the entrance block to the second charge, and use it. But this leads to the fact that in the process of program execution in the controller will re-read the value from input. A procedure for reading an analog signal of entrance is quite expensive and lengthy. Therefore, we use in the case of a LAD analog connector, and in the case of FBD – variable.
In FLProg variables and analog connectors can be represented as the terminal connections on the Board. With them Board exchange values and connected to each other.
In the project in the language of the LAD drag a block "analog Input connector" on the FIRST cost of the project.
It is automatically assigned the name of AC1. Then connect its input to the output of the analog input block.
And on the second charge, drag the block "analogue Output connector".
Do it double click and the editor of the block will bind it to the connector AC1
In the project in FBD will create a new variable by clicking on the appropriate button or by double click on the "Add variable" in the tree tag.
In the editor window, the block will fill in the variable name, select type (Integer), and set the default value of 0
Then drag a new variable first, one cost, and then the other. Also connect the first circuit Board AC input with the output of the analog input block of the controller.
Since the level indicator 10 values, you need to change the value from zero to the maximum control value has changed from zero to 10. This again will help a scaler. Get him on the second charge and adjust as follows.
Now connect the input in the case of the LAD-and to the unit analog outputs connector, and in the case of the FBD to the output variable.
Consider a logic level indicator.
The led "Level 1" should light up if the signal value is greater than 0
The led "Level 2" should light up if the signal value is greater than 1
The led "Level 3" should light up if the signal value is greater than 2
The led "Level 4" should light up if the signal value is greater than 3
The led "Level 5" should light up if the signal value is greater than 4
The led "Level 6" should light up if the signal value is greater than 5
The led "Level 7" should light up if the signal value is greater than 6
Led "8" should light up if the signal value is greater than 7
Led "9" should light up if the signal value is greater than 8
Led "10" light should illuminate if the signal value is greater than 9
To implement this logic we use in the case of language LAD relay comparison, in the case of the FBD language of the comparator.
In the project in the language of the LAD pull on the second charge, 10 relay of the comparison and bind their outputs connected to the level meter ( see first lesson) and set the comparison type "Greater than".
Right click on the input "In" of each relay unit of comparison will open the context menu and select "Insert constant". In the opened window edit constants leave type “Integer” and enter for each output value corresponding to a logic indicator.
Inputs "A" all relay modules connect comparison with the output of the scaler. Should turn out such a scheme.
In the project in FBD get to the second charge, 10 units of "Comparator" in the same set up for the kind of comparison "More" (double click on the block to invoke the block editor). As in LAD-e insert the constants to the inputs I2 of the blocks and the inputs I1 combine with the output of the scaler.
Then we will create 10 digital outputs tied to the pay outs which are connected to a level meter (see first lesson) and get them on the second charge. And join each with their own comparator.
All programs ready, you can compile and install the controller (see first lesson)