OpenPLC-with-LDmicro/C2/Simulation-and-Compilation/English
|
|
Slide 1:
Welcome Slide |
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. |