<?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-version1-with-LDmicro%2FC3%2FPWM-Instruction%2FEnglish</id>
		<title>OpenPLC-version1-with-LDmicro/C3/PWM-Instruction/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-version1-with-LDmicro%2FC3%2FPWM-Instruction%2FEnglish"/>
		<link rel="alternate" type="text/html" href="https://script.spoken-tutorial.org/index.php?title=OpenPLC-version1-with-LDmicro/C3/PWM-Instruction/English&amp;action=history"/>
		<updated>2026-05-13T15:05:33Z</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-version1-with-LDmicro/C3/PWM-Instruction/English&amp;diff=54708&amp;oldid=prev</id>
		<title>Nancyvarkey at 10:07, 14 January 2021</title>
		<link rel="alternate" type="text/html" href="https://script.spoken-tutorial.org/index.php?title=OpenPLC-version1-with-LDmicro/C3/PWM-Instruction/English&amp;diff=54708&amp;oldid=prev"/>
				<updated>2021-01-14T10:07:35Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;a href=&quot;https://script.spoken-tutorial.org/index.php?title=OpenPLC-version1-with-LDmicro/C3/PWM-Instruction/English&amp;amp;diff=54708&amp;amp;oldid=54620&quot;&gt;Show changes&lt;/a&gt;</summary>
		<author><name>Nancyvarkey</name></author>	</entry>

	<entry>
		<id>https://script.spoken-tutorial.org/index.php?title=OpenPLC-version1-with-LDmicro/C3/PWM-Instruction/English&amp;diff=54620&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 '''PWM Instruction''' |-  || Slide 2:...&quot;</title>
		<link rel="alternate" type="text/html" href="https://script.spoken-tutorial.org/index.php?title=OpenPLC-version1-with-LDmicro/C3/PWM-Instruction/English&amp;diff=54620&amp;oldid=prev"/>
				<updated>2020-12-29T08:33:46Z</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;PWM Instruction&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 '''PWM Instruction'''&lt;br /&gt;
|- &lt;br /&gt;
|| Slide 2: &lt;br /&gt;
&lt;br /&gt;
Learning Objectives&lt;br /&gt;
* PWM (Pulse Width Modulation) instruction&lt;br /&gt;
&lt;br /&gt;
|| &lt;br /&gt;
&lt;br /&gt;
In this tutorial we’ll learn about working of &lt;br /&gt;
* Pulse Width Modulation instruction&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 V1 Mainboard&lt;br /&gt;
* 24V, 2A SMPS&lt;br /&gt;
* USBasp programmer&lt;br /&gt;
* Heater 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 version 1 Mainboard'''&lt;br /&gt;
* '''24V, 2A SMPS'''&lt;br /&gt;
* '''USBasp programmer'''&lt;br /&gt;
* '''Heater module'''&lt;br /&gt;
|- &lt;br /&gt;
|| Slide 4: Pre-requisites&lt;br /&gt;
* Heater module&lt;br /&gt;
* Working of '''Move''' instruction.&lt;br /&gt;
&lt;br /&gt;
If not, please refer to the relevant tutorials from [https://spoken-tutorial.org/ Home | spoken-tutorial.org]&lt;br /&gt;
|| To follow this tutorial, you should know about&lt;br /&gt;
* Heater module and&lt;br /&gt;
* Working of '''Move''' instruction.&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;
|| 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 6a: PWM instruction&lt;br /&gt;
* Can set the duty cycle of the PWM peripheral built into certain microcontrollers&lt;br /&gt;
* Duty cycle must be a number between 0 and 100&lt;br /&gt;
&lt;br /&gt;
|| This sets the duty cycle of the PWM peripheral built into certain microcontrollers.&lt;br /&gt;
&lt;br /&gt;
Duty cycle must be a number between 0 and 100.&lt;br /&gt;
|- &lt;br /&gt;
|| Slide 6b: PWM instruction&lt;br /&gt;
* PWM frequency specified might not be exactly achievable.&lt;br /&gt;
* It depends on microcontroller's clock frequency&lt;br /&gt;
&lt;br /&gt;
|| We can specify the '''PWM''' frequency in '''Hertz'''.&lt;br /&gt;
&lt;br /&gt;
The frequency specified might not be exactly achievable.&lt;br /&gt;
&lt;br /&gt;
It depends on how it divides into the microcontroller's clock frequency.&lt;br /&gt;
|- &lt;br /&gt;
|| Show image of heater module&lt;br /&gt;
|| Here, we will create a logic to control the speed of a fan using '''PWM'''. &lt;br /&gt;
&lt;br /&gt;
We will use the fan in the Heater module.&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; Place the cursor to the right of the contact &amp;gt;&amp;gt; Click Instructions -&amp;gt; Insert MOV &lt;br /&gt;
|| Insert a '''Contact'''.&lt;br /&gt;
&lt;br /&gt;
Place the cursor to the right of the Contact and insert a '''Move''' instruction.&lt;br /&gt;
|- &lt;br /&gt;
|| Double-click on Xnew &amp;gt;&amp;gt; Type switch1 in the name box &amp;gt;&amp;gt; Click the OK button&lt;br /&gt;
|| Rename the '''Contact''' as '''‘switch1’'''.&lt;br /&gt;
|- &lt;br /&gt;
|| Double-click on the MOV &amp;gt;&amp;gt; Set Destination to dc &amp;gt;&amp;gt; Set Source to 20 &amp;gt;&amp;gt; Click the OK button&lt;br /&gt;
|| In the move instruction set the variable dc to 20.&lt;br /&gt;
&lt;br /&gt;
Click on the OK button.&lt;br /&gt;
|- &lt;br /&gt;
|| Click Edit -&amp;gt; Insert rung below &amp;gt;&amp;gt; Click Edit -&amp;gt; Insert rung below&lt;br /&gt;
|| Now, insert a rung below the current rung.&lt;br /&gt;
|- &lt;br /&gt;
|| For both the rungs&lt;br /&gt;
&lt;br /&gt;
Click Instructions -&amp;gt; Insert Contact &amp;gt;&amp;gt; Place the cursor to the right of the contact &amp;gt;&amp;gt; Click Instructions -&amp;gt; Insert MOV &lt;br /&gt;
|| In the new rung insert a '''Contact''' and a '''Move''' instruction as shown.&lt;br /&gt;
|- &lt;br /&gt;
|| Double-click on Xnew &amp;gt;&amp;gt; Type switch2 in the name box &amp;gt;&amp;gt; Click the OK button&lt;br /&gt;
&lt;br /&gt;
Double-click on the MOV &amp;gt;&amp;gt; Set Destination to dc &amp;gt;&amp;gt; Set Source to 60 &amp;gt;&amp;gt; Click the OK button&lt;br /&gt;
|| Rename the '''Contact''' as '''‘switch2’'''.&lt;br /&gt;
&lt;br /&gt;
In the '''Move''' instruction set the variable dc to 60.&lt;br /&gt;
|- &lt;br /&gt;
|| Click Edit -&amp;gt; Insert rung below &amp;gt;&amp;gt; Place the cursor in the new rung &lt;br /&gt;
|| Insert one more rung below.&lt;br /&gt;
&lt;br /&gt;
|- &lt;br /&gt;
|| Insert Instructions -&amp;gt; Analog Operations -&amp;gt; Insert Set PWM output&lt;br /&gt;
|| Now, insert a '''PWM''' instruction from '''‘Analog Operations’''' as shown here.&lt;br /&gt;
|- &lt;br /&gt;
|| Double-click on PWM &lt;br /&gt;
|| Double-click on it.&lt;br /&gt;
|- &lt;br /&gt;
|| Highlight two columns&lt;br /&gt;
|| We can find two columns.&lt;br /&gt;
|- &lt;br /&gt;
|| Highlight Duty cycle variable &lt;br /&gt;
&lt;br /&gt;
Type dc &lt;br /&gt;
|| First one is the duty cycle variable.&lt;br /&gt;
&lt;br /&gt;
Set it to variable ‘'''dc’'''.&lt;br /&gt;
|- &lt;br /&gt;
|| Highlight Frequency&lt;br /&gt;
|| Second is Frequency in '''Hertz'''.&lt;br /&gt;
&lt;br /&gt;
By default, it is set to 1kHz i.e. 1000Hz. &lt;br /&gt;
&lt;br /&gt;
Do not change it.&lt;br /&gt;
|- &lt;br /&gt;
|| Click the OK button&lt;br /&gt;
|| Click the '''OK''' button.&lt;br /&gt;
|- &lt;br /&gt;
|| Highlight dc type in the I/O list&lt;br /&gt;
|| In the I/O list we can see the variable '''‘dc’''' is of type '''PWM out.'''&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 state column in the IO list&lt;br /&gt;
|| We can observe initially the states of all the instructions are 0.&lt;br /&gt;
|- &lt;br /&gt;
|| Double click on Xswitch1 &lt;br /&gt;
|| Change the state of '''Xswitch1''' to 1 by double-clicking on it.&lt;br /&gt;
|- &lt;br /&gt;
|| Highlight the value of dc&lt;br /&gt;
|| The variable '''dc''' is set to 20.&lt;br /&gt;
|- &lt;br /&gt;
|| &lt;br /&gt;
&lt;br /&gt;
Highlight the value of dc&lt;br /&gt;
&lt;br /&gt;
|| The '''dc''' variable value is set as the duty cycle of the PWM peripheral.&lt;br /&gt;
&lt;br /&gt;
This happens when the input condition of PWM instruction is true.&lt;br /&gt;
&lt;br /&gt;
In our case, it is true as the PWM instruction is connected to the positive rail.&lt;br /&gt;
|- &lt;br /&gt;
|| Double click on Xswitch1 &lt;br /&gt;
|| Change the state of '''Xswitch1''' back to 0.&lt;br /&gt;
|- &lt;br /&gt;
|| Double click on Xswitch2 &lt;br /&gt;
&lt;br /&gt;
Highlight the value of dc&lt;br /&gt;
&lt;br /&gt;
Double click on Xswitch2&lt;br /&gt;
|| Similarly, when '''Xswitch2''' state is 1 the duty cycle will be set to 60.&lt;br /&gt;
|- &lt;br /&gt;
|| &lt;br /&gt;
|| Make sure that at a time only one of the Contacts has its state 1.&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;
|| 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;
|| Highlight ‘dc’ in the I/O list&lt;br /&gt;
|| We can see that variable '''dc''' is already assigned pin number 21, which is '''PD7'''.&lt;br /&gt;
&lt;br /&gt;
This is the PWM pin for '''ATMega16''' microcontroller.&lt;br /&gt;
|- &lt;br /&gt;
|| Double-click on Xswitch1 in I/O list &amp;gt;&amp;gt; Select PC7 &amp;gt;&amp;gt; Click OK button&lt;br /&gt;
&lt;br /&gt;
Double-click on Xswitch2 in I/O list &amp;gt;&amp;gt; Select PC6 &amp;gt;&amp;gt; Click OK button&lt;br /&gt;
|| Now assign '''PC0''' to '''Xswitch1 '''and '''PC1''' to '''Xswitch2''' as shown.&lt;br /&gt;
&lt;br /&gt;
|- &lt;br /&gt;
|| Click on Compile &amp;gt;&amp;gt; Click on Compile &amp;gt;&amp;gt; rename it as ‘pwm.hex’ &amp;gt;&amp;gt; Go to Desktop/LDmicro folder &amp;gt;&amp;gt; Click on Save.&lt;br /&gt;
&lt;br /&gt;
Click OK button&lt;br /&gt;
|| Compile the logic as''' pwm.hex'''&lt;br /&gt;
|- &lt;br /&gt;
|| Click on File &amp;gt;&amp;gt; Click on Save &amp;gt;&amp;gt; Rename it as ‘pwm.ld’ &amp;gt;&amp;gt; Go to Desktop/LDmicro folder &amp;gt;&amp;gt; Click on Save&lt;br /&gt;
|| Save the ladder diagram as '''pwm.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:pwm.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;
|| pwm.png&lt;br /&gt;
|| Let us see the connection details now. &lt;br /&gt;
|- &lt;br /&gt;
|| pwm.png&lt;br /&gt;
|| Power the''' Heater module''' through relimate connectors from the '''Mainboard'''.&lt;br /&gt;
&lt;br /&gt;
Connect '''PD7''' to the fan pin of the '''MCU''' pins of the '''Heater module.'''&lt;br /&gt;
|- &lt;br /&gt;
|| pwm.png&lt;br /&gt;
|| Connect '''GND''' and 5V of the '''Switchboard''' to '''GND''' and 5V of the '''Mainboard''' respectively.&lt;br /&gt;
&lt;br /&gt;
Then connect '''NO1''' to '''PC0''' and '''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;
|| &lt;br /&gt;
|| After making all the connections properly, turn on the power supply.&lt;br /&gt;
|- &lt;br /&gt;
|| &lt;br /&gt;
|| Initially the fan will be off as the duty cycle is 0.&lt;br /&gt;
&lt;br /&gt;
The '''FANon''' LED on the Heater module would be glowing dim.&lt;br /&gt;
&lt;br /&gt;
Press the switch '''NO1'''.&lt;br /&gt;
&lt;br /&gt;
We can observe the fan is turned ON.&lt;br /&gt;
&lt;br /&gt;
The duty cycle is 20 here.&lt;br /&gt;
|- &lt;br /&gt;
|| &lt;br /&gt;
|| Now press the switch '''NO2'''.&lt;br /&gt;
&lt;br /&gt;
We can observe the speed of the fan is increasing comparatively.&lt;br /&gt;
&lt;br /&gt;
This is because of the increase in the duty cycle to 60.&lt;br /&gt;
|- &lt;br /&gt;
|| &lt;br /&gt;
|| Thus we have controlled the speed of the fan using '''PWM'''.&lt;br /&gt;
|- &lt;br /&gt;
|| &lt;br /&gt;
|| Turn off the power supply.&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 8: Summary&lt;br /&gt;
* PWM instruction&lt;br /&gt;
&lt;br /&gt;
|| In this tutorial we learnt about working of * PWM instruction&lt;br /&gt;
&lt;br /&gt;
|- &lt;br /&gt;
|| Slide 9:&lt;br /&gt;
&lt;br /&gt;
Assignment: &lt;br /&gt;
&lt;br /&gt;
|| As an assignment,&lt;br /&gt;
&lt;br /&gt;
Control the brightness of the red LED of Traffic Light module.&lt;br /&gt;
&lt;br /&gt;
Hints: Replace fan of Heater module with red LED of Traffic light module.&lt;br /&gt;
Connect PD7 pin to +5V pin of the red LED of the Traffic Light module.&lt;br /&gt;
|- &lt;br /&gt;
|| Slide 10:&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 11:&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;
|- &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>