<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="https://script.spoken-tutorial.org/skins/common/feed.css?303"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://script.spoken-tutorial.org/index.php?action=history&amp;feed=atom&amp;title=OpenPLC-with-LDmicro%2FC3%2FCTU-Counter%2FEnglish</id>
		<title>OpenPLC-with-LDmicro/C3/CTU-Counter/English - Revision history</title>
		<link rel="self" type="application/atom+xml" href="https://script.spoken-tutorial.org/index.php?action=history&amp;feed=atom&amp;title=OpenPLC-with-LDmicro%2FC3%2FCTU-Counter%2FEnglish"/>
		<link rel="alternate" type="text/html" href="https://script.spoken-tutorial.org/index.php?title=OpenPLC-with-LDmicro/C3/CTU-Counter/English&amp;action=history"/>
		<updated>2026-05-13T20:22:30Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.23.17</generator>

	<entry>
		<id>https://script.spoken-tutorial.org/index.php?title=OpenPLC-with-LDmicro/C3/CTU-Counter/English&amp;diff=55351&amp;oldid=prev</id>
		<title>Nirmala Venkat: Created page with &quot; {| border=&quot;1&quot; |-  | align=center| '''Visual Cue''' | align=center| '''Narration''' |-  || Slide 1:  || Welcome to the spoken tutorial on '''CTU Counter''' |-  || Slide 2: Lea...&quot;</title>
		<link rel="alternate" type="text/html" href="https://script.spoken-tutorial.org/index.php?title=OpenPLC-with-LDmicro/C3/CTU-Counter/English&amp;diff=55351&amp;oldid=prev"/>
				<updated>2021-07-14T10:43:31Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot; {| border=&amp;quot;1&amp;quot; |-  | align=center| &amp;#039;&amp;#039;&amp;#039;Visual Cue&amp;#039;&amp;#039;&amp;#039; | align=center| &amp;#039;&amp;#039;&amp;#039;Narration&amp;#039;&amp;#039;&amp;#039; |-  || Slide 1:  || Welcome to the spoken tutorial on &amp;#039;&amp;#039;&amp;#039;CTU Counter&amp;#039;&amp;#039;&amp;#039; |-  || Slide 2: Lea...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| align=center| '''Visual Cue'''&lt;br /&gt;
| align=center| '''Narration'''&lt;br /&gt;
|- &lt;br /&gt;
|| Slide 1: &lt;br /&gt;
|| Welcome to the spoken tutorial on '''CTU Counter'''&lt;br /&gt;
|- &lt;br /&gt;
|| Slide 2: Learning Objectives&lt;br /&gt;
* Count up (CTU) counter&lt;br /&gt;
&lt;br /&gt;
|| In this tutorial, we’ll learn about the working of '''Count up''' counter&lt;br /&gt;
&lt;br /&gt;
|- &lt;br /&gt;
|| Slide 3: System Requirements&lt;br /&gt;
* Ubuntu 18.04 OS&lt;br /&gt;
* LDmicro&lt;br /&gt;
* OpenPLC Mainboard&lt;br /&gt;
* 24V, 2A SMPS&lt;br /&gt;
* USBasp programmer&lt;br /&gt;
* Traffic Light module&lt;br /&gt;
* Switchboard module&lt;br /&gt;
&lt;br /&gt;
|| To record this tutorial I am using:&lt;br /&gt;
* '''Ubuntu Linux 18.04''' operating system&lt;br /&gt;
* '''LDmicro'''&lt;br /&gt;
* '''OpenPLC Mainboard'''&lt;br /&gt;
* '''24V, 2A SMPS'''&lt;br /&gt;
* '''USBasp''' programmer&lt;br /&gt;
* '''Traffic Light''' module and &lt;br /&gt;
* '''Switchboard''' module&lt;br /&gt;
&lt;br /&gt;
|- &lt;br /&gt;
|| Slide 4: Pre-requisites&lt;br /&gt;
* Working of Contact, Coil and RESET instructions&lt;br /&gt;
* If not, please refer to the relevant tutorials from [https://spoken-tutorial.org/ Home | spoken-tutorial.org]&lt;br /&gt;
&lt;br /&gt;
|| &lt;br /&gt;
* To follow this tutorial, you should know the working of &lt;br /&gt;
&lt;br /&gt;
# '''Contact'''&lt;br /&gt;
# '''Coil''' and &lt;br /&gt;
# '''RESET''' instructions.&lt;br /&gt;
&lt;br /&gt;
* If not, please refer to the relevant tutorials in this series on this website.&lt;br /&gt;
&lt;br /&gt;
|- &lt;br /&gt;
|| Slide 5: Prerequisites - Hardware setup&lt;br /&gt;
&lt;br /&gt;
hardware-prerequisite.jpg&lt;br /&gt;
|| Connect''' SMPS''' and '''USBasp''' to the '''Mainboard''' as shown in the picture.&lt;br /&gt;
&lt;br /&gt;
Keep these connections throughout this tutorial.&lt;br /&gt;
|- &lt;br /&gt;
|| Slide 5: Counters&lt;br /&gt;
&lt;br /&gt;
3 types of counters&lt;br /&gt;
# Count up (CTU)&lt;br /&gt;
# Count down(CTD)&lt;br /&gt;
# Count circular(CTC)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|| In '''LDmicro''', we have 3 types of '''counters'''.&lt;br /&gt;
&lt;br /&gt;
'''Count up''' which is represented as '''CTU'''.&lt;br /&gt;
&lt;br /&gt;
'''Count down''' which is represented as '''CTD''' and&lt;br /&gt;
&lt;br /&gt;
'''Count circular '''which is represented as '''CTC'''.&lt;br /&gt;
|- &lt;br /&gt;
|| &lt;br /&gt;
|| Here first we will learn about '''CTU counter'''.&lt;br /&gt;
&lt;br /&gt;
In this tutorial, we will create a '''logic''' to turn '''on''' an '''LED'''.&lt;br /&gt;
&lt;br /&gt;
The '''condition''' is when the switch is pressed for more than or equal to 3 times.&lt;br /&gt;
|- &lt;br /&gt;
|| Open the LDmicro from the launcher bar&lt;br /&gt;
|| Let us open '''LDmicro'''.&lt;br /&gt;
|- &lt;br /&gt;
|| Click ‘Instructions -&amp;gt; Insert Contact’ &amp;gt;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Place the cursor to the right of the contact &amp;gt;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Click ‘Instructions -&amp;gt; Insert Coil’&lt;br /&gt;
|| Insert a '''Contact''' and a '''Coil''' as shown.&lt;br /&gt;
|- &lt;br /&gt;
|| Double-click on Xnew &amp;gt;&amp;gt; Type switch in name box &amp;gt;&amp;gt; Click OK button&lt;br /&gt;
|| Rename the '''Contact''' as '''‘switch’.'''&lt;br /&gt;
|- &lt;br /&gt;
|| Double click on the Ynew &amp;gt;&amp;gt; Rename it as ‘LED’ &amp;gt;&amp;gt; Click OK button&lt;br /&gt;
|| Then rename the '''Coil''' as '''‘LED’.'''.&lt;br /&gt;
|- &lt;br /&gt;
|| Place the cursor to the right of the contact &amp;gt;&amp;gt; Click Instructions -&amp;gt; Counters -&amp;gt; Insert CTU&lt;br /&gt;
|| Place the cursor to the right of '''Xswitch'''. &lt;br /&gt;
&lt;br /&gt;
Now insert a '''CTU''' from '''Instructions''' as shown here.&lt;br /&gt;
|- &lt;br /&gt;
|| Double-click on Cnew&lt;br /&gt;
|| Double-click on the '''counter'''.&lt;br /&gt;
|- &lt;br /&gt;
|| In the name column, type count&lt;br /&gt;
|| We can observe there are two columns.&lt;br /&gt;
&lt;br /&gt;
First one is for the name of the '''counter'''.&lt;br /&gt;
&lt;br /&gt;
Type '''‘count’''' in it.&lt;br /&gt;
|- &lt;br /&gt;
|| In the True if &amp;gt;= column type 3&lt;br /&gt;
&lt;br /&gt;
Click the OK button&lt;br /&gt;
|| Second column is the '''condition''' column ‘'''True if &amp;gt;=’'''.&lt;br /&gt;
&lt;br /&gt;
Here, we have to enter the desired count value.&lt;br /&gt;
&lt;br /&gt;
We will enter 3 as the count value.&lt;br /&gt;
&lt;br /&gt;
Click on the '''OK''' button.&lt;br /&gt;
&lt;br /&gt;
Note that the name is prefixed by '''C''' by default.&lt;br /&gt;
|- &lt;br /&gt;
|| &lt;br /&gt;
|| We will now check the working of this '''logic'''.&lt;br /&gt;
|- &lt;br /&gt;
|| Click Simulate -&amp;gt; Simulation mode &amp;gt;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Click Simulate -&amp;gt; Real-time simulation&lt;br /&gt;
|| Let us turn '''on''' the '''simulation mode'''.&lt;br /&gt;
&lt;br /&gt;
For that, click '''Simulate''' and then on '''Simulation mode.'''&lt;br /&gt;
&lt;br /&gt;
Next, start '''real-time simulation''' as shown.&lt;br /&gt;
|- &lt;br /&gt;
|| Highlight the state of Xswitch, YLED and Ccount in the I/O list&lt;br /&gt;
|| We can observe initially the states of '''Xswitch''', '''YLED''' and '''Ccount''' are 0.&lt;br /&gt;
|- &lt;br /&gt;
|| Double click on Xswitch in the I/O list&lt;br /&gt;
|| Double click on the '''Xswitch to '''change its state to 1.&lt;br /&gt;
|- &lt;br /&gt;
|| Highlight the state of Ccount and YLED&lt;br /&gt;
|| We can observe the state of the '''counter Ccount''' changes to 1.&lt;br /&gt;
&lt;br /&gt;
But, the state of '''YLED''' is still 0.&lt;br /&gt;
|- &lt;br /&gt;
|| Double click on Xswitch&lt;br /&gt;
|| Now, change the state of '''Xswitch''' back to 0.&lt;br /&gt;
|- &lt;br /&gt;
|| Highlight the state of Ccount&lt;br /&gt;
|| We can observe the state of '''Ccount''' is still 1.&lt;br /&gt;
|- &lt;br /&gt;
|| &lt;br /&gt;
|| That is the '''counter''' value updates only with the rising edge of its input.&lt;br /&gt;
|- &lt;br /&gt;
|| Double click on Xswitch for 3 times&lt;br /&gt;
|| Change the state of '''Xswitch''' from 0 to 1 for a couple more times.&lt;br /&gt;
|- &lt;br /&gt;
|| Highlight the state of Ccount&lt;br /&gt;
|| After 3 low to high transitions of '''Xswitch''', the state of '''Ccount''' reaches 3.&lt;br /&gt;
|- &lt;br /&gt;
|| Highlight the state of YLED&lt;br /&gt;
|| We can now observe the state of '''YLED''' changes to 1.&lt;br /&gt;
|- &lt;br /&gt;
|| Double click on Xswitch for 2 times&lt;br /&gt;
|| Change the state of '''Xswitch''' to 0.&lt;br /&gt;
&lt;br /&gt;
Again change it back to 1.&lt;br /&gt;
|- &lt;br /&gt;
|| Highlight the state of YLED&lt;br /&gt;
|| The state of '''Ccount''' changes to 4.&lt;br /&gt;
&lt;br /&gt;
We can observe that the state of '''YLED''' is still 1.&lt;br /&gt;
|- &lt;br /&gt;
|| &lt;br /&gt;
|| Once the '''counter''' reaches desired count value, its output will always be 1.&lt;br /&gt;
&lt;br /&gt;
This is because of the '''condition &amp;gt;= 3''' in the '''CTU''' instruction.&lt;br /&gt;
|- &lt;br /&gt;
|| Click Simulate -&amp;gt; Halt Simulation &amp;gt;&amp;gt; Click Simulate -&amp;gt; Simulation Mode&lt;br /&gt;
|| Now, turn '''off''' the '''simulation mode'''.&lt;br /&gt;
&lt;br /&gt;
For that, click '''Simulate''' and then on '''Halt Simulation.'''&lt;br /&gt;
&lt;br /&gt;
Then click '''Simulate''' and '''Simulation Mode.'''&lt;br /&gt;
|- &lt;br /&gt;
|| &lt;br /&gt;
|| Now let us '''compile''' the '''logic'''.&lt;br /&gt;
&lt;br /&gt;
The detailed steps on how to '''compile''' and save the '''logic''' are explained in the earlier tutorials.&lt;br /&gt;
|- &lt;br /&gt;
|| Click on Settings &amp;gt;&amp;gt; Click on Microcontroller &amp;gt;&amp;gt; Select AVR ATmega16 40-PDIP &lt;br /&gt;
&lt;br /&gt;
Click on Settings &amp;gt;&amp;gt; Click on MCU parameters &amp;gt;&amp;gt; Change Crystal frequency to 16&lt;br /&gt;
|| Click on '''Settings''' and select the '''microcontroller AVR ATmega16 40-PDIP.''' &lt;br /&gt;
&lt;br /&gt;
Adjust its '''parameters''' as shown here.&lt;br /&gt;
|- &lt;br /&gt;
|| Double-click on Xswitch in I/O list &amp;gt;&amp;gt; Select PC0 &amp;gt;&amp;gt; Click OK button&lt;br /&gt;
&lt;br /&gt;
Double-click on YLED in I/O list &amp;gt;&amp;gt; Select PA0 &amp;gt;&amp;gt; Click OK button&lt;br /&gt;
|| Assign '''pin PC0''' to '''Xswitch '''and '''PA0''' to '''YLED'''.&lt;br /&gt;
|- &lt;br /&gt;
|| Click on Compile &amp;gt;&amp;gt; Click on Compile &amp;gt;&amp;gt; Go to Desktop/LDmicro folder &amp;gt;&amp;gt; Rename it as ‘ctu.hex’ &amp;gt;&amp;gt; Click on Save.&lt;br /&gt;
&lt;br /&gt;
Click '''OK''' button&lt;br /&gt;
|| '''Compile''' the '''logic''' as '''ctu.hex.'''&lt;br /&gt;
|- &lt;br /&gt;
|| Click on File &amp;gt;&amp;gt; Click on Save &amp;gt;&amp;gt; Go to Desktop/LDmicro folder &amp;gt;&amp;gt; Rename it as ‘ctu.ld’ &amp;gt;&amp;gt; Click on Save&lt;br /&gt;
|| Then save the '''ladder diagram''' as '''ctu.ld.'''&lt;br /&gt;
|- &lt;br /&gt;
|| &lt;br /&gt;
|| We will now see the working of this '''logic''' on hardware.&lt;br /&gt;
|- &lt;br /&gt;
|| Connect Mainboard to PC using USBasp&lt;br /&gt;
&lt;br /&gt;
laptop-usbasp.jpg&lt;br /&gt;
&lt;br /&gt;
|| Connect the '''Mainboard''' to your laptop using '''USBasp'''.&lt;br /&gt;
&lt;br /&gt;
Turn '''on''' the '''power supply'''.&lt;br /&gt;
|- &lt;br /&gt;
|| Open terminal &amp;gt;&amp;gt; Type cd Desktop/LDmicro &amp;gt;&amp;gt; Press ENTER &amp;gt;&amp;gt; type ‘'''avrdude -c usbasp -p m16 -U flash:w:ctu.hex’ '''&amp;gt;&amp;gt; Press ENTER&lt;br /&gt;
|| Open the '''Terminal''' by pressing '''CTRL+ALT+T''' keys simultaneously.&lt;br /&gt;
&lt;br /&gt;
Go to the folder where you have saved the '''hex file'''.&lt;br /&gt;
&lt;br /&gt;
Type the '''command''' as shown to upload the '''hex file''' to the '''Mainboard'''.&lt;br /&gt;
|- &lt;br /&gt;
|| Remove the '''USBasp''' connection from the laptop.&lt;br /&gt;
|| Turn '''off''' the '''power supply'''.&lt;br /&gt;
&lt;br /&gt;
Remove the '''USBasp''' connection from the laptop.&lt;br /&gt;
&lt;br /&gt;
This will prevent any hardware damage.&lt;br /&gt;
|- &lt;br /&gt;
|| ctu.png&lt;br /&gt;
|| Let us see the connection details now. &lt;br /&gt;
|- &lt;br /&gt;
|| ctu.png to show all the connections as per the narration&lt;br /&gt;
|| Connect '''GND pin''' of the red '''LED''' of '''Traffic Light''' module to '''GND''' of the '''Mainboard'''.&lt;br /&gt;
&lt;br /&gt;
Then connect '''+5V pin''' of red '''LED''' to '''PA0 pin''' of the '''Mainboard'''.&lt;br /&gt;
|- &lt;br /&gt;
|| ctu.png to show all the connections as per the narration&lt;br /&gt;
|| Connect '''GND''' and '''5V''' of '''switchboard''' to '''GND''' and '''5V''' of the '''Mainboard''' respectively.&lt;br /&gt;
&lt;br /&gt;
Then connect '''NO1''' of the '''Switchboard''' to '''PC0''' of the '''Mainboard'''.&lt;br /&gt;
&lt;br /&gt;
Make the connections as shown in the picture.&lt;br /&gt;
|- &lt;br /&gt;
|| Turn on the power&lt;br /&gt;
|| After making all the connections properly, turn '''on''' the '''power supply'''.&lt;br /&gt;
|- &lt;br /&gt;
|| Red '''LED''' doesn't glow&lt;br /&gt;
|| Initially the red '''LED''' will not glow.&lt;br /&gt;
|- &lt;br /&gt;
|| Press switch '''NO1''' thrice&lt;br /&gt;
|| It will glow only when the switch''' NO1''' is pressed for at least three times.&lt;br /&gt;
&lt;br /&gt;
So, press the switch''' NO1''' for 3 times.&lt;br /&gt;
|- &lt;br /&gt;
|| '''LED''' glows&lt;br /&gt;
|| We can see the '''LED''' will be glowing even after the '''NO1''' is released.&lt;br /&gt;
|- &lt;br /&gt;
|| Turn off the power.&lt;br /&gt;
|| Turn '''off''' the '''power supply'''.&lt;br /&gt;
|- &lt;br /&gt;
|| Slide 6: Resetting CTU&lt;br /&gt;
&lt;br /&gt;
CTU counters can be reset using RES instruction&lt;br /&gt;
|| In order to turn '''off''' the '''LED''' we need to '''reset''' the '''counter'''.&lt;br /&gt;
&lt;br /&gt;
It can be done by using a '''RESET''' instruction as learnt in the '''RTO''' tutorial.&lt;br /&gt;
|- &lt;br /&gt;
|| &lt;br /&gt;
|| This brings us to the end of this tutorial.&lt;br /&gt;
&lt;br /&gt;
Let us summarize.&lt;br /&gt;
|- &lt;br /&gt;
|| Slide 7: Summary&lt;br /&gt;
* Count up (CTU) counter&lt;br /&gt;
|| In this tutorial we learnt about working of '''Count up counter'''.&lt;br /&gt;
|- &lt;br /&gt;
|| Slide 8: Assignment&lt;br /&gt;
* Draw a ladder diagram to turn on an LED when the switch is pressed for &amp;gt;= 5 times.&lt;br /&gt;
* Include logic to reset the LED.&lt;br /&gt;
&lt;br /&gt;
Hint: Use another Contact and RES instruction&lt;br /&gt;
|| As an assignment do the following:&lt;br /&gt;
&lt;br /&gt;
# 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.&lt;br /&gt;
# Include '''logic''' to '''reset''' the '''LED'''.&lt;br /&gt;
&lt;br /&gt;
Hint: Use another '''Contact''' and '''RES''' instruction.&lt;br /&gt;
|- &lt;br /&gt;
|| Slide 9:&lt;br /&gt;
&lt;br /&gt;
About Spoken Tutorial project&lt;br /&gt;
|| The video at the following link summarises the Spoken Tutorial project.&lt;br /&gt;
&lt;br /&gt;
Please download and watch it&lt;br /&gt;
|- &lt;br /&gt;
|| Slide 10:&lt;br /&gt;
&lt;br /&gt;
Spoken Tutorial workshops&lt;br /&gt;
|| The''' Spoken Tutorial Project''' team:&lt;br /&gt;
* conducts workshops using spoken tutorials and&lt;br /&gt;
* gives certificates on passing online tests.&lt;br /&gt;
&lt;br /&gt;
For more details, please write to us&lt;br /&gt;
|- &lt;br /&gt;
|| Slide 11:&lt;br /&gt;
&lt;br /&gt;
Forum for specific questions:&lt;br /&gt;
|| Please post your timed queries in this forum&lt;br /&gt;
|- &lt;br /&gt;
|| Slide 12:&lt;br /&gt;
&lt;br /&gt;
Forum for specific questions:&lt;br /&gt;
|| Do you have any general / technical questions on OpenPLC?&lt;br /&gt;
&lt;br /&gt;
Please visit the FOSSEE forum and post your question.&lt;br /&gt;
|- &lt;br /&gt;
|| Slide 13:&lt;br /&gt;
&lt;br /&gt;
Acknowledgement&lt;br /&gt;
|| Spoken Tutorial Project is funded by MHRD, Government of India.&lt;br /&gt;
|- &lt;br /&gt;
|| Slide 14:&lt;br /&gt;
&lt;br /&gt;
Thank you slide&lt;br /&gt;
|| This tutorial has been contributed by FOSSEE and Spoken Tutorial Project, IIT Bombay.&lt;br /&gt;
&lt;br /&gt;
And this is Harsha Priyanka from FOSSEE team, signing off.&lt;br /&gt;
&lt;br /&gt;
Thanks for watching.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Nirmala Venkat</name></author>	</entry>

	</feed>