Difference between revisions of "OpenPLC-version1-with-LDmicro/C3/CTU-Counter/English"

From Script | Spoken-Tutorial
Jump to: navigation, search
 
Line 9: Line 9:
 
|| Welcome to the spoken tutorial on '''CTU Counter'''
 
|| Welcome to the spoken tutorial on '''CTU Counter'''
 
|-  
 
|-  
|| Slide 2: Learning Objectives* Count up (CTU) counter
+
|| Slide 2: Learning Objectives
 +
* Count up (CTU) counter
  
|| In this tutorial, we’ll learn about the working of  
+
|| In this tutorial, we’ll learn about the working of '''Count up''' counter
 
+
* '''Count up''' counter
+
  
 
|-  
 
|-  
 
|| Slide 3: System Requirements
 
|| Slide 3: System Requirements
* Ubuntu 18.04''' '''OS
+
* Ubuntu 18.04 OS
 
* LDmicro
 
* LDmicro
 
* OpenPLC version 1 Mainboard
 
* OpenPLC version 1 Mainboard
Line 35: Line 34:
  
 
|-  
 
|-  
|| Slide 4: Pre-requisites* Working of Contact, Coil and RESET instructions
+
|| Slide 4: Pre-requisites
 +
* Working of Contact, Coil and RESET instructions
 
* If not, please refer to the relevant tutorials from [https://spoken-tutorial.org/ Home | spoken-tutorial.org]
 
* If not, please refer to the relevant tutorials from [https://spoken-tutorial.org/ Home | spoken-tutorial.org]
  
|| * To follow this tutorial, you should know the working of  
+
||  
 +
* To follow this tutorial, you should know the working of  
  
 
# '''Contact'''
 
# '''Contact'''
Line 62: Line 63:
  
  
|| In LDmicro, we have 3 types of counters.
+
|| In '''LDmicro''', we have 3 types of '''counters'''.
  
 
'''Count up''' which is represented as '''CTU'''.
 
'''Count up''' which is represented as '''CTU'''.
Line 71: Line 72:
 
|-  
 
|-  
 
||  
 
||  
|| Here first we will learn about '''CTU''' counter.
+
|| Here first we will learn about '''CTU counter'''.
  
In this tutorial, we will create a logic to turn on an LED.
+
In this tutorial, we will create a '''logic''' to turn '''on''' an '''LED'''.
  
The condition is when the switch is pressed for more than or equal to 3 times.
+
The '''condition''' is when the switch is pressed for more than or equal to 3 times.
 
|-  
 
|-  
 
|| Open the LDmicro from the launcher bar
 
|| Open the LDmicro from the launcher bar
Line 85: Line 86:
  
 
Click ‘Instructions -> Insert Coil’
 
Click ‘Instructions -> Insert Coil’
|| Insert a Contact and a Coil as shown.
+
|| Insert a '''Contact''' and a '''Coil''' as shown.
 
|-  
 
|-  
 
|| Double-click on Xnew >> Type switch in name box >> Click OK button
 
|| Double-click on Xnew >> Type switch in name box >> Click OK button
|| Rename the Contact as '''‘switch’.'''
+
|| Rename the '''Contact''' as '''‘switch’.'''
 
|-  
 
|-  
 
|| Double click on the Ynew >> Rename it as ‘LED’ >> Click OK button
 
|| Double click on the Ynew >> Rename it as ‘LED’ >> Click OK button
|| Then rename the Coil as '''‘LED’.'''.
+
|| Then rename the '''Coil''' as '''‘LED’.'''.
 
|-  
 
|-  
 
|| Place the cursor to the right of the contact >> Click Instructions -> Counters -> Insert CTU
 
|| Place the cursor to the right of the contact >> Click Instructions -> Counters -> Insert CTU
|| Place the cursor to the right of Xswitch.  
+
|| Place the cursor to the right of '''Xswitch'''.  
  
Now Insert a '''CTU''' from Instructions as shown here.
+
Now insert a '''CTU''' from '''Instructions''' as shown here.
 
|-  
 
|-  
 
|| Double-click on Cnew
 
|| Double-click on Cnew
|| Double-click on the counter.
+
|| Double-click on the '''counter'''.
 
|-  
 
|-  
 
|| In the name column, type count
 
|| In the name column, type count
 
|| We can observe there are two columns.
 
|| We can observe there are two columns.
  
First one is for the name of the counter.
+
First one is for the name of the '''counter'''.
  
 
Type '''‘count’''' in it.
 
Type '''‘count’''' in it.
Line 111: Line 112:
  
 
Click the OK button
 
Click the OK button
|| Second column is the condition column ‘'''True if >=’'''.
+
|| Second column is the '''condition''' column ‘'''True if >=’'''.
  
 
Here, we have to enter the desired count value.
 
Here, we have to enter the desired count value.
Line 119: Line 120:
 
Click on the '''OK''' button.
 
Click on the '''OK''' button.
  
Note that the name is prefixed by C by default.
+
Note that the name is prefixed by '''C''' by default.
 
|-  
 
|-  
 
||  
 
||  
|| We will now check the working of this logic.
+
|| We will now check the working of this '''logic'''.
 
|-  
 
|-  
 
|| Click Simulate -> Simulation mode >>
 
|| Click Simulate -> Simulation mode >>
  
 
Click Simulate -> Real-time simulation
 
Click Simulate -> Real-time simulation
|| Let us turn on the simulation mode.
+
|| Let us turn '''on''' the '''simulation mode'''.
  
 
For that, click '''Simulate''' and then on '''Simulation mode.'''
 
For that, click '''Simulate''' and then on '''Simulation mode.'''
  
Next, start real-time simulation as shown.
+
Next, start '''real-time simulation''' as shown.
 
|-  
 
|-  
 
|| Highlight the state of Xswitch, YLED and Ccount in the I/O list
 
|| Highlight the state of Xswitch, YLED and Ccount in the I/O list
Line 140: Line 141:
 
|-  
 
|-  
 
|| Highlight the state of Ccount and YLED
 
|| Highlight the state of Ccount and YLED
|| We can observe the state of the counter '''Ccount''' changes to 1.
+
|| We can observe the state of the '''counter Ccount''' changes to 1.
  
 
But, the state of '''YLED''' is still 0.
 
But, the state of '''YLED''' is still 0.
Line 148: Line 149:
 
|-  
 
|-  
 
|| Highlight the state of Ccount
 
|| Highlight the state of Ccount
|| We can observe the state of '''Ccount''' is still 1
+
|| We can observe the state of '''Ccount''' is still 1.
 
|-  
 
|-  
 
||  
 
||  
|| That is the counter value updates only with the rising edge of its input.
+
|| That is the '''counter''' value updates only with the rising edge of its input.
 
|-  
 
|-  
 
|| Double click on Xswitch for 3 times
 
|| Double click on Xswitch for 3 times
Line 173: Line 174:
 
|-  
 
|-  
 
||  
 
||  
|| Once the counter reaches desired count value, its output will always be 1.
+
|| Once the '''counter''' reaches desired count value, its output will always be 1.
  
This is because of the condition >= 3 in the CTU instruction.
+
This is because of the '''condition >= 3''' in the '''CTU''' instruction.
 
|-  
 
|-  
 
|| Click Simulate -> Halt Simulation >> Click Simulate -> Simulation Mode
 
|| Click Simulate -> Halt Simulation >> Click Simulate -> Simulation Mode
|| Now, turn off the simulation mode.
+
|| Now, turn '''off''' the '''simulation mode'''.
  
 
For that, click '''Simulate''' and then on '''Halt Simulation.'''
 
For that, click '''Simulate''' and then on '''Halt Simulation.'''
Line 185: Line 186:
 
|-  
 
|-  
 
||  
 
||  
|| Now let us compile the logic.
+
|| Now let us '''compile''' the '''logic'''.
  
The detailed steps on how to compile and save the logic are explained in the earlier tutorials.
+
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 Microcontroller >> Select AVR ATmega16 40-PDIP  
  
 
Click on Settings >> Click on MCU parameters >> Change Crystal frequency to 16
 
Click on Settings >> Click on MCU parameters >> Change Crystal frequency to 16
|| Click on '''Settings''' and select the microcontroller '''AVR ATmega16 40-PDIP.'''  
+
|| Click on '''Settings''' and select the '''microcontroller AVR ATmega16 40-PDIP.'''  
  
Adjust its parameters as shown here.
+
Adjust its '''parameters''' as shown here.
 
|-  
 
|-  
 
|| Double-click on Xswitch in I/O list >> Select PC0 >> Click OK button
 
|| 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
 
Double-click on YLED in I/O list >> Select PA0 >> Click OK button
|| Assign pin '''PC0''' to '''Xswitch '''and '''PA0''' to '''YLED'''.
+
|| Assign '''pin PC0''' to '''Xswitch '''and '''PA0''' to '''YLED'''.
 
|-  
 
|-  
 
|| Click on Compile >> Click on Compile >> Go to Desktop/LDmicro folder >> Rename it as ‘ctu.hex’ >> Click on Save.
 
|| Click on Compile >> Click on Compile >> Go to Desktop/LDmicro folder >> Rename it as ‘ctu.hex’ >> Click on Save.
  
Click OK button
+
Click '''OK''' button
|| Compile the logic as '''ctu.hex.'''
+
|| '''Compile''' the '''logic''' as '''ctu.hex.'''
 
|-  
 
|-  
 
|| Click on File >> Click on Save >> Go to Desktop/LDmicro folder >> Rename it as ‘ctu.ld’ >> Click on Save
 
|| Click on File >> Click on Save >> Go to Desktop/LDmicro folder >> Rename it as ‘ctu.ld’ >> Click on Save
|| Then save the ladder diagram as '''ctu.ld.'''
+
|| Then save the '''ladder diagram''' as '''ctu.ld.'''
 
|-  
 
|-  
 
||  
 
||  
|| We will now see the working of this logic on hardware.
+
|| We will now see the working of this '''logic''' on hardware.
 
|-  
 
|-  
 
|| Connect Mainboard to PC using USBasp
 
|| Connect Mainboard to PC using USBasp
Line 218: Line 219:
 
|| Connect the '''Mainboard''' to your laptop using '''USBasp'''.
 
|| Connect the '''Mainboard''' to your laptop using '''USBasp'''.
  
Turn on the power supply.
+
Turn '''on''' the '''power supply'''.
 
|-  
 
|-  
 
|| Open terminal >> Type cd Desktop/LDmicro >> Press ENTER >> type ‘'''avrdude -c usbasp -p m16 -U flash:w:ctu.hex’ '''>> Press ENTER
 
|| Open terminal >> Type cd Desktop/LDmicro >> Press ENTER >> type ‘'''avrdude -c usbasp -p m16 -U flash:w:ctu.hex’ '''>> Press ENTER
|| Open the Terminal by pressing '''CTRL+ALT+T''' keys simultaneously.
+
|| Open the '''Terminal''' by pressing '''CTRL+ALT+T''' keys simultaneously.
  
Go to the folder where you have saved the hex file.
+
Go to the folder where you have saved the '''hex file'''.
  
Type the command as shown to upload the hex file to the '''Mainboard'''.
+
Type the '''command''' as shown to upload the '''hex file''' to the '''Mainboard'''.
 
|-  
 
|-  
 
|| Remove the '''USBasp''' connection from the laptop.
 
|| Remove the '''USBasp''' connection from the laptop.
|| Turn off the power supply.
+
|| Turn '''off''' the '''power supply'''.
  
 
Remove the '''USBasp''' connection from the laptop.
 
Remove the '''USBasp''' connection from the laptop.
Line 237: Line 238:
 
|| Let us see the connection details now.  
 
|| Let us see the connection details now.  
 
|-  
 
|-  
|| ctu.png
+
|| ctu.png to show all the connections as per the narration
|| Connect '''GND''' pin of the red LED of '''Traffic Light''' module to '''GND''' of the '''Mainboard'''.
+
|| Connect '''GND pin''' of the red '''LED''' of '''Traffic Light''' module to '''GND''' of the '''Mainboard'''.
  
Then connect '''+5V pin''' of red LED to '''PA0''' pin of the '''Mainboard'''.
+
Then connect '''+5V pin''' of red '''LED''' to '''PA0 pin''' of the '''Mainboard'''.
 
|-  
 
|-  
|| ctu.png
+
|| ctu.png to show all the connections as per the narration
|| Connect '''GND''' and 5V of '''switchboard''' to GND and 5V of the '''Mainboard''' respectively.
+
|| 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'''.
 
Then connect '''NO1''' of the '''Switchboard''' to '''PC0''' of the '''Mainboard'''.
Line 249: Line 250:
 
Make the connections as shown in the picture.
 
Make the connections as shown in the picture.
 
|-  
 
|-  
||  
+
|| Turn on the power
|| After making all the connections properly, turn on the power supply.
+
|| After making all the connections properly, turn '''on''' the '''power supply'''.
 
|-  
 
|-  
||  
+
|| Red '''LED''' doesn't glow
|| Initially the red LED will not glow.
+
|| Initially the red '''LED''' will not glow.
 
|-  
 
|-  
||  
+
|| Press switch '''NO1''' thrice
 
|| It will glow only when the switch''' NO1''' is pressed for at least three times.
 
|| It will glow only when the switch''' NO1''' is pressed for at least three times.
  
 
So, press the switch''' NO1''' for 3 times.
 
So, press the switch''' NO1''' for 3 times.
 
|-  
 
|-  
||  
+
|| '''LED''' glows
|| We can see the LED will be glowing even after the '''NO1''' is released.
+
|| We can see the '''LED''' will be glowing even after the '''NO1''' is released.
 
|-  
 
|-  
||  
+
|| Turn off the power.
|| Turn off the power supply.
+
|| Turn '''off''' the '''power supply'''.
 
|-  
 
|-  
 
|| Slide 6: Resetting CTU
 
|| Slide 6: Resetting CTU
  
 
CTU counters can be reset using RES instruction
 
CTU counters can be reset using RES instruction
|| In order to turn off the LED we need to reset the counter.
+
|| In order to turn '''off''' the '''LED''' we need to '''reset''' the '''counter'''.
  
 
It can be done by using a '''RESET''' instruction as learnt in the '''RTO''' tutorial.
 
It can be done by using a '''RESET''' instruction as learnt in the '''RTO''' tutorial.
Line 278: Line 279:
 
Let us summarize.
 
Let us summarize.
 
|-  
 
|-  
|| Slide 7: Summary* Count up (CTU) counter
+
|| Slide 7: Summary
 
+
* Count up (CTU) counter
 
+
|| In this tutorial we learnt about working of '''Count up counter'''.
|| In this tutorial we learnt about working of * '''Count up '''counter
+
 
|-  
 
|-  
|| Slide 8: Assignment* Draw a ladder diagram to turn on an LED when the switch is pressed for >= 5 times.
+
|| Slide 8: Assignment
 +
* Draw a ladder diagram to turn on an LED when the switch is pressed for >= 5 times.
 
* Include logic to reset the LED.
 
* Include logic to reset the LED.
  
Line 289: Line 290:
 
|| As an assignment do the following:
 
|| As an assignment do the following:
  
# Draw a ladder diagram to turn on an LED. The condition is when the switch is pressed for more than or equal to 5 times.
+
# Draw a '''ladder diagram''' to turn '''on''' an '''LED'''. The '''condition''' is when the switch is pressed for more than or equal to 5 times.
# Include logic to reset the LED.
+
# Include '''logic''' to '''reset''' the '''LED'''.
  
Hint: Use another Contact and RES instruction.
+
Hint: Use another '''Contact''' and '''RES''' instruction.
 
|-  
 
|-  
 
|| Slide 9:
 
|| Slide 9:
Line 304: Line 305:
  
 
Spoken Tutorial workshops
 
Spoken Tutorial workshops
|| The''' Spoken Tutorial Project''' team:* conducts workshops using spoken tutorials and
+
|| The''' Spoken Tutorial Project''' team:
 +
* conducts workshops using spoken tutorials and
 
* gives certificates on passing online tests.
 
* gives certificates on passing online tests.
  

Latest revision as of 20:57, 9 January 2021

Visual Cue Narration
Slide 1: Welcome to the spoken tutorial on CTU Counter
Slide 2: Learning Objectives
  • Count up (CTU) counter
In this tutorial, we’ll learn about the working of Count up counter
Slide 3: System Requirements
  • Ubuntu 18.04 OS
  • 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. Contact
  2. Coil and
  3. RESET instructions.
  • 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.

Slide 5: Counters

3 types of counters

  1. Count up (CTU)
  2. Count down(CTD)
  3. Count circular(CTC)


In LDmicro, we have 3 types of counters.

Count up which is represented as CTU.

Count down which is represented as CTD and

Count circular which is represented as CTC.

Here first we will learn about CTU counter.

In this tutorial, we will create a logic to turn on an LED.

The condition is when the switch is pressed for more than or equal to 3 times.

Open the LDmicro from the launcher bar Let us open LDmicro.
Click ‘Instructions -> Insert Contact’ >>

Place the cursor to the right of the contact >>

Click ‘Instructions -> Insert Coil’

Insert a Contact and a Coil as shown.
Double-click on Xnew >> Type switch in name box >> Click OK button Rename the Contact as ‘switch’.
Double click on the Ynew >> Rename it as ‘LED’ >> Click OK button Then rename the Coil as ‘LED’..
Place the cursor to the right of the contact >> Click Instructions -> Counters -> Insert CTU Place the cursor to the right of Xswitch.

Now insert a CTU from Instructions as shown here.

Double-click on Cnew Double-click on the counter.
In the name column, type count We can observe there are two columns.

First one is for the name of the counter.

Type ‘count’ in it.

In the True if >= column type 3

Click the OK button

Second column is the condition column ‘True if >=’.

Here, we have to enter the desired count value.

We will enter 3 as the count value.

Click on the OK button.

Note that the name is prefixed by C by default.

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 Ccount in the I/O list We can observe initially the states of Xswitch, YLED and Ccount are 0.
Double click on Xswitch in the I/O list Double click on the Xswitch to change its state to 1.
Highlight the state of Ccount and YLED We can observe the state of the counter Ccount changes to 1.

But, the state of YLED is still 0.

Double click on Xswitch Now, change the state of Xswitch back to 0.
Highlight the state of Ccount We can observe the state of Ccount is still 1.
That is the counter value updates only with the rising edge of its input.
Double click on Xswitch for 3 times Change the state of Xswitch from 0 to 1 for a couple more times.
Highlight the state of Ccount After 3 low to high transitions of Xswitch, the state of Ccount reaches 3.
Highlight the state of YLED We can now observe the state of YLED changes to 1.
Double click on Xswitch for 2 times Change the state of Xswitch to 0.

Again change it back to 1.

Highlight the state of YLED The state of Ccount changes to 4.

We can observe that the state of YLED is still 1.

Once the counter reaches desired count value, its output will always be 1.

This is because of the condition >= 3 in the CTU 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 Xswitch and PA0 to YLED.
Click on Compile >> Click on Compile >> Go to Desktop/LDmicro folder >> Rename it as ‘ctu.hex’ >> Click on Save.

Click OK button

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

ctu.png Let us see the connection details now.
ctu.png to show all the connections as per the narration Connect GND pin of the red LED of Traffic Light module to GND of the Mainboard.

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

ctu.png to show all the connections as per the narration 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.

Turn on the power After making all the connections properly, turn on the power supply.
Red LED doesn't glow Initially the red LED will not glow.
Press switch NO1 thrice It will glow only when the switch NO1 is pressed for at least three times.

So, press the switch NO1 for 3 times.

LED glows We can see the LED will be glowing even after the NO1 is released.
Turn off the power. Turn off the power supply.
Slide 6: Resetting CTU

CTU counters can be reset using RES instruction

In order to turn off the LED we need to reset the counter.

It can be done by using a RESET instruction as learnt in the RTO tutorial.

This brings us to the end of this tutorial.

Let us summarize.

Slide 7: Summary
  • Count up (CTU) counter
In this tutorial we learnt about working of Count up counter.
Slide 8: Assignment
  • Draw a ladder diagram to turn on an LED when the switch is pressed for >= 5 times.
  • Include logic to reset the LED.

Hint: Use another Contact and RES instruction

As an assignment do the following:
  1. Draw a ladder diagram to turn on an LED. The condition is when the switch is pressed for more than or equal to 5 times.
  2. Include logic to reset the LED.

Hint: Use another Contact and RES instruction.

Slide 9:

About Spoken Tutorial project

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

Please download and watch it

Slide 10:

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

Forum for specific questions:

Please post your timed queries in this forum
Slide 12:

Forum for specific questions:

Do you have any general / technical questions on OpenPLC?

Please visit the FOSSEE forum and post your question.

Slide 13:

Acknowledgement

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

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