Presentation is loading. Please wait.

Presentation is loading. Please wait.

Pulse Width Modulation Instructor Dr Matthew Khi Yi Kyaw.

Similar presentations


Presentation on theme: "Pulse Width Modulation Instructor Dr Matthew Khi Yi Kyaw."— Presentation transcript:

1 Pulse Width Modulation Instructor Dr Matthew Khi Yi Kyaw

2 What is square wave? Pattern of a digital output What is a duty cycle? The duration of on time What is Pulse Width Modulation(PWM) Pulse width is varied rapidly to produce an effect of varying analog voltage signal an analog signal is modulating over a digital signal

3 PWM Frequency and Timers pin 3,5,6,9,10,and 11 can be configured as (PWM) outputs. 6 analog channel Pins 3 and 11 are paired on timer2 The base frequencies for pins 3, 9,10 and 11 is 31250Hz. The divisor available on pins 3 and 11 are: 1,8,32,64,128,256,an1024 with selection mode 0x01,0x02,0x03,0x04,0x05,0x06,and 0x07 respectively. The default mode for timer 2 is 0x04 i.e is divisor 64. Thus the Frequency of PWM is 488.28125Hz.

4 Hardware Arudino UNO R3 Proto board Jumpers Light Emitting Diode(LED) Resistor(470Ώ) Program

5 1.Circuit Diagram

6 Software int ledPin=3; int sensorPin=A0; int delay_value=0; void setup(){ } void loop() { for (int fadeValue =0 ; fadeValue <=255; fadeValue +=5){ analogWrite(ledPin,fadeValue); delay_value=analogRead (sensorPin); delay(delay_value); } for (int fadeValue =255 ; fadeValue>=0; fadeValue -=5){ analogWrite (ledPin, fadeValue); delay_value = analogRead(sensorPin); delay (delay_value); }

7 Serial Port Serial port is used for serial communication to interface the signal from one device to another. The serial port uses RS232 standard.

8 2.Circuit Diagram of Serial Port

9 char val; const int ledPin=13; void setup(){ pinMode (ledPin,OUTPUT); Serial.begin(9600); } void loop( ){ int sensorValue = analogRead(A0); if (Serial.available()) { val= Serial.read(); } if (val=='H') { digitalWrite(ledPin, HIGH); float voltage =sensorValue*(5.0/1023.0); Serial.println(voltage); } else { digitalWrite(ledPin, LOW); Serial.println(" Press H to start reading the Voltage"); }

10 2. Homework Write a program to give a delay to the PWM using input from serial-port instead of analog input.

11 References. http://arduino.cc.. http://arduino.cc/en/Main/ArduinoBoardUno.. http://arduino.cc/en/Guide/Introduction.. www.atmel.com/Images/doc8161.pdf.. "Arduino Programming Notebook" by - by Brian W. Evans.. Beginning Android ADK with Arduino by Mario Bohmer. http://arduino.cc/en/Tutorial/Button. http://arduino.cc/en/Tutorial/Blink. http://arduino.cc/en/uploads/Main/arduino_Uno_Rev3-02-TH.zip.. http://arduino.cc/en/uploads/Main/Arduino_Uno_Rev3- schematic.pdf.. http://arduino.cc/en/Main/ArduinoBoardUno.. http://playground.arduino.cc/Code/PwmFrequency. http://playground.arduino.cc/Main/TimerPWMCheatsheet 6

12


Download ppt "Pulse Width Modulation Instructor Dr Matthew Khi Yi Kyaw."

Similar presentations


Ads by Google