OpenPLC-version1-with-LDmicro/C3/CTD-Counter/English

From Script | Spoken-Tutorial
Revision as of 18:08, 23 December 2020 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 CTD Counter
Slide 2:

Learning Objectives

  • Count down (CTD) counter

In this tutorial we’ll learn about working of

  • Count down counter
Slide 3:

System Requirements

  • Ubuntu 18.04 operating system
  • LDmicro
  • OpenPLC version 1 Mainboard
  • 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 version1 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
  1. CTU and
  2. Compare instruction.
  • 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.

We will create an up-down counter to understand the working of CTD.
Open the LDmicro from the launcher bar Let us open LDmicro.
Click on Instructions -> Insert Contact >> Place the cursor to the right of Xnew >> Click on Instructions -> Insert Coil Insert a Contact and a Coil as shown.
Double-click on Xnew >> Type ‘up’ in the name box >> Click the OK button Rename the Contact as ‘up’.
Place the cursor below Xup >> Click on Instructions -> Insert Contact Now Insert a Contact parallel to Xup.

Rename the new Contact as ‘down’.

Place the cursor to the right of Xup >> Click Instructions -> Counters -> Insert CTU To the right of Xup insert a CTU as shown here.
Double-click the Cnew >> Type count in the name column >> Click the OK button Double click on CTU.

Rename the CTU as ‘count’.

The condition value is by default 0.

Don’t change it.

Place the cursor to the right of Xdown >> Click Instructions -> Counters -> Insert CTD To the right of Xdown insert a CTD as shown here.
Double-click the Cnew >> Type count in the name column >> Click the OK button Double click on CTD.

Just like CTU it has two columns, ‘Name’ and ‘True if >=’.

Rename the CTD as ‘count’.

The condition value is by default 0.

Don’t change it.

Double-click on Ynew >> Select Internal Relay >> Type relay in the name box >> Click the OK button Now configure the Coil as Internal Relay and rename it as ‘relay’.
This is because here we don't need any physical output from CTU & CTD.
Click Edit -> Insert Rung below Now place a rung below as shown here.
Place the cursor in the new rung >> Click on Instructions -> Comparison operators -> Insert GEQ In the new rung insert a greater than or equal to Compare instruction.
Double-click on greater than or equal to Compare instruction >> Type Ccount in the ‘Closed’ if: column >> Type 3 in the >= column Double-click on the compare instruction.

Compare Ccount variable with 3.

That is in the Closed if column enter Ccount.

In the >= column enter 3.

Click on the OK button

Place the cursor to the right of Compare instruction >> Click on Instructions -> Insert Coil Now to the right of it insert a Coil.
Double click on Ynew >> Type LED in the name column Rename it as ‘LED’.
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 states of all the instructions in the IO list We can observe initially that the state of every instruction is 0 except for Rrelay.
Double click on Xup Double click on Xup to change its state to 1.
Highlight the state of Ccount We can observe the state of the Ccount changes to 1.
Highlight the state of Ccount Keep changing the state of Xup by double clicking on it until Ccount value reaches 3.
Highlight the state of YLED We can observe the state of YLED changes to 1.
Just like in the CTU example.
Double click on Xdown Now change the state of Xdown to 1.
Highlight the state of Ccount We can observe the Ccount value changes to 2.

That is decreased by 1.

Highlight the state of YLED Also, the state of YLED goes back to 0.

The state of YLED will be 1 only when Ccount value is >= 3.

Double click on Xdown Change the state of Xdown back to 0.
Highlight the state of Ccount The value of Ccount is still 2.
Highlight the state of Ccount The CTD decreases the count value by 1 only with the rising edge of its input.
Thus the working of CTU and CTD is similar.

The only difference is CTD decrements the counter value.

We can also reset the CTD using RESET instruction.
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 Xup and PC1 to Xdown.

Assign pin PA0 to YLED.

Click on Compile >> Click on Compile >> Go to Desktop/LDmicro folder >> Rename it as ‘ctd.hex’ >> Click on Save.

Click OK button

Compile the logic as ctd.hex.
Click on File >> Click on Save >> Go to Desktop/LDmicro folder >> Rename it as ‘ctd.ld’ >> Click on Save Then save the ladder diagram as ctd.ld.
We will now 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:ctd.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.

ctd.png Let us see the connection details now.
ctd.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.

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

Connect NO1 to PC0 of the Mainboard.

Then connect NO2 to PC1 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.
It will glow only when NO1 is pressed for at least three times.

So, press the switch NO1 for 3 times.

Now the count value is 3.
Press the switch NO2.

The count value becomes 2 and the LED will turn off.

Thus CTD decreases the count value by 1 after every switch press.

Turn off the power supply.

Slide : Where can an up-down counter be used?* The up-down counter can be used when we need to count finished products.
  • CTU will increment the count value when a product is finished.
  • CTD will decrement the count of products that fail the quality test.
Where can an up-down counter be used?

The up-down counter can be used when we need to count the finished products.

CTU will increment the count value when a product is finished.

CTD will decrement the count of products that fail the quality test.

This brings us to the end of this tutorial.

Let us summarize.

Slide 5: Summary* Count down (CTD) counter In this tutorial we learnt about working of * Count down counter
Slide 6:

About Spoken Tutorial project

The video at the following link summarises the Spoken Tutorial project.

Please download and watch it

Slide 7:

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 8:

Forum for specific questions:

* Please post your timed queries in this Forum
Slide 19:

Forum for specific questions:

Do you have any general / technical questions on OpenPLC?

Please visit the FOSSEE forum and post your question.

Slide 10:

Acknowledgement

Spoken Tutorial Project is funded by MHRD, Government of India.
Slide 11:

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, Nirmala Venkat