Difference between revisions of "OpenPLC-version1-with-LDmicro/C3/Arithmetic-Instructions/English"

From Script | Spoken-Tutorial
Jump to: navigation, search
(Created page with " {| style="border-spacing:0;" | style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| <center>'''Visual Cue'''</center> | style="background-color:#ffffff...")
 
 
Line 50: Line 50:
 
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| '''LDmicro''' has 4 Arithmetic instructions.
 
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| '''LDmicro''' has 4 Arithmetic instructions.
  
They are Add, Subtract, Multiply and Divide.
+
They are '''Add, Subtract, Multiply''' and '''Divide'''.
  
 
|-
 
|-
 
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| Slide 5b: Arithmetic instructions
 
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| Slide 5b: Arithmetic instructions
  
* Can only handle 16-bit signed integer values
+
* Can only handle 16-bit signed '''integer''' values
 
* Floating point numbers are not handled by these instructions
 
* Floating point numbers are not handled by these instructions
  
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| In '''LDmicro''', these instructions can handle only up to 16 bit signed integer values.
+
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| In '''LDmicro''', these instructions can handle only up to 16 bit signed '''integer''' values.
  
Floating point numbers are not handled by these instructions.
+
'''Floating point''' numbers are not handled by these instructions.
  
 
|-
 
|-
Line 76: Line 76:
 
|-
 
|-
 
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| Click Instructions -> Insert Contact >> Place the cursor to the right of the contact >> Click ‘Instructions -> Click on Arithmetic operator -> Insert ADD
 
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| Click Instructions -> Insert Contact >> Place the cursor to the right of the contact >> Click ‘Instructions -> Click on Arithmetic operator -> Insert ADD
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| First, place a Contact from Instructions.
+
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| First, place a '''Contact''' from '''Instructions'''.
  
 
Next to the right of it insert an '''ADD''' instruction as shown.
 
Next to the right of it insert an '''ADD''' instruction as shown.
Line 82: Line 82:
 
|-
 
|-
 
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| Double-click on contact >> Type switch in name box >> Click OK button
 
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| Double-click on contact >> Type switch in name box >> Click OK button
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| Rename the Contact as '''‘switch’'''.
+
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| Rename the '''Contact''' as '''‘switch’'''.
  
 
|-
 
|-
Line 97: Line 97:
 
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| First, we have '''Destination'''.
 
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| First, we have '''Destination'''.
  
It should be the variable name to which you want to save the result.
+
It should be the '''variable''' name to which you want to save the result.
  
Enter the variable name as '''‘result’'''.
+
Enter the '''variable''' name as '''‘result’'''.
  
 
|-
 
|-
Line 109: Line 109:
  
 
Click OK button
 
Click OK button
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| Then the next two columns are operands.
+
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| Then the next two columns are '''operands'''.
  
These can be either constants or variables.
+
These can be either '''constants''' or '''variables'''.
  
Enter the operands as 4 and 5 respectively.
+
Enter the '''operands''' as 4 and 5 respectively.
  
Click on the OK button.
+
Click on the '''OK''' button.
  
 
|-
 
|-
 
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| Highlight ‘result’ in I/O list
 
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| Highlight ‘result’ in I/O list
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| Observe that the type of '''‘result’''' is shown as a general variable.
+
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| Observe that the type of '''‘result’''' is shown as a '''general variable.'''
  
 
Also we can observe that there is no prefix before its name.
 
Also we can observe that there is no prefix before its name.
Line 125: Line 125:
 
|-
 
|-
 
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"|  
 
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"|  
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| Note that the variables can also be timer and counter variables.  
+
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| Note that the '''variables''' can also be '''timer''' and '''counter variables'''.  
  
We will learn about these variables in the later tutorials.
+
We will learn about these '''variables''' in the later tutorials.
  
 
|-
 
|-
 
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"|  
 
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"|  
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| We will now check the working of this logic.
+
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| We will now check the working of this '''logic'''.
  
 
|-
 
|-
Line 137: Line 137:
  
 
Click Simulate -> Real-time simulation
 
Click Simulate -> Real-time simulation
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| Let us turn on the simulation mode.
+
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| Let us turn '''ON''' the '''simulation mode'''.
  
For that, click '''Simulate''' and then on S'''imulation mode.'''
+
For that, click '''Simulate''' and then on '''Simulation mode.'''
  
Next, start real-time simulation as shown.
+
Next, start '''real-time simulation''' as shown.
  
 
|-
 
|-
Line 153: Line 153:
 
|-
 
|-
 
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| Highlight the state of the ‘result’
 
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| Highlight the state of the ‘result’
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| We can observe the value of variable '''‘result’''' changes to 9.
+
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| We can observe the value of '''variable ‘result’''' changes to 9.
  
 
|-
 
|-
 
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| Click on Simulate >> Click on Halt simulation >> Click on Simulation Mode
 
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| Click on Simulate >> Click on Halt simulation >> Click on Simulation Mode
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| Turn off the simulation mode.
+
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| Turn '''OFF''' the '''simulation mode'''.
  
 
For that, click '''Simulate''' and then on '''Halt Simulation.'''
 
For that, click '''Simulate''' and then on '''Halt Simulation.'''
Line 165: Line 165:
 
|-
 
|-
 
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| Double-click on ADD >> Change second operand to 40000 >> Click the OK button
 
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| Double-click on ADD >> Change second operand to 40000 >> Click the OK button
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| Change the second operand in the ADD instruction to 40000.
+
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| Change the second '''operand''' in the '''ADD''' instruction to 40000.
  
 
Click the '''OK''' button.
 
Click the '''OK''' button.
Line 171: Line 171:
 
|-
 
|-
 
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| Click Simulate -> Simulation mode  
 
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| Click Simulate -> Simulation mode  
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| Turn on the Simulation mode.
+
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| Turn '''ON''' the '''Simulation mode'''.
  
 
|-
 
|-
Line 181: Line 181:
 
It says '''‘Constant 40000 out of range: -32768 to 32767 inclusive’.'''
 
It says '''‘Constant 40000 out of range: -32768 to 32767 inclusive’.'''
  
This means that operands should be signed 16 bit integers.
+
This means that '''operands''' should be signed 16-bit '''integers'''.
  
Click the OK button.
+
Click the '''OK''' button.
  
 
|-
 
|-
 
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| Double-click on ADD >> Change second operand to 32767 >> Click the OK button
 
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| Double-click on ADD >> Change second operand to 32767 >> Click the OK button
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| Now change the second operand to 32767 as shown.
+
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| Now change the second '''operand''' to 32767 as shown.
  
 
|-
 
|-
Line 193: Line 193:
  
 
Click Simulate -> Real-time simulation
 
Click Simulate -> Real-time simulation
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| Start real-time simulation.
+
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| Start '''real-time simulation.'''
  
 
|-
 
|-
Line 205: Line 205:
 
|-
 
|-
 
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"|  
 
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"|  
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| That is, the result of the '''ADD '''operation is also a signed 16-bit integer.
+
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| That is, the result of the '''ADD '''operation is also a signed 16-bit '''integer'''.
  
 
|-
 
|-
Line 211: Line 211:
  
 
Highlight the state of the ‘result’
 
Highlight the state of the ‘result’
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| Change the state of '''Xswitch''' to 0 and then again to 1.
+
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| Change the state of '''Xswitch''' to 0.
  
We can observe that the state of the variable '''‘result’''' doesn't change.
+
And then again to 1.
 +
 
 +
We can observe that the state of the '''variable ‘result’''' doesn't change.
  
 
|-
 
|-
 
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"|  
 
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"|  
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| Thus the ADD operation happens only once.
+
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| Thus the '''ADD operation''' happens only once.
  
 
|-
 
|-
 
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"|  
 
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"|  
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| Now, we will try to increment a variable on every switch press.
+
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| Now, we will try to increment a '''variable''' on every '''switch''' press.
  
 
Also, we will understand the importance of '''One shot '''instructions.
 
Also, we will understand the importance of '''One shot '''instructions.
Line 227: Line 229:
 
|-
 
|-
 
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| Click on Halt simulation >> Click on Simulation Mode
 
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| Click on Halt simulation >> Click on Simulation Mode
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| Turn off the simulation mode as shown.
+
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| Turn '''OFF''' the '''simulation mode''' as shown.
  
 
|-
 
|-
 
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| Double-click on ADD >> Change second operand to result >> Click the OK button
 
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| Double-click on ADD >> Change second operand to result >> Click the OK button
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| Double click on the ADD instruction.
+
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| Double click on the '''ADD''' instruction.
  
Change the second operand to variable '''‘result’'''.
+
Change the second '''operand''' to '''variable ‘result’'''.
  
 
|-
 
|-
Line 239: Line 241:
  
 
Click Simulate -> Real-time simulation
 
Click Simulate -> Real-time simulation
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| Start real-time simulation as shown.
+
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| Start '''real-time simulation''' as shown.
  
 
|-
 
|-
Line 255: Line 257:
 
|-
 
|-
 
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| Click on Halt simulation >> Click on Simulation Mode
 
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| Click on Halt simulation >> Click on Simulation Mode
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| Turn off the simulation mode.
+
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| Turn '''OFF''' the '''simulation mode'''.
  
 
|-
 
|-
Line 261: Line 263:
  
 
We can do that by using a '''One Shot''' instruction.
 
We can do that by using a '''One Shot''' instruction.
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| How can we prevent PLC from evaluating the instruction on each cycle?
+
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| How can we prevent '''PLC''' from evaluating the instruction on each '''cycle'''?
  
 
We can do that by using a '''One Shot''' instruction.
 
We can do that by using a '''One Shot''' instruction.
Line 267: Line 269:
 
|-
 
|-
 
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"|  
 
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"|  
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| Let us try doing this on LDmicro.
+
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| Let us try doing this on '''LDmicro'''.
  
 
|-
 
|-
Line 277: Line 279:
  
 
Click Simulate -> Real-time simulation
 
Click Simulate -> Real-time simulation
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| Start real-time simulation.
+
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| Start '''real-time simulation.'''
  
 
|-
 
|-
Line 285: Line 287:
 
|-
 
|-
 
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| Highlight the state of the ‘result’
 
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| Highlight the state of the ‘result’
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| We can observe that the state of the variable '''‘result’''' changes to 4.
+
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| We can observe that the state of the '''variable ‘result’''' changes to 4.
  
That is, ADD operation happens only once.
+
That is, '''ADD operation''' happens only once.
  
 
Change the state of '''Xswitch''' back to 0.
 
Change the state of '''Xswitch''' back to 0.
Line 297: Line 299:
 
We can observe that the state of the''' 'result'''' changes to 8.
 
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.
+
That is, '''ADD operation''' happens only when input changes its state from low to high.
  
 
|-
 
|-
 
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| Click on Simulate >> Click on Halt simulation Click on Simulate >> Click on Simulation Mode
 
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| Click on Simulate >> Click on Halt simulation Click on Simulate >> Click on Simulation Mode
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| Turn off the simulation mode.
+
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| Turn '''OFF''' the '''simulation mode'''.
  
 
|-
 
|-
 
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| Click on File >> Click on Save >> Go to Desktop/LDmicro folder >> Rename it as ‘add.ld’ >> Click on Save
 
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| Click on File >> Click on Save >> Go to Desktop/LDmicro folder >> Rename it as ‘add.ld’ >> Click on Save
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| Save the ladder diagram as '''add.ld'''.
+
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| Save the '''ladder diagram''' as '''add.ld'''.
  
 
|-
 
|-
Line 314: Line 316:
 
'''Observation:'''
 
'''Observation:'''
  
The value changes when the input goes from high to low.
+
The value changes when the '''input''' goes from high to low.
  
 
That is when the state of Xswitch goes from 1 to 0.
 
That is when the state of Xswitch goes from 1 to 0.
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| As an Assignment,
+
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| As an assignment:
  
Replace an '''OSF''' in the place of '''OSR''' and observe the '''‘result’''' variable.
+
Replace an '''OSF''' in the place of '''OSR''' and observe the '''‘result’ variable'''.
  
 
'''Observation:'''
 
'''Observation:'''
  
The value changes when the input goes from high to low.
+
The value changes when the '''input''' goes from high to low.
  
 
That is when the state of '''Xswitch''' goes from 1 to 0.
 
That is when the state of '''Xswitch''' goes from 1 to 0.
Line 332: Line 334:
 
* Use OSR, when you want the change in count to happen when the switch is pressed
 
* Use OSR, when you want the change in count to happen when the switch is pressed
 
* Use OSF, when you want the change to happen when the switch is released
 
* Use OSF, when you want the change to happen when the switch is released
 
 
 
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| When to use OSR or OSF?
 
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| When to use OSR or OSF?
  
* Use OSR, when you want the change in count to happen when the switch is pressed
+
* Use '''OSR''', when you want the change in count to happen when the '''switch''' is pressed
* Use OSF, when you want the change to happen when the switch is released
+
* Use '''OSF''', when you want the change to happen when the '''switch''' is released
  
 
|-
 
|-
 
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"|  
 
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"|  
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| Next, we will look at other Arithmetic instructions.
+
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| Next, we will look at other '''Arithmetic''' instructions.
  
 
|-
 
|-
Line 352: Line 352:
 
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| The instructions subtract, multiply, and divide work in the similar way as of addition.
 
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| The instructions subtract, multiply, and divide work in the similar way as of addition.
  
Note that the Divide instruction gives quotient as the result.
+
Note that the '''Divide''' instruction gives quotient as the result.
  
 
Explore these instructions on your own.
 
Explore these instructions on your own.
Line 360: Line 360:
 
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| This brings us to the end of this tutorial.
 
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| This brings us to the end of this tutorial.
  
Let us summarize
+
Let us summarize.
  
 
|-
 
|-
Line 370: Line 370:
 
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| In this tutorial, we learnt about
 
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| In this tutorial, we learnt about
  
* Arithmetic instructions
+
* '''Arithmetic''' instructions
 
|-
 
|-
 
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| Slide 10:
 
| style="background-color:#ffffff;border:1pt solid #000001;padding:0.176cm;"| Slide 10:

Latest revision as of 12:25, 3 December 2020

Visual Cue
Narration
Slide 1: Welcome to the spoken tutorial on Arithmetic Instructions
Slide 2: Learning Objectives
  • Arithmetic instructions
In this tutorial we’ll learn about
  • Arithmetic instructions
Slide 3: System Requirements
  • Ubuntu 18.04 operating system
  • LDmicro
To record this tutorial I am using:
  • Ubuntu Linux 18.04 operating system
  • LDmicro
Slide 4: Pre-requisites
  • To follow this tutorial, you should know the working One Shot instructions.
  • If not, please refer to the relevant tutorials in this series on this website.
Slide 5a: Arithmetic instructions
  • Four arithmetic instructions
  1. ADD
  2. SUB
  3. MUL
  4. DIV
LDmicro has 4 Arithmetic instructions.

They are Add, Subtract, Multiply and Divide.

Slide 5b: Arithmetic instructions
  • Can only handle 16-bit signed integer values
  • Floating point numbers are not handled by these 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?
  • Use OSR, when you want the change in count to happen when the switch is pressed
  • Use OSF, when you want the change to happen when the switch is released
When to use OSR or OSF?
  • Use OSR, when you want the change in count to happen when the switch is pressed
  • Use OSF, when you want the change to happen when the switch is released
Next, we will look at other Arithmetic instructions.
Slide 8: Arithmetic Instructions
  • SUB, MUL and DIV work similar to ADD
  • NOTE: DIV instruction gives quotient as the result
  • Explore these instructions on your own.
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
  • Arithmetic instructions


In this tutorial, we learnt about
  • Arithmetic instructions
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:
  • conducts workshops using spoken tutorials and
  • gives certificates on passing online tests.

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.

Contributors and Content Editors

Nancyvarkey, Priyanka.guntaka123