OpenPLC-with-LDmicro/C3/TON-and-TOFF-Instructions/English

From Script | Spoken-Tutorial
Revision as of 17:43, 13 July 2021 by Nirmala Venkat (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Visual Cue
Narration
Slide 1: Welcome to the spoken tutorial on TON & TOFF instructions
Slide 2: Learning Objectives
  • Delayed turn ON (TON) timer
  • Delayed turn OFF (TOFF) timer
In this tutorial we’ll learn about working of
  • Delayed turn ON timer and
  • Delayed turn OFF timer
Slide 3: System Requirements
  • Ubuntu 18.04 OS
  • LDmicro
  • OpenPLCainboard
  • 24V, 2A SMPS
  • USBasp programmer
  • Traffic Light module
  • Switchboard module
To record this tutorial I am using:
  • Ubuntu Linux 18.04 operating system
  • LDmicro
  • OpenPLC Mainboard
  • 24V, 2A SMPS
  • USBasp programmer
  • Traffic Light module and
  • Switchboard module
Slide 4: Pre-requisites
  • To follow this tutorial, you should know the working of a Contact and a Coil.
  • If not, please refer to the relevant tutorials in this series on this website.
Slide 5: Prerequisites - Hardware setup

hardware-prerequisite.jpg

Connect SMPS and USBasp to the Mainboard as shown in the picture.

Keep these connections throughout this tutorial.

Open the LDmicro from the launcher bar Let us open LDmicro.
Click on Instructions -> Timers Click on Instructions and then on Timers.

In LDmicro, we have 3 different types of timers.

They are Delayed turn ON, Delayed turn OFF and Retentive delayed turn ON.

First, we will learn the working of a Delayed turn ON timer.
Insert ‘Instructions -> Insert Contact’ >> Place the cursor to the right of the contact >>

Insert ‘Instructions -> Insert Coil’

Insert a Contact and a Coil as shown.
Double-click on contact >> Type switch in name box >> Click OK button Rename the Contact as ‘switch’.
Double click on the coil >> Rename it as ‘LED1’ >> Click OK button Then rename the Coil as ‘LED'.
Place the cursor to the right of the contact >> Click Instructions -> Timers -> Insert TON We will now add a Delayed turn on timer to the right of Xswitch.

For that, place the cursor to the right of Xswitch.

Click on Instructions then Timers and then Insert TON.

Double-click on Tnew Double-click on the timer.
In the name column, type ON In the Name column, type ON.

Note that the name will be prefixed by T by default.

In the delay box type 5000

Click the OK button

In the Delay column we can enter the desired delay.

Note that the delay is in milliseconds.

We’ll have a delay of 5s.

So type 5000.

Click the OK button.

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 the state of Xswitch, YLED and TON in the I/O list Initially, the state of Xswitch, YLED and TON are 0.
Double click on Xswitch Double-click on Xswitch to change its state to 1.
Highlight the state of TON and YLED The state of TON will change to 20ms but the state of YLED is still 0.
Highlight the state of TON and YLED We can observe that the state of YLED will change to 1 after 5s.

The state of TON changes to 4.990s.

The TON variable counts up from zero in the units of PLC scan cycle, which is 10ms.
Double click on Xswitch in the I/O list Now, change the state of Xswitch to 0.
Highlight the state of YLED We can observe the state of YLED and TON changes to 0 immediately.
That is, when TON is given logic 0, it outputs logic 0 immediately.
Double click on Xswitch >> Double click on Xswitch Again change the state of Xswitch to 1.

Within 5s, change it back to 0.

Highlight the state of TON We can observe the state of TON goes back to 0.
Thus, for TON to output logic 1, it should be given logic 1 for at least the delay time.
Click Simulate -> Halt Simulation >> Click Simulate -> Simulation Mode Now, turn OFF the simulation mode.

For that, click Simulate and then on Halt Simulation.

Then click Simulate and Simulation Mode.

Now let us compile the logic.

The detailed steps on how to compile and save the logic are explained in the earlier tutorials.

Click on Settings >> Click on Microcontroller >> Select AVR ATmega16 40-PDIP

Click on Settings >> Click on MCU parameters >> Change Crystal frequency to 16

Click on Settings and select the microcontroller AVR ATmega16 40-PDIP.

Adjust its parameters as shown here.

Double-click on Xswitch in I/O list >> Select PC0 >> Click OK button

Double-click on YLED in I/O list >> Select PA0 >> Click OK button

Assign pin PC0 to Xswitch and pin PA0 to YLED.
Click on Compile >> Click on Compile >> rename it as ‘timeron.hex’ >> Go to Desktop/LDmicro folder >> Click on Save.

Click OK button

Compile the logic as timeron.hex
Click on File >> Click on Save >> Rename it as ‘timeron.ld’ >> Go to Desktop/LDmicro folder >> Click on Save Save the ladder diagram as timeron.ld.
Now we will see the working of this logic on hardware.
Connect Mainboard to PC using USBasp

laptop-usbasp.jpg

Connect the Mainboard to your laptop using USBasp.

Turn ON the power supply.

Open terminal >> Type cd Desktop/LDmicro >> Press ENTER >> type ‘avrdude -c usbasp -p m16 -U flash:w:timeron.hex’ >> Press ENTER Open the Terminal by pressing CTRL+ALT+T keys simultaneously.

Go to the folder where you have saved the hex file.

Type the command as shown to upload the hex file to the Mainboard.

Remove the USBasp connection from the laptop. Turn OFF the power supply.

Remove the USBasp connection from the laptop.

This will prevent any hardware damage.

timeron.png Let us see the connection details now.
timeron.png Connect GND pin of the red LED of Traffic Light module to GND of the Mainboard.

Then connect the +5V pin of the red LED to PA0 pin of the Mainboard.

timeron.png Connect GND and 5V of switchboard to GND and 5V of the Mainboard respectively.

Then connect NO1 of the Switchboard to PC0 of the Mainboard.

Make the connections as shown in the picture.

After making all the connections properly, turn ON the power supply.
Initially the red LED will not glow.
Press the switch NO1.

Remember NO1 should be pressed for at least 5s for LED to turn ON.

The red LED should turn ON 5s after the NO1 is pressed.
You can use latched action switches to avoid long pressing of switches.
Red LED will go OFF immediately when you release the switch NO1.
Thus the LED will glow after the switch is pressed for delay time.
Turn OFF the power supply.

Remove the connections made for this example.

We will now learn about the working of Delayed turn off timer.
Slide 6: Delayed turn off timer
  • When it is given logic 1 it outputs logic 1 immediately.
  • When given logic 0 it takes at least the delay time provided to output logic 0.
  • Its variable counts up from zero in the units of PLC scan cycle


For a Delayed turn off timer when given logic 1, it outputs logic 1 immediately.

When given logic 0 it takes at least the delay time provided to output logic 0.

Its variable counts up from zero in the units of PLC scan cycle.

Slide 7:

Code file - timeroff.ld

  • The files used in this tutorial are available in the Code Files link on this tutorial page.
  • Please download and extract them
  • Make a copy and then use them while practising
Switch back to LDmicro. Switch back to LDmicro.

I’ll open the timeroff.ld which I have created and saved already.

timeroff.ld logic on LDmicro interface Here, I have replaced the Delayed turn on timer with Delayed turn off timer.

I have renamed it as TOFF and given delay as 5s.

Hardware setup before connections Then compiled the logic as ‘timeroff.hex’ and uploaded the same to the Mainboard.
timeroff.png The connections will be the same as in the Delayed turn ON timer example.
Hardware setup after connections We can see that the red LED turns ON immediately after NO1 is pressed.
It will take 5s to turn OFF once you release the switch NO1.
Thus the LED goes off, after the delay time once the switch is released.
Note the difference between Delayed turn on and Delayed turn off timers.
This brings us to the end of this tutorial.

Let us summarize.

Slide 8: Summary
  • Delayed turn ON (TON) timer
  • Delayed turn OFF (TOFF) timer


In this tutorial we learnt about working of
  • Delayed turn ON timer and
  • Delayed turn OFF timer
Slide 9: Assignment
  • Draw a ladder diagram to blink an LED.
  • Hint: Use both Delayed turn ON and Delayed turn OFF timers.


  • As an assignment, draw a ladder diagram to blink an LED.
  • Hint: Use both Delayed turn ON and Delayed turn OFF timers.
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

Nirmala Venkat