<?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%2FCTD-Counter%2FEnglish</id>
		<title>OpenPLC-with-LDmicro/C3/CTD-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%2FCTD-Counter%2FEnglish"/>
		<link rel="alternate" type="text/html" href="https://script.spoken-tutorial.org/index.php?title=OpenPLC-with-LDmicro/C3/CTD-Counter/English&amp;action=history"/>
		<updated>2026-05-13T20:22:21Z</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/CTD-Counter/English&amp;diff=55352&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 '''CTD Counter'''. |-  || Slide 2:...&quot;</title>
		<link rel="alternate" type="text/html" href="https://script.spoken-tutorial.org/index.php?title=OpenPLC-with-LDmicro/C3/CTD-Counter/English&amp;diff=55352&amp;oldid=prev"/>
				<updated>2021-07-14T10:57:58Z</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;CTD Counter&amp;#039;&amp;#039;&amp;#039;. |-  || Slide 2:...&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 '''CTD Counter'''.&lt;br /&gt;
|- &lt;br /&gt;
|| Slide 2: &lt;br /&gt;
&lt;br /&gt;
Learning Objectives&lt;br /&gt;
* Count down (CTD) counter&lt;br /&gt;
|| &lt;br /&gt;
&lt;br /&gt;
In this tutorial we’ll learn about working of '''Count down counter'''.&lt;br /&gt;
|- &lt;br /&gt;
|| Slide 3:&lt;br /&gt;
&lt;br /&gt;
System Requirements&lt;br /&gt;
* Ubuntu 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&lt;br /&gt;
* Switchboard module&lt;br /&gt;
|| &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;
|| Slide 4: Pre-requisites&lt;br /&gt;
* Working of '''CTU''' and '''Compare''' 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;
# '''CTU '''and&lt;br /&gt;
# '''Compare''' instruction.&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;
|| &lt;br /&gt;
|| We will create an '''up-down counter''' to understand the working of '''CTD'''.&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 on Instructions -&amp;gt; Insert Contact &amp;gt;&amp;gt; Place the cursor to the right of Xnew &amp;gt;&amp;gt; Click on 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 ‘up’ in the name box &amp;gt;&amp;gt; Click the OK button&lt;br /&gt;
|| Rename the '''Contact''' as '''‘up’'''.&lt;br /&gt;
&lt;br /&gt;
|- &lt;br /&gt;
|| Place the cursor below Xup &amp;gt;&amp;gt; Click on Instructions -&amp;gt; Insert Contact&lt;br /&gt;
|| Now insert a '''Contact''' parallel to '''Xup'''.&lt;br /&gt;
&lt;br /&gt;
Rename the new '''Contact''' as '''‘down’'''.&lt;br /&gt;
|- &lt;br /&gt;
|| Place the cursor to the right of Xup &amp;gt;&amp;gt; Click Instructions -&amp;gt; Counters -&amp;gt; Insert CTU&lt;br /&gt;
|| To the right of '''Xup''' insert a '''CTU '''as shown here.&lt;br /&gt;
|- &lt;br /&gt;
|| Double-click the Cnew &amp;gt;&amp;gt; Type count in the name column &amp;gt;&amp;gt; Click the OK button&lt;br /&gt;
|| Double click on '''CTU'''.&lt;br /&gt;
&lt;br /&gt;
Rename the '''CTU''' as '''‘count’. '''&lt;br /&gt;
&lt;br /&gt;
The '''condition''' value is by default 0.&lt;br /&gt;
&lt;br /&gt;
Don’t change it. &lt;br /&gt;
|- &lt;br /&gt;
|| Place the cursor to the right of Xdown &amp;gt;&amp;gt; Click Instructions -&amp;gt; Counters -&amp;gt; Insert CTD&lt;br /&gt;
|| To the right of '''Xdown''' insert a '''CTD '''as shown here.&lt;br /&gt;
|- &lt;br /&gt;
|| Double-click the Cnew &amp;gt;&amp;gt; Type count in the name column &amp;gt;&amp;gt; Click the OK button&lt;br /&gt;
|| Double click on '''CTD'''.&lt;br /&gt;
&lt;br /&gt;
Just like '''CTU''' it has two columns, '''‘Name’''' and '''‘True if &amp;gt;=’'''.&lt;br /&gt;
&lt;br /&gt;
Rename the '''CTD''' as '''‘count’.''' &lt;br /&gt;
&lt;br /&gt;
The '''condition''' value is by default 0.&lt;br /&gt;
&lt;br /&gt;
Don’t change it.&lt;br /&gt;
|- &lt;br /&gt;
|| Double-click on Ynew &amp;gt;&amp;gt; Select Internal Relay &amp;gt;&amp;gt; Type relay in the name box &amp;gt;&amp;gt; Click the OK button&lt;br /&gt;
|| Now configure the '''Coil''' as '''Internal Relay''' and rename it as '''‘relay’'''.&lt;br /&gt;
|- &lt;br /&gt;
|| &lt;br /&gt;
|| This is because here we don't need any physical output from '''CTU''' and '''CTD'''.&lt;br /&gt;
|- &lt;br /&gt;
|| Click Edit -&amp;gt; Insert Rung below&lt;br /&gt;
|| Now place a '''rung''' below as shown here.&lt;br /&gt;
|- &lt;br /&gt;
|| Place the cursor in the new rung &amp;gt;&amp;gt; Click on Instructions -&amp;gt; Comparison operators -&amp;gt; Insert GEQ&lt;br /&gt;
|| In the new '''rung''' insert a greater than or equal to '''Compare''' instruction.&lt;br /&gt;
|- &lt;br /&gt;
|| Double-click on greater than or equal to Compare instruction &amp;gt;&amp;gt; Type Ccount in the ‘Closed’ if: column &amp;gt;&amp;gt; Type 3 in the &amp;gt;= column&lt;br /&gt;
|| Double-click on the '''Compare''' instruction.&lt;br /&gt;
&lt;br /&gt;
Compare '''Ccount variable''' with 3.&lt;br /&gt;
&lt;br /&gt;
That is in the '''Closed if''' column enter '''Ccount'''.&lt;br /&gt;
&lt;br /&gt;
In the '''&amp;gt;= (greater than or equals to)''' column enter 3.&lt;br /&gt;
&lt;br /&gt;
Click on the '''OK''' button.&lt;br /&gt;
|- &lt;br /&gt;
|| Place the cursor to the right of Compare instruction &amp;gt;&amp;gt; Click on Instructions -&amp;gt; Insert Coil&lt;br /&gt;
|| Now to the right of it, insert a '''Coil'''.&lt;br /&gt;
|- &lt;br /&gt;
|| Double click on Ynew &amp;gt;&amp;gt; Type LED in the name column&lt;br /&gt;
|| Rename it as '''‘LED’'''.&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 states of all the instructions in the IO list&lt;br /&gt;
|| We can observe initially that the state of every instruction is 0 except for '''Rrelay'''.&lt;br /&gt;
|- &lt;br /&gt;
|| Double click on Xup &lt;br /&gt;
|| Double click on '''Xup''' to change its state to 1.&lt;br /&gt;
|- &lt;br /&gt;
|| Highlight the state of Ccount&lt;br /&gt;
|| We can observe the state of the '''Ccount''' changes to 1.&lt;br /&gt;
|- &lt;br /&gt;
|| Highlight the state of Ccount&lt;br /&gt;
|| Keep changing the state of '''Xup '''by double clicking on it until '''Ccount''' value reaches 3.&lt;br /&gt;
|- &lt;br /&gt;
|| Highlight the state of YLED&lt;br /&gt;
|| We can observe the state of '''YLED''' changes to 1.&lt;br /&gt;
|- &lt;br /&gt;
|| &lt;br /&gt;
|| Just like in the '''CTU''' example.&lt;br /&gt;
|- &lt;br /&gt;
|| Double click on Xdown &lt;br /&gt;
|| Now change the state of '''Xdown''' to 1.&lt;br /&gt;
|- &lt;br /&gt;
|| Highlight the state of Ccount&lt;br /&gt;
|| We can observe the '''Ccount''' value changes to 2.&lt;br /&gt;
&lt;br /&gt;
That is decreased by 1.&lt;br /&gt;
|- &lt;br /&gt;
|| Highlight the state of YLED&lt;br /&gt;
|| Also, the state of '''YLED''' goes back to 0.&lt;br /&gt;
&lt;br /&gt;
The state of '''YLED''' will be 1 only when '''Ccount''' value is '''&amp;gt;= (greater than or equals to)''' 3.&lt;br /&gt;
|- &lt;br /&gt;
|| Double click on Xdown &lt;br /&gt;
|| Change the state of '''Xdown''' back to 0.&lt;br /&gt;
|- &lt;br /&gt;
|| Highlight the state of Ccount&lt;br /&gt;
|| The value of '''Ccount''' is still 2.&lt;br /&gt;
|- &lt;br /&gt;
|| Highlight the state of Ccount&lt;br /&gt;
|| The '''CTD''' decreases the count value by 1 only with the rising edge of its '''input'''.&lt;br /&gt;
|- &lt;br /&gt;
|| &lt;br /&gt;
|| Thus the working of '''CTU''' and '''CTD''' is similar.&lt;br /&gt;
&lt;br /&gt;
The only difference is '''CTD''' decrements the '''counter''' value.&lt;br /&gt;
|- &lt;br /&gt;
|| &lt;br /&gt;
|| We can also reset the '''CTD''' using '''RESET''' 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 '''Xup '''and '''PC1''' to '''Xdown'''.&lt;br /&gt;
&lt;br /&gt;
Assign '''pin 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 ‘ctd.hex’ &amp;gt;&amp;gt; Click on Save.&lt;br /&gt;
&lt;br /&gt;
Click OK button&lt;br /&gt;
|| '''Compile''' the '''logic''' as '''ctd.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 ‘ctd.ld’ &amp;gt;&amp;gt; Click on Save&lt;br /&gt;
|| Then save the '''ladder diagram''' as '''ctd.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:ctd.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;
|| Turn off the power supply &amp;gt;&amp;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;
|| ctd.png&lt;br /&gt;
|| Let us see the connection details now. &lt;br /&gt;
|- &lt;br /&gt;
|| ctd.png &amp;gt;&amp;gt; point 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 the '''+5V pin''' of the red '''LED''' to '''PA0''' pin of the '''Mainboard'''.&lt;br /&gt;
|- &lt;br /&gt;
|| ctd.png &amp;gt;&amp;gt; point 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;
Connect '''NO1''' to '''PC0''' of the '''Mainboard'''.&lt;br /&gt;
&lt;br /&gt;
Then connect '''NO2''' to '''PC1''' 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 supply&lt;br /&gt;
|| After making all the connections properly, turn '''on''' the '''power supply'''.&lt;br /&gt;
|- &lt;br /&gt;
|| Point to red LED&lt;br /&gt;
|| Initially the red '''LED''' will not glow.&lt;br /&gt;
|- &lt;br /&gt;
|| Press NO1 three times to make it glow&lt;br /&gt;
|| It will glow only when '''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;
|| &lt;br /&gt;
|| Now the '''count''' value is 3.&lt;br /&gt;
|- &lt;br /&gt;
|| Press the switch NO2 &amp;gt;&amp;gt; LED turns off&lt;br /&gt;
&lt;br /&gt;
Turn off the power supply&lt;br /&gt;
|| Press the switch '''NO2'''.&lt;br /&gt;
&lt;br /&gt;
The '''count''' value becomes 2 and the '''LED''' will turn '''off'''.&lt;br /&gt;
&lt;br /&gt;
Thus '''CTD''' decreases the '''count''' value by 1 after every switch press.&lt;br /&gt;
&lt;br /&gt;
Turn '''off''' the '''power supply'''.&lt;br /&gt;
|- &lt;br /&gt;
|| Slide : Where can an up-down counter be used?&lt;br /&gt;
* The up-down counter can be used when we need to count finished products.&lt;br /&gt;
* CTU will increment the count value when a product is finished. &lt;br /&gt;
* CTD will decrement the count of products that fail the quality test.&lt;br /&gt;
&lt;br /&gt;
|| Where can an '''up-down counter''' be used?&lt;br /&gt;
&lt;br /&gt;
The '''up-down counter''' can be used when we need to count the finished products.&lt;br /&gt;
&lt;br /&gt;
'''CTU''' will increment the '''count''' value when a product is finished. &lt;br /&gt;
&lt;br /&gt;
'''CTD''' will decrement the count of products that fail the quality test.&lt;br /&gt;
&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 5: Summary&lt;br /&gt;
* Count down (CTD) counter&lt;br /&gt;
&lt;br /&gt;
|| In this tutorial we learnt about working of '''Count down counter'''.&lt;br /&gt;
|- &lt;br /&gt;
|| Slide 6:&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 7:&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 8:&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;
|- &lt;br /&gt;
|| Slide 19:&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 10:&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 11:&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>