Difference between revisions of "OpenPLC-version1-with-LDmicro/C3/CTC-Counter/English"
(Created page with " {| border="1" |- | align=center| '''Visual Cue''' | align=center| '''Narration''' |- || Slide 1: || Welcome to the spoken tutorial on '''CTC Counter''' |- || Slide 2: L...") |
Nancyvarkey (Talk | contribs) |
||
Line 15: | Line 15: | ||
|| | || | ||
− | In this tutorial, we’ll learn about working of | + | In this tutorial, we’ll learn about working of '''Count circular counter'''. |
− | + | ||
|- | |- | ||
|| Slide 3: System Requirements | || Slide 3: System Requirements | ||
Line 32: | Line 31: | ||
* '''OpenPLC version1 Mainboard''' | * '''OpenPLC version1 Mainboard''' | ||
* '''24V, 2A SMPS''' | * '''24V, 2A SMPS''' | ||
− | * '''USBasp''' | + | * '''USBasp programmer''' |
* '''Traffic Light''' module and | * '''Traffic Light''' module and | ||
* '''Switchboard''' module | * '''Switchboard''' module | ||
|- | |- | ||
− | || Slide 4: Pre-requisites* Working of CTU and CTD counters | + | || Slide 4: Pre-requisites |
+ | * Working of CTU and CTD counters | ||
* 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 '''CTU''' and '''CTD''' | + | || |
+ | * To follow this tutorial, you should know the working of '''CTU''' and '''CTD counters'''. | ||
* 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 55: | Line 56: | ||
|- | |- | ||
|| | || | ||
− | || In this tutorial, we will create a ladder logic to turn on an LED. | + | || In this tutorial, we will create a '''ladder logic''' to turn '''on''' an '''LED'''. |
− | The condition is when the switch is pressed for exactly 3 times. | + | The '''condition''' is when the switch is pressed for exactly 3 times. |
|- | |- | ||
|| Click ‘Instructions -> Insert Contact’ | || Click ‘Instructions -> Insert Contact’ | ||
Line 69: | Line 70: | ||
For that place the cursor to the right of '''Xswitch'''. | For that place the cursor to the right of '''Xswitch'''. | ||
− | Click on Instructions, then Counters and then on ‘'''Insert CTC’'''. | + | Click on '''Instructions''', then '''Counters''' and then on ‘'''Insert CTC’'''. |
|- | |- | ||
|| Double-click on Cnew | || Double-click on Cnew | ||
− | || Double-click on the CTC. | + | || Double-click on the '''CTC'''. |
|- | |- | ||
− | || In the | + | || 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 84: | Line 85: | ||
Click the OK button | Click the OK button | ||
− | || Second column is the Max value i.e. maximum value of the counter. | + | || Second column is the '''Max value''' i.e. maximum value of the '''counter'''. |
− | Here, we have to enter the desired count value. | + | Here, we have to enter the desired '''count''' value. |
− | We will enter 3 as the count value. | + | We will enter 3 as the '''count''' value. |
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. |
|- | |- | ||
|| Click Edit -> Insert rung below | || Click Edit -> Insert rung below | ||
− | || Now, insert a rung below. | + | || Now, insert a '''rung''' below. |
|- | |- | ||
|| Place the cursor in the new rung >> Click Instructions -> Comparison operators -> Insert EQU | || Place the cursor in the new rung >> Click Instructions -> Comparison operators -> Insert EQU | ||
Place the cursor to the right of EQU >> Click Instructions -> Insert Coil | Place the cursor to the right of EQU >> Click Instructions -> Insert Coil | ||
− | || Insert '''equals''' | + | || Insert '''equals compare''' instruction in the new '''rung''' as shown. |
Place the cursor to the right of '''EQU''' and insert a '''Coil'''. | Place the cursor to the right of '''EQU''' and insert a '''Coil'''. | ||
|- | |- | ||
|| Double-click on EQU >> Type Ccount in the ‘Closed’ if column >> Type 3 in =: column >> Click the OK button | || Double-click on EQU >> Type Ccount in the ‘Closed’ if column >> Type 3 in =: column >> Click the OK button | ||
− | || In the | + | || In the '''Compare''' instruction, compare '''Ccount''' with 3. |
That is, in the '''‘Closed if’''' column type '''Ccount''' and in the '''‘equals’''' column type 3. | That is, in the '''‘Closed if’''' column type '''Ccount''' and in the '''‘equals’''' column type 3. | ||
|- | |- | ||
|| Double click on the coil >> Rename it as ‘LED’ >> Click OK button | || Double click on the coil >> Rename it as ‘LED’ >> Click OK button | ||
− | || Rename the Coil as '''‘LED’'''. | + | || Rename the '''Coil''' as '''‘LED’'''. |
|- | |- | ||
|| | || | ||
− | || 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 TON in the IO list | || Highlight the state of Xswitch, YLED and TON in the IO list | ||
Line 137: | Line 138: | ||
|- | |- | ||
|| | || | ||
− | || Just like CTU | + | || Just like '''CTU''' and '''CTD''', the '''Ccount''' value updates only with the rising edge of its input. |
|- | |- | ||
|| Double-click on Xswitch for 5 times | || Double-click on Xswitch for 5 times | ||
Line 154: | Line 155: | ||
|- | |- | ||
|| | || | ||
− | || That is there is no need of '''RESET''' instruction to reset the counter. | + | || That is there is no need of '''RESET''' instruction to '''reset''' the '''counter'''. |
|- | |- | ||
|| 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 164: | Line 165: | ||
|- | |- | ||
|| | || | ||
− | || 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 | + | || 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 | + | || Assign '''pin PC0''' to '''Xswitch''' and '''PA0''' to '''YLED'''. |
|- | |- | ||
|| Click on Compile >> Click on Compile >> Go to Desktop/LDmicro folder >> Rename it as ‘ctc.hex’ >> Click on Save. | || Click on Compile >> Click on Compile >> Go to Desktop/LDmicro folder >> Rename it as ‘ctc.hex’ >> Click on Save. | ||
Click OK button | Click OK button | ||
− | || Compile the logic as '''ctc.hex''' | + | || '''Compile''' the '''logic''' as '''ctc.hex''' |
|- | |- | ||
|| Click on File >> Click on Save >> Go to Desktop/LDmicro folder >> Rename it as ‘ctc.ld’ >> Click on Save | || Click on File >> Click on Save >> Go to Desktop/LDmicro folder >> Rename it as ‘ctc.ld’ >> Click on Save | ||
Line 189: | Line 190: | ||
|- | |- | ||
|| | || | ||
− | || 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 197: | Line 198: | ||
|| 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:ctc.hex’ '''>> Press ENTER | || Open terminal >> Type cd Desktop/LDmicro >> Press ENTER >> type ‘'''avrdude -c usbasp -p m16 -U flash:w:ctc.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 216: | Line 217: | ||
|| Let us see the connection details now. | || Let us see the connection details now. | ||
|- | |- | ||
− | || ctc.png | + | || ctc.png >> connect as per the narration |
− | || Connect '''GND''' | + | || 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''' | + | Then connect the '''+5V pin''' of the red '''LED''' to '''PA0 pin''' of the '''Mainboard'''. |
|- | |- | ||
− | || ctc.png | + | || ctc.png >> connect 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 228: | Line 229: | ||
Make the connections as shown in the picture. | Make the connections as shown in the picture. | ||
|- | |- | ||
− | || | + | || Turn '''on''' the '''power supply'''. |
− | || After making all the connections properly, turn on the power supply. | + | || After making all the connections properly, turn '''on''' the '''power supply'''. |
|- | |- | ||
− | || | + | || Point to red '''LED''' |
− | || Initially the red LED will not glow. | + | || Initially the red '''LED''' will not glow. |
|- | |- | ||
− | || | + | || Press '''NO1''' three times |
− | || It will glow only when NO1 is pressed for three times. | + | || It will glow only when '''NO1''' is pressed for three times. |
− | So, press the NO1 for 3 times. | + | So, press the '''NO1''' for 3 times. |
|- | |- | ||
− | || | + | || LED glows |
− | || We can see the LED will be glowing even after NO1 is released. | + | || We can see the '''LED''' will be glowing even after '''NO1''' is released. |
|- | |- | ||
− | || | + | || Press '''NO1''' |
|| Press the switch '''NO1''' for one more time. | || Press the switch '''NO1''' for one more time. | ||
− | We can observe the LED goes off. | + | We can observe the '''LED''' goes '''off'''. |
Recall that it was not the case with '''CTU'''. | Recall that it was not the case with '''CTU'''. | ||
|- | |- | ||
|| | || | ||
− | || That is '''CTC''' | + | || That is '''CTC counter''' resets automatically after reaching the desired '''count''' value. |
− | Thus the difference between '''CTU''' and '''CTC''' is auto reset. | + | Thus the difference between '''CTU''' and '''CTC''' is '''auto reset'''. |
|- | |- | ||
− | || | + | || Turn '''off''' the '''power supply'''. |
− | || Turn off the power supply. | + | || Turn '''off''' the '''power supply'''. |
|- | |- | ||
|| | || | ||
Line 262: | Line 263: | ||
Let us summarize. | Let us summarize. | ||
|- | |- | ||
− | || Slide 7: Summary* Count circular (CTC) counter | + | || Slide 7: Summary |
+ | * Count circular (CTC) counter | ||
− | || In this tutorial we learnt about working of | + | || In this tutorial we learnt about working of '''Count circular '''counter. |
|- | |- | ||
|| Slide 8: Assignment | || Slide 8: Assignment | ||
Line 275: | Line 277: | ||
|| As an assignment, do the following. | || As an assignment, do the following. | ||
− | Draw a ladder logic where the state of LED depends on switch press count. | + | Draw a '''ladder logic''' where the state of '''LED''' depends on switch press count. |
− | That is, when# count = 0, LED should RESET. | + | That is, when |
− | # count = 1 , LED should start blinking | + | # '''count''' = 0, '''LED''' should '''RESET'''. |
− | # count = 2, the LED should be SET | + | # '''count''' = 1 , '''LED''' should start blinking |
+ | # '''count''' = 2, the '''LED''' should be '''SET''' | ||
|- | |- | ||
|| Slide 9: | || Slide 9: | ||
Line 291: | Line 294: | ||
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 | * gives certificates on passing online | ||
tests. | tests. |
Latest revision as of 00:35, 11 January 2021
Visual Cue | Narration |
Slide 1: | Welcome to the spoken tutorial on CTC Counter |
Slide 2:
Learning Objectives
|
In this tutorial, we’ll learn about working of Count circular counter. |
Slide 3: System Requirements
|
To record this tutorial I am using:
|
Slide 4: Pre-requisites
|
|
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 | Let us open LDmicro. |
In this tutorial, we will create a ladder logic to turn on an LED.
The condition is when the switch is pressed for exactly 3 times. | |
Click ‘Instructions -> Insert Contact’
Double-click on Xnew >> Type ‘switch’ in name box >> Click OK button |
Insert a Contact and then rename it as ‘switch’ as shown. |
Place the cursor to the right of Xswitch >> Click Instructions -> Counters -> Insert CTC | We will now insert a CTC to the right of Xswitch.
For that place the cursor to the right of Xswitch. Click on Instructions, then Counters and then on ‘Insert CTC’. |
Double-click on Cnew | Double-click on the CTC. |
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 Max value i.e. maximum value of the counter.
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. |
Click Edit -> Insert rung below | Now, insert a rung below. |
Place the cursor in the new rung >> Click Instructions -> Comparison operators -> Insert EQU
Place the cursor to the right of EQU >> Click Instructions -> Insert Coil |
Insert equals compare instruction in the new rung as shown.
Place the cursor to the right of EQU and insert a Coil. |
Double-click on EQU >> Type Ccount in the ‘Closed’ if column >> Type 3 in =: column >> Click the OK button | In the Compare instruction, compare Ccount with 3.
That is, in the ‘Closed if’ column type Ccount and in the ‘equals’ column type 3. |
Double click on the coil >> Rename it as ‘LED’ >> Click OK button | Rename the Coil 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 state of Xswitch, YLED and TON in the IO list | Initially the state of Xswitch, YLED and Ccount are 0. |
Double-click on Xswitch in the IO list
Highlight the state of Ccount |
Change the state of Xswitch to 1 by double clicking on it.
We can observe the Ccount value changes to 1. Change the state of Xswitch back to 0. |
Just like CTU and CTD, the Ccount value updates only with the rising edge of its input. | |
Double-click on Xswitch for 5 times
Highlight the state of YLED |
Keep double clicking on Xswitch until the state of Ccount reaches 3.
We can observe the state of YLED changes to 1. |
Double-click on Xswitch
Highlight the state of Ccount |
Once again change the state of Xswitch from 0 to 1.
We can observe the Ccount value goes back to 0. |
That is there is no need of RESET instruction to reset the counter. | |
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 ‘ctc.hex’ >> Click on Save.
Click OK button |
Compile the logic as ctc.hex |
Click on File >> Click on Save >> Go to Desktop/LDmicro folder >> Rename it as ‘ctc.ld’ >> Click on Save | Save the file as ctc.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:ctc.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. |
ctc.png | Let us see the connection details now. |
ctc.png >> connect as per the narration | 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. |
ctc.png >> connect 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 supply. | After making all the connections properly, turn on the power supply. |
Point to red LED | Initially the red LED will not glow. |
Press NO1 three times | It will glow only when NO1 is pressed for three times.
So, press the NO1 for 3 times. |
LED glows | We can see the LED will be glowing even after NO1 is released. |
Press NO1 | Press the switch NO1 for one more time.
We can observe the LED goes off. Recall that it was not the case with CTU. |
That is CTC counter resets automatically after reaching the desired count value.
Thus the difference between CTU and CTC is auto reset. | |
Turn off the power supply. | Turn off the power supply. |
This brings us to the end of this tutorial.
Let us summarize. | |
Slide 7: Summary
|
In this tutorial we learnt about working of Count circular counter. |
Slide 8: Assignment
Draw a ladder logic where the state of LED depends on switch press count
|
As an assignment, do the following.
Draw a ladder logic where the state of LED depends on switch press count. That is, when
|
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:
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. |