OpenPLC-version1-with-LDmicro/C3/Arithmetic-Instructions/English
|
|
Slide 1: | Welcome to the spoken tutorial on Arithmetic Instructions |
Slide 2: Learning Objectives
|
In this tutorial we’ll learn about
|
Slide 3: System Requirements
|
To record this tutorial I am using:
|
Slide 4: Pre-requisites
|
|
Slide 5a: Arithmetic instructions
|
LDmicro has 4 Arithmetic instructions.
They are Add, Subtract, Multiply and Divide. |
Slide 5b: Arithmetic instructions
|
In LDmicro, these instructions can handle only up to 16 bit signed integer values.
Floating point numbers are not handled by these instructions. |
Now, we’ll learn about working of these instructions. | |
Open LDmicro | Let us open LDmicro. |
Let us start with an example of the ADD instruction. | |
Click Instructions -> Insert Contact >> Place the cursor to the right of the contact >> Click ‘Instructions -> Click on Arithmetic operator -> Insert ADD | First, place a Contact from Instructions.
Next to the right of it insert an ADD instruction as shown. |
Double-click on contact >> Type switch in name box >> Click OK button | Rename the Contact as ‘switch’. |
Double-click on ADD | Now, double click on the ADD instruction.
A dialog box opens which has three inputs. |
Highlight Destination
Enter ‘result’ |
First, we have Destination.
It should be the variable name to which you want to save the result. Enter the variable name as ‘result’. |
Highlight ‘is set to := :’ and ‘+ :’
Type 4 in ‘is set to :=’ column Type 5 in ‘+:’ column Click OK button |
Then the next two columns are operands.
These can be either constants or variables. Enter the operands as 4 and 5 respectively. Click on the OK button. |
Highlight ‘result’ in I/O list | Observe that the type of ‘result’ is shown as a general variable.
Also we can observe that there is no prefix before its name. |
Note that the variables can also be timer and counter variables.
We will learn about these variables in the later tutorials. | |
We will now check the working of this logic. | |
Click Simulate -> Simulation mode >>
Click Simulate -> Real-time simulation |
Let us turn on the simulation mode.
For that, click Simulate and then on Simulation mode. Next, start real-time simulation as shown. |
Highlight Xswitch and result in the IO list | Initially the state of Xswitch and result are 0. |
Double-click on ‘Xswitch’ | Change the state of Xswitch to 1. |
Highlight the state of the ‘result’ | We can observe the value of variable ‘result’ changes to 9. |
Click on Simulate >> Click on Halt simulation >> Click on Simulation Mode | Turn off the simulation mode.
For that, click Simulate and then on Halt Simulation. Then click Simulate and Simulation Mode. |
Double-click on ADD >> Change second operand to 40000 >> Click the OK button | Change the second operand in the ADD instruction to 40000.
Click the OK button. |
Click Simulate -> Simulation mode | Turn on the Simulation mode. |
Highlight the text ‘Constant 40000 out of range: -32768 to -32767’
Click the OK button |
A dialog box appears.
It says ‘Constant 40000 out of range: -32768 to 32767 inclusive’. This means that operands should be signed 16 bit integers. Click the OK button. |
Double-click on ADD >> Change second operand to 32767 >> Click the OK button | Now change the second operand to 32767 as shown. |
Click Simulate -> Simulation mode >>
Click Simulate -> Real-time simulation |
Start real-time simulation. |
Double-click on Xswitch | Change the state of Xswitch to 1. |
Highlight the state of the ‘result’ | We can observe that the value of the ‘result’ changes to ‘-32765’. |
That is, the result of the ADD operation is also a signed 16-bit integer. | |
Double-click on ‘switch’ in the IO list >> Double-click on ‘switch’ in the IO list >>
Highlight the state of the ‘result’ |
Change the state of Xswitch to 0 and then again to 1.
We can observe that the state of the variable ‘result’ doesn't change. |
Thus the ADD operation happens only once. | |
Now, we will try to increment a variable on every switch press.
Also, we will understand the importance of One shot instructions. | |
Click on Halt simulation >> Click on Simulation Mode | Turn off the simulation mode as shown. |
Double-click on ADD >> Change second operand to result >> Click the OK button | Double click on the ADD instruction.
Change the second operand to variable ‘result’. |
Click Simulate -> Simulation mode >>
Click Simulate -> Real-time simulation |
Start real-time simulation as shown. |
Double-click on ‘switch’ in the IO list | Change the state of Xswitch to 1. |
Highlight the state of the ‘result’ | We can observe that the value of ‘result’ keeps changing rapidly. |
It keeps updating until the state of Xswitch is 1. | |
Click on Halt simulation >> Click on Simulation Mode | Turn off the simulation mode. |
Slide: How can we prevent PLC from evaluating the instruction on each cycle?
We can do that by using a One Shot instruction. |
How can we prevent PLC from evaluating the instruction on each cycle?
We can do that by using a One Shot instruction. |
Let us try doing this on LDmicro. | |
Place the cursor to the right of the contact >> Click on Instructions -> Insert OSR | Place an OSR to the right of Xswitch. |
Click Simulate -> Simulation mode >>
Click Simulate -> Real-time simulation |
Start real-time simulation. |
Double-click on ‘switch’ in the IO list | Change the state of Xswitch from 0 to 1. |
Highlight the state of the ‘result’ | We can observe that the state of the variable ‘result’ changes to 4.
That is, ADD operation happens only once. Change the state of Xswitch back to 0. |
Again change the state of Xswitch from 0 to 1.
We can observe that the state of the 'result' changes to 8. That is, ADD operation happens only when input changes its state from low to high. | |
Click on Simulate >> Click on Halt simulation Click on Simulate >> Click on Simulation Mode | Turn off the simulation mode. |
Click on File >> Click on Save >> Go to Desktop/LDmicro folder >> Rename it as ‘add.ld’ >> Click on Save | Save the ladder diagram as add.ld. |
Slide 6: Assignment
Replace an OSF in the place of OSR. Observe the ‘result’ variable. Observation: The value changes when the input goes from high to low. That is when the state of Xswitch goes from 1 to 0. |
As an Assignment,
Replace an OSF in the place of OSR and observe the ‘result’ variable. Observation: The value changes when the input goes from high to low. That is when the state of Xswitch goes from 1 to 0. |
Slide 7: When to use OSR/OSF?
|
When to use OSR or OSF?
|
Next, we will look at other Arithmetic instructions. | |
Slide 8: Arithmetic Instructions
|
The instructions subtract, multiply, and divide work in the similar way as of addition.
Note that the Divide instruction gives quotient as the result. Explore these instructions on your own. |
This brings us to the end of this tutorial.
Let us summarize | |
Slide 9: Summary
|
In this tutorial, we learnt about
|
Slide 10:
About Spoken Tutorial project |
The video at the following link summarises the Spoken Tutorial project.
Please download and watch it |
Slide 11:
Spoken Tutorial workshops |
The Spoken Tutorial Project team:
For more details, please write to us |
Slide 12:
Forum for specific questions: |
Please post your timed queries in this Forum. |
Slide 13:
Forum for specific questions: |
Do you have any general / technical questions on OpenPLC?
Please visit the FOSSEE forum and post your question. |
Slide 14:
Acknowledgement |
Spoken Tutorial Project is funded by MHRD, Government of India. |
Slide 15:
Thank you slide |
This tutorial has been contributed by FOSSEE and Spoken Tutorial Project, IIT Bombay.
And this is Harsha Priyanka from FOSSEE team, signing off. Thanks for watching. |