OpenPLC-with-LDmicro/C3/CTC-Counter/English
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. |