Difference between revisions of "OpenPLC-version1-with-LDmicro/C2/Simulation-and-Compilation/English"
(Created page with " {| style="border-spacing:0;" | style="border:1pt solid #000000;padding:0.176cm;"| <center>'''Visual Cue'''</center> | style="border:1pt solid #000000;padding:0.176cm;"| <cent...") |
Nancyvarkey (Talk | contribs) |
||
Line 6: | Line 6: | ||
|- | |- | ||
| style="border:1pt solid #000000;padding:0.176cm;"| Slide 1: | | style="border:1pt solid #000000;padding:0.176cm;"| Slide 1: | ||
− | | style="border:1pt solid #000000;padding:0.176cm;"| Welcome to the spoken tutorial on '''Simulation and Compilation''' in LDmicro. | + | | style="border:1pt solid #000000;padding:0.176cm;"| Welcome to the spoken tutorial on '''Simulation and Compilation''' in '''LDmicro'''. |
|- | |- | ||
Line 13: | Line 13: | ||
Learning Objectives | Learning Objectives | ||
− | * Simulate a ladder diagram | + | * '''Simulate''' a '''ladder''' diagram |
− | * Compile a ladder diagram in LDmicro | + | * '''Compile''' a '''ladder''' diagram in '''LDmicro''' |
| style="border:1pt solid #000000;padding:0.176cm;"| In this tutorial, we will learn how to | | style="border:1pt solid #000000;padding:0.176cm;"| In this tutorial, we will learn how to | ||
− | * '''Simulate''' a ladder diagram and | + | * '''Simulate''' a '''ladder''' diagram and |
− | * '''Compile''' a ladder diagram in '''LDmicro''' | + | * '''Compile''' a '''ladder''' diagram in '''LDmicro''' |
|- | |- | ||
Line 26: | Line 26: | ||
System Requirements | System Requirements | ||
− | * Ubuntu Linux 18.04 | + | * '''Ubuntu Linux 18.04''' operating system |
− | * LDmicro | + | * '''LDmicro''' |
| style="border:1pt solid #000000;padding:0.176cm;"| To record this tutorial I am using: | | style="border:1pt solid #000000;padding:0.176cm;"| To record this tutorial I am using: | ||
Line 37: | Line 37: | ||
| style="border:1pt solid #000000;padding:0.176cm;"| Slide 4: Pre-requisites | | style="border:1pt solid #000000;padding:0.176cm;"| Slide 4: Pre-requisites | ||
− | * How to create a ladder diagram in LDmicro | + | * How to create a '''ladder''' diagram in '''LDmicro''' |
* If not, please refer to the relevant tutorials in this series from [https://spoken-tutorial.org/ Home | spoken-tutorial.org] | * If not, please refer to the relevant tutorials in this series from [https://spoken-tutorial.org/ Home | spoken-tutorial.org] | ||
| style="border:1pt solid #000000;padding:0.176cm;"| To follow this tutorial, you should know | | style="border:1pt solid #000000;padding:0.176cm;"| To follow this tutorial, you should know | ||
− | * How to create a ladder diagram in '''LDmicro'''. | + | * How to create a '''ladder''' diagram in '''LDmicro'''. |
* If not, please refer to the relevant tutorials in this series on this website. | * If not, please refer to the relevant tutorials in this series on this website. | ||
Line 54: | Line 54: | ||
LDmicro - Simulator | LDmicro - Simulator | ||
− | * LDmicro has an in-built simulator | + | * '''LDmicro''' has an '''in-built simulator''' |
− | * It helps us to verify ladder diagram before experimenting on the actual hardware. | + | * It helps us to verify '''ladder''' diagram before experimenting on the actual hardware. |
* It reduces the hardware damage due to improper code | * It reduces the hardware damage due to improper code | ||
| style="border:1pt solid #000000;padding:0.176cm;"| | | style="border:1pt solid #000000;padding:0.176cm;"| | ||
− | * '''LDmicro''' has an | + | * '''LDmicro''' has an '''in-built simulator'''. |
− | * It helps us to verify ladder diagram before experimenting on the actual hardware. | + | * It helps us to verify '''ladder''' diagram before experimenting on the actual hardware. |
* It reduces the hardware damage due to improper code. | * It reduces the hardware damage due to improper code. | ||
|- | |- | ||
| style="border:1pt solid #000000;padding:0.176cm;"| narration | | style="border:1pt solid #000000;padding:0.176cm;"| narration | ||
− | | style="border:1pt solid #000000;padding:0.176cm;"| Now, we’ll see how to simulate a ladder diagram. | + | | style="border:1pt solid #000000;padding:0.176cm;"| Now, we’ll see how to '''simulate''' a '''ladder''' diagram. |
− | We will use the ladder diagram file, '''sample.ld '''which we created earlier. | + | We will use the '''ladder''' diagram file, '''sample.ld '''which we created earlier. |
|- | |- | ||
| style="border:1pt solid #000000;padding:0.176cm;"| Slide 6: Code Files - sample.ld | | style="border:1pt solid #000000;padding:0.176cm;"| Slide 6: Code Files - sample.ld | ||
− | * The file '''sample.ld '''used in this tutorial is available in the '''Code files''' link of this tutorial page | + | * The file '''sample.ld '''used in this tutorial is available in the '''Code files''' link of this tutorial page. |
* Please download and use them while practising | * Please download and use them while practising | ||
| style="border:1pt solid #000000;padding:0.176cm;"| The file '''sample.ld''' is available in the '''Code files''' link of this tutorial. | | style="border:1pt solid #000000;padding:0.176cm;"| The file '''sample.ld''' is available in the '''Code files''' link of this tutorial. | ||
+ | |||
+ | |||
Please download and use them while practising. | Please download and use them while practising. | ||
Line 99: | Line 101: | ||
|- | |- | ||
| style="border:1pt solid #000000;padding:0.176cm;"| Highlight first rung | | style="border:1pt solid #000000;padding:0.176cm;"| Highlight first rung | ||
− | | style="border:1pt solid #000000;padding:0.176cm;"| In the '''Simulation''' ''' | + | | style="border:1pt solid #000000;padding:0.176cm;"| In the '''Simulation Mode''', the whole '''ladder''' diagram changes to gray. |
The cursor also disappears. | The cursor also disappears. | ||
− | We can’t place an instruction in the '''Simulation''' | + | We can’t place an instruction in the '''Simulation Mode'''. |
|- | |- | ||
Line 115: | Line 117: | ||
|- | |- | ||
| style="border:1pt solid #000000;padding:0.176cm;"| Highlight second rung | | style="border:1pt solid #000000;padding:0.176cm;"| Highlight second rung | ||
− | | style="border:1pt solid #000000;padding:0.176cm;"| Here, the '''LED2''' is energized as it is directly connected to the positive rail. | + | | style="border:1pt solid #000000;padding:0.176cm;"| Here, the '''LED2''' is energized as it is directly connected to the positive '''rail'''. |
|- | |- | ||
Line 121: | Line 123: | ||
| style="border:1pt solid #000000;padding:0.176cm;"| The '''LED1''' is not energized. | | style="border:1pt solid #000000;padding:0.176cm;"| The '''LED1''' is not energized. | ||
− | This is because there is a '''switch''' in between the positive rail and '''LED1'''. | + | This is because there is a '''switch''' in between the positive '''rail''' and '''LED1'''. |
For '''LED1''' to be energized, '''switch''' should be '''ON'''. | For '''LED1''' to be energized, '''switch''' should be '''ON'''. | ||
Line 132: | Line 134: | ||
Double click on ‘switch’ in the editor window and highlight the I/O list | Double click on ‘switch’ in the editor window and highlight the I/O list | ||
− | | style="border:1pt solid #000000;padding:0.176cm;"| We can change the state of the inputs in two ways. | + | | style="border:1pt solid #000000;padding:0.176cm;"| We can change the state of the '''inputs''' in two ways. |
1. Double-click on the list that appears at the bottom of the screen. | 1. Double-click on the list that appears at the bottom of the screen. | ||
Line 138: | Line 140: | ||
We can see that the state changes to 1. | We can see that the state changes to 1. | ||
− | 2. Otherwise, double-click on appropriate instruction in the ladder diagram. | + | 2. Otherwise, double-click on appropriate instruction in the '''ladder''' diagram. |
|- | |- | ||
Line 146: | Line 148: | ||
|- | |- | ||
| style="border:1pt solid #000000;padding:0.176cm;"| | | style="border:1pt solid #000000;padding:0.176cm;"| | ||
− | | style="border:1pt solid #000000;padding:0.176cm;"| This is because the change will not be reflected until the PLC cycles. | + | | style="border:1pt solid #000000;padding:0.176cm;"| This is because the change will not be reflected until the '''PLC cycles'''. |
|- | |- | ||
Line 155: | Line 157: | ||
# '''Single cycle''' option. | # '''Single cycle''' option. | ||
− | If you choose ‘'''Single Cycle'''’ option, the '''PLC''' | + | If you choose ‘'''Single Cycle'''’ option, the '''PLC cycles''' only for one time. |
|- | |- | ||
Line 176: | Line 178: | ||
We can see that the '''LED1''' is still glowing even after the '''switch''' is off. | We can see that the '''LED1''' is still glowing even after the '''switch''' is off. | ||
− | It means that input changes are not reflected. | + | It means that '''input''' changes are not reflected. |
|- | |- | ||
| style="border:1pt solid #000000;padding:0.176cm;"| | | style="border:1pt solid #000000;padding:0.176cm;"| | ||
− | | style="border:1pt solid #000000;padding:0.176cm;"| Therefore, we need to choose ‘'''Single Cycle’''' every time we change the input state. | + | | style="border:1pt solid #000000;padding:0.176cm;"| Therefore, we need to choose ‘'''Single Cycle’''' every time we change the '''input''' state. |
− | Use the ‘'''Single Cycle'''’ option when you want to debug the program step by step. | + | Use the ‘'''Single Cycle'''’ option when you want to '''debug''' the program step by step. |
|- | |- | ||
Line 193: | Line 195: | ||
|- | |- | ||
− | | style="border:1pt solid #000000;padding:0.176cm;"| Double click on the ‘switch’ in the I/O list | + | | style="border:1pt solid #000000;padding:0.176cm;"| Double-click on the ‘switch’ in the I/O list |
| style="border:1pt solid #000000;padding:0.176cm;"| Change the state of the ‘'''switch'''’ from 0 to 1. | | style="border:1pt solid #000000;padding:0.176cm;"| Change the state of the ‘'''switch'''’ from 0 to 1. | ||
Line 199: | Line 201: | ||
We can observe that the state of '''LED1''' changes to 1 immediately. | We can observe that the state of '''LED1''' changes to 1 immediately. | ||
− | Thus, the outputs gets auto-updated according to the input changes. | + | Thus, the '''outputs''' gets auto-updated according to the '''input''' changes. |
|- | |- | ||
| style="border:1pt solid #000000;padding:0.176cm;"| Click ‘Simulate -> Halt Simulation’ | | style="border:1pt solid #000000;padding:0.176cm;"| Click ‘Simulate -> Halt Simulation’ | ||
− | | style="border:1pt solid #000000;padding:0.176cm;"| We can halt simulation by clicking on ‘'''Simulate -> | + | | style="border:1pt solid #000000;padding:0.176cm;"| We can halt '''simulation''' by clicking on ‘'''Simulate -> Halt Simulation'''’. |
|- | |- | ||
− | | style="border:1pt solid #000000;padding:0.176cm;"| Click | + | | style="border:1pt solid #000000;padding:0.176cm;"| Click ‘Simulate -> Simulation mode’ |
− | | style="border:1pt solid #000000;padding:0.176cm;"| Then click on ‘'''Simulate'''’ and on ‘'''Simulation mode'''’ | + | | style="border:1pt solid #000000;padding:0.176cm;"| Then click on ‘'''Simulate'''’ and on ‘'''Simulation mode'''’ one more time. |
− | This will turn off the simulation mode. | + | This will turn off the '''simulation mode'''. |
|- | |- | ||
| style="border:1pt solid #000000;padding:0.176cm;"| narration | | style="border:1pt solid #000000;padding:0.176cm;"| narration | ||
− | | style="border:1pt solid #000000;padding:0.176cm;"| Next, we’ll see the effects of cycle time on ladder diagram. | + | | style="border:1pt solid #000000;padding:0.176cm;"| Next, we’ll see the effects of '''cycle''' time on '''ladder''' diagram. |
|- | |- | ||
Line 220: | Line 222: | ||
It includes | It includes | ||
− | # reading the input states | + | # reading the '''input''' states |
# executing the program | # executing the program | ||
− | # updating the outputs | + | # updating the '''outputs''' |
− | | style="border:1pt solid #000000;padding:0.176cm;"| The cycle time of a PLC is the time taken from | + | | style="border:1pt solid #000000;padding:0.176cm;"| The '''cycle time''' of a '''PLC''' is the time taken from |
− | # reading the input states, | + | # reading the '''input''' states, |
# executing the program and | # executing the program and | ||
− | # updating the outputs. | + | # updating the '''outputs'''. |
|- | |- | ||
| style="border:1pt solid #000000;padding:0.176cm;"| | | style="border:1pt solid #000000;padding:0.176cm;"| | ||
− | | style="border:1pt solid #000000;padding:0.176cm;"| Now we’ll see the effect of cycle time in '''LDmicro.''' | + | | style="border:1pt solid #000000;padding:0.176cm;"| Now we’ll see the effect of '''cycle''' time in '''LDmicro.''' |
|- | |- | ||
| style="border:1pt solid #000000;padding:0.176cm;"| | | style="border:1pt solid #000000;padding:0.176cm;"| | ||
− | | style="border:1pt solid #000000;padding:0.176cm;"| Switch back to LDmicro. | + | | style="border:1pt solid #000000;padding:0.176cm;"| Switch back to '''LDmicro'''. |
|- | |- | ||
Line 252: | Line 254: | ||
Click OK button | Click OK button | ||
− | | style="border:1pt solid #000000;padding:0.176cm;"| By default, the cycle time is set to 10 milliseconds. | + | | style="border:1pt solid #000000;padding:0.176cm;"| By default, the '''cycle''' time is set to 10 milliseconds. |
Change it to 5s i.e. 5000ms. | Change it to 5s i.e. 5000ms. | ||
Line 266: | Line 268: | ||
| style="border:1pt solid #000000;padding:0.176cm;"| Now start''' real time simulation''' as shown. | | style="border:1pt solid #000000;padding:0.176cm;"| Now start''' real time simulation''' as shown. | ||
− | Change the state of the ''' | + | Change the state of the ‘'''switch'''’ to 1. |
|- | |- | ||
Line 276: | Line 278: | ||
|- | |- | ||
| style="border:1pt solid #000000;padding:0.176cm;"| Click on Simulate -> Simulation mode | | style="border:1pt solid #000000;padding:0.176cm;"| Click on Simulate -> Simulation mode | ||
− | | style="border:1pt solid #000000;padding:0.176cm;"| Turn off the simulation mode as shown. | + | | style="border:1pt solid #000000;padding:0.176cm;"| Turn off the '''simulation mode''' as shown. |
|- | |- | ||
| style="border:1pt solid #000000;padding:0.176cm;"| | | style="border:1pt solid #000000;padding:0.176cm;"| | ||
− | | style="border:1pt solid #000000;padding:0.176cm;"| Next, we will see how to compile a ladder diagram. | + | | style="border:1pt solid #000000;padding:0.176cm;"| Next, we will see how to '''compile''' a '''ladder''' diagram. |
|- | |- | ||
| style="border:1pt solid #000000;padding:0.176cm;"| Slide 8: Pre-compilation checklist | | style="border:1pt solid #000000;padding:0.176cm;"| Slide 8: Pre-compilation checklist | ||
− | * Microcontroller selection | + | * '''Microcontroller''' selection |
− | * MCU Parameters | + | * '''MCU Parameters''' |
− | * I/O assignment | + | * '''I/O assignment''' |
− | | style="border:1pt solid #000000;padding:0.176cm;"| Before compiling, we need to check the following: | + | | style="border:1pt solid #000000;padding:0.176cm;"| Before '''compiling''', we need to check the following: |
− | * Selection of proper | + | * Selection of proper '''microcontroller''' |
− | * Setting | + | * Setting '''microcontroller''' parameters |
− | * Assigning ports to I/O instructions | + | * Assigning '''ports''' to '''I/O''' instructions |
|- | |- | ||
Line 304: | Line 306: | ||
| style="border:1pt solid #000000;padding:0.176cm;"| Click on ‘Settings’ >> Click ‘Microcontroller’ | | style="border:1pt solid #000000;padding:0.176cm;"| Click on ‘Settings’ >> Click ‘Microcontroller’ | ||
− | | style="border:1pt solid #000000;padding:0.176cm;"| First, we’ve to select the part number of the microcontroller. | + | | style="border:1pt solid #000000;padding:0.176cm;"| First, we’ve to select the part number of the '''microcontroller'''. |
In the menu bar, click on '''Settings -> Microcontroller''' | In the menu bar, click on '''Settings -> Microcontroller''' | ||
Line 312: | Line 314: | ||
Select AVR ATmega16 40-PDIP | Select AVR ATmega16 40-PDIP | ||
− | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.176cm;"| Here, you can observe the list of supported microcontrollers by '''LDmicro'''. | + | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.176cm;"| Here, you can observe the list of supported '''microcontrollers''' by '''LDmicro'''. |
I’m using '''Atmel AVR ATmega16 40-PDIP.''' | I’m using '''Atmel AVR ATmega16 40-PDIP.''' | ||
Line 318: | Line 320: | ||
So, I’ll select ‘'''AVR ATmega16 40-PDIP'''’. | So, I’ll select ‘'''AVR ATmega16 40-PDIP'''’. | ||
− | If you are using a different microcontroller, select accordingly from the menu. | + | If you are using a different '''microcontroller''', select accordingly from the menu. |
− | Because different microcontrollers have different hex files for the same program. | + | Because different '''microcontrollers''' have different '''hex''' files for the same program. |
|- | |- | ||
Line 336: | Line 338: | ||
|- | |- | ||
| style="border:1pt solid #000000;padding:0.176cm;"| Highlight ‘Cycle time’ | | style="border:1pt solid #000000;padding:0.176cm;"| Highlight ‘Cycle time’ | ||
− | | style="border:1pt solid #000000;padding:0.176cm;"| Change the cycle time value to 10 milliseconds. | + | | style="border:1pt solid #000000;padding:0.176cm;"| Change the '''cycle''' time value to 10 milliseconds. |
10 milliseconds is a good value for most of the applications. | 10 milliseconds is a good value for most of the applications. | ||
Line 344: | Line 346: | ||
| style="border:1pt solid #000000;padding:0.176cm;"| Next is '''Crystal Frequency:''' | | style="border:1pt solid #000000;padding:0.176cm;"| Next is '''Crystal Frequency:''' | ||
− | * We have attached a 16 MHz external crystal in the OpenPLC hardware. | + | * We have attached a '''16 MHz external crystal''' in the '''OpenPLC''' hardware. |
− | * So set crystal frequency to 16 if you are using the same hardware. | + | * So set '''crystal''' frequency to 16 if you are using the same hardware. |
* Always set proper values. | * Always set proper values. | ||
− | * Otherwise it may cause communication and timers to behave inappropriately. | + | * Otherwise it may cause '''communication''' and '''timers''' to behave inappropriately. |
|- | |- | ||
Line 361: | Line 363: | ||
|- | |- | ||
| style="border:1pt solid #000000;padding:0.176cm;"| Click the OK button | | style="border:1pt solid #000000;padding:0.176cm;"| Click the OK button | ||
− | | style="border:1pt solid #000000;padding:0.176cm;"| After setting the microcontroller parameters properly, click on the '''OK''' button. | + | | style="border:1pt solid #000000;padding:0.176cm;"| After setting the '''microcontroller''' parameters properly, click on the '''OK''' button. |
|- | |- | ||
| style="border:1pt solid #000000;padding:0.176cm;"| Point to the default names | | style="border:1pt solid #000000;padding:0.176cm;"| Point to the default names | ||
− | | style="border:1pt solid #000000;padding:0.176cm;"| We should change the default names of the instructions before compiling the logic. | + | | style="border:1pt solid #000000;padding:0.176cm;"| We should change the default names of the instructions before '''compiling''' the '''logic'''. |
− | Please remember this whenever you compile the logic. | + | Please remember this whenever you '''compile''' the '''logic'''. |
− | We have changed the default names for this ladder diagram in the earlier tutorial. | + | We have changed the default names for this '''ladder''' diagram in the earlier tutorial. |
|- | |- | ||
Line 375: | Line 377: | ||
| style="border:1pt solid #000000;padding:0.176cm;"| Now, we must assign '''I/O '''pin to each '''I/O''' instruction. | | style="border:1pt solid #000000;padding:0.176cm;"| Now, we must assign '''I/O '''pin to each '''I/O''' instruction. | ||
− | Because different I/O assignment generates different hex files. | + | Because different '''I/O''' assignment generates different '''hex''' files. |
|- | |- | ||
Line 391: | Line 393: | ||
Just select a pin accordingly. | Just select a pin accordingly. | ||
− | I’ll select ‘'''PA7'''’, which is the 7th pin of Port A. | + | I’ll select ‘'''PA7'''’, which is the 7th pin of '''Port A'''. |
Then, click on the '''OK''' button. | Then, click on the '''OK''' button. | ||
Line 417: | Line 419: | ||
|- | |- | ||
| style="border:1pt solid #000000;padding:0.176cm;"| | | style="border:1pt solid #000000;padding:0.176cm;"| | ||
− | | style="border:1pt solid #000000;padding:0.176cm;"| Now, let us compile. | + | | style="border:1pt solid #000000;padding:0.176cm;"| Now, let us '''compile'''. |
|- | |- | ||
Line 452: | Line 454: | ||
Summary | Summary | ||
− | * Simulate a ladder diagram | + | * Simulate a '''ladder''' diagram |
− | * Compile a ladder diagram in LDmicro | + | * Compile a '''ladder''' diagram in '''LDmicro''' |
| style="border:1pt solid #000000;padding:0.176cm;"| In this tutorial, we learnt to | | style="border:1pt solid #000000;padding:0.176cm;"| In this tutorial, we learnt to | ||
− | * '''Simulate''' a ladder diagram and | + | * '''Simulate''' a '''ladder''' diagram and |
− | * '''Compile''' a ladder diagram in '''LDmicro''' | + | * '''Compile''' a '''ladder''' diagram in '''LDmicro''' |
|- | |- | ||
Line 465: | Line 467: | ||
Assignment: | Assignment: | ||
− | * Change the cycle time to 3s and 10s | + | * Change the '''cycle''' time to 3s and 10s |
− | * Observe the changes while simulating | + | * Observe the changes while '''simulating''' |
| style="border:1pt solid #000000;padding:0.176cm;"| As an assignment, | | style="border:1pt solid #000000;padding:0.176cm;"| As an assignment, | ||
− | # Change the cycle time to 3 secs and then to 10 secs | + | # Change the '''cycle''' time to 3 secs and then to 10 secs |
− | # Observe the changes in simulation time. | + | # Observe the changes in '''simulation''' time. |
|- | |- |
Latest revision as of 16:32, 6 April 2020
|
|
Slide 1: | Welcome to the spoken tutorial on Simulation and Compilation in LDmicro. |
Slide 2:
Learning Objectives
|
In this tutorial, we will learn how to
|
Slide 3:
System Requirements
|
To record this tutorial I am using:
|
Slide 4: Pre-requisites
|
To follow this tutorial, you should know
|
First we will know about LDmicro simulator. | |
Slide 5:
LDmicro - Simulator
|
|
narration | Now, we’ll see how to simulate a ladder diagram.
We will use the ladder diagram file, sample.ld which we created earlier. |
Slide 6: Code Files - sample.ld
|
The file sample.ld is available in the Code files link of this tutorial.
Please download and use them while practising. |
Open LDmicro | Let us open LDmicro. |
Click ‘File -> Open’
Select the file Click OK button |
In the menu bar, click on File and then Open.
Select the file sample.ld from the location where you have saved. |
Click on “Simulate -> Simulation Mode” | In the menu bar, click on Simulate then on Simulation Mode. |
Highlight first rung | In the Simulation Mode, the whole ladder diagram changes to gray.
The cursor also disappears. We can’t place an instruction in the Simulation Mode. |
Highlight second rung
Highlight first rung |
The instructions that are energized appear in bright red color.
The instructions that are not energized appear in gray color. |
Highlight second rung | Here, the LED2 is energized as it is directly connected to the positive rail. |
Highlight ‘switch’ | The LED1 is not energized.
This is because there is a switch in between the positive rail and LED1. For LED1 to be energized, switch should be ON. i.e, It should be given value 1. |
Double click on ‘switch’ in I/O list and highlight the I/O list
|
We can change the state of the inputs in two ways.
1. Double-click on the list that appears at the bottom of the screen. We can see that the state changes to 1. 2. Otherwise, double-click on appropriate instruction in the ladder diagram. |
Highlight state of the ‘switch’ in I/O list | Note that LED1 isn’t energized even after changing the state of the switch. |
This is because the change will not be reflected until the PLC cycles. | |
For the changes to be reflected, choose either one of the below options.
If you choose ‘Single Cycle’ option, the PLC cycles only for one time. | |
Click ‘Simulate -> Single cycle’
|
Select ‘Single Cycle’.
Now we can observe that the first rung is energized. That is, LED1 is glowing. |
Double click on the ‘switch’ in the I/O list
Highlight first rung |
Now again change the state of the ‘switch’ from 1 to 0.
We can see that the LED1 is still glowing even after the switch is off. It means that input changes are not reflected. |
Therefore, we need to choose ‘Single Cycle’ every time we change the input state.
Use the ‘Single Cycle’ option when you want to debug the program step by step. | |
But, this is not the case with Real-Time Simulation. | |
Choose ‘Simulation -> Real-Time Simulation’ | In the menu bar, select ‘Simulate -> Start Real-Time Simulation’. |
Double-click on the ‘switch’ in the I/O list | Change the state of the ‘switch’ from 0 to 1.
We can observe that the state of LED1 changes to 1 immediately. Thus, the outputs gets auto-updated according to the input changes. |
Click ‘Simulate -> Halt Simulation’ | We can halt simulation by clicking on ‘Simulate -> Halt Simulation’. |
Click ‘Simulate -> Simulation mode’ | Then click on ‘Simulate’ and on ‘Simulation mode’ one more time.
This will turn off the simulation mode. |
narration | Next, we’ll see the effects of cycle time on ladder diagram. |
Slide 7: Cycle time
It includes
|
The cycle time of a PLC is the time taken from
|
Now we’ll see the effect of cycle time in LDmicro. | |
Switch back to LDmicro. | |
Click on Settings
Click on MCU parameters |
In the menu bar, click on ‘Settings’.
Then click on MCU parameters. |
Highlight cycle time
Change the cycle time to 5s Click OK button |
By default, the cycle time is set to 10 milliseconds.
Change it to 5s i.e. 5000ms. Then, click on the OK button in the top right of the window. |
Click Simulate -> Simulation mode
Click Simulate -> Start Real-time simulation Double click on Xswitch in the I/O list |
Now start real time simulation as shown.
Change the state of the ‘switch’ to 1. |
Point to YLED1 state. | You can observe that the LED1 doesn’t change its state immediately.
Instead it takes upto 5s to get its state updated. |
Click on Simulate -> Simulation mode | Turn off the simulation mode as shown. |
Next, we will see how to compile a ladder diagram. | |
Slide 8: Pre-compilation checklist
|
Before compiling, we need to check the following:
|
Switch to LDmicro interface. | |
Click on ‘Settings’ >> Click ‘Microcontroller’ | First, we’ve to select the part number of the microcontroller.
In the menu bar, click on Settings -> Microcontroller |
Highlight the list of microcontrollers
Select AVR ATmega16 40-PDIP |
Here, you can observe the list of supported microcontrollers by LDmicro.
I’m using Atmel AVR ATmega16 40-PDIP. So, I’ll select ‘AVR ATmega16 40-PDIP’. If you are using a different microcontroller, select accordingly from the menu. Because different microcontrollers have different hex files for the same program. |
Click ‘Settings’ >> Click ‘MCU parameters’ | Now click on Settings -> MCU Parameters. |
Point to ‘PLC Configuration’ | ‘PLC Configuration’ pop-up window appears. |
Here you can set different parameters. | |
Highlight ‘Cycle time’ | Change the cycle time value to 10 milliseconds.
10 milliseconds is a good value for most of the applications. |
Change Crystal frequency to 16 | Next is Crystal Frequency:
|
Highlight ‘Baud rate’ | Next is UART Baud rate:
By default, it is in disable state. It will be enabled only when you are using any of the serial instructions. We will learn about this in detail when we use serial instructions. |
Click the OK button | After setting the microcontroller parameters properly, click on the OK button. |
Point to the default names | We should change the default names of the instructions before compiling the logic.
Please remember this whenever you compile the logic. We have changed the default names for this ladder diagram in the earlier tutorial. |
Now, we must assign I/O pin to each I/O instruction.
Because different I/O assignment generates different hex files. | |
On LDmicro interface:
Double-click on ‘switch’ in I/O list Select ‘PA7’ Click OK button |
To do so, double-click on ‘Xswitch’ in the I/O list.
A pop up window opens showing the unallocated pins. Just select a pin accordingly. I’ll select ‘PA7’, which is the 7th pin of Port A. Then, click on the OK button. |
Double-click on ‘LED1’ in I/O list
Select ‘PC0’ Click OK Double-click on ‘LED2’ in I/O list Select ‘PC1’ Click OK |
Similarly, double-click on YLED1 and assign PC0 as shown.
Then double-click on YLED2 and assign PC1. |
We have assigned I/O pin to each I/O instruction. | |
Now, let us compile. | |
Click ‘Compile’ >> Click ‘Compile’ | In the menu bar, click on Compile then on Compile. |
Double-click on Desktop
Rename it as ‘sample’ |
Save pop-up window opens.
I’ll save it in the folder LDmicro on Desktop with the same name ‘sample.hex’. |
Click OK button | We will get a pop-up window which shows ‘Compile Successful’.
Click on the OK button. |
Highlight ‘Compile -> Compile As’ | If you want to save it under other name choose ‘Compile -> Compile As’. |
This brings us to the end of this tutorial.
Let us summarize. | |
Slide 9:
Summary
|
In this tutorial, we learnt to
|
Slide 10:
Assignment:
|
As an assignment,
|
Slide 11:
About Spoken Tutorial project |
The video at the following link summarises the Spoken Tutorial project.
Please download and watch it |
Slide 12:
Spoken Tutorial workshops |
The Spoken Tutorial Project Team conducts workshops and gives certificates.
For more details, please write to us. |
Slide 13:
Forum questions |
Please post your timed queries in this forum. |
Slide 14:
Forum for specific questions: |
Do you have any general / technical questions on OpenPLC?
Please visit the FOSSEE forum and post your question. |
Slide 15:
Acknowledgement |
Spoken Tutorial Project is funded by MHRD, Government of India. |
Slide 16:
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. |