EMS1EP Lecture 8 Pulse Width Modulation (PWM)

Slides:



Advertisements
Similar presentations
Sensing and Control.
Advertisements

EMS1EP Lecture 6 Digital Inputs
EMS1EP Lecture 5 Digital Outputs Dr. Robert Ross.
EMS1EP Lecture 4 Intro to Programming Dr. Robert Ross.
EMS1EP Lecture 1 Intro to Arduino Dr. Robert Ross.
EMS1EP Lecture 9 Analog to Digital Conversion (ADC) Dr. Robert Ross.
Lab7: Introduction to Arduino
Servo Background Servos provide control of rotary position Servos are used extensively in the remote control hobby world for: Aircraft (flaps, ailerons,
Anurag Dwivedi & Rudra Pratap Suman.  Open Source electronic prototyping platform based on flexible easy to use hardware and software.
What is Arduino?  Arduino is a ATMEL 168 micro-controller kit designed specially for small projects  User friendly IDE(Integrated Development Environment)
Servos The material presented is taken from a variety of sources including:
Re-programming the Simon Says with Arduino Linz Craig, Brian Huang.
Khaled A. Al-Utaibi  Digital Vs Analog Signals  Converting an Analog Signal to a Digital One  Reading Analog Sensors with the.
Introduction to Arduino Programming January MER-421:Mechatronic System Design.
L.
Living with the Lab Using servos with an Arduino EAS 199A Fall 2011.
Secret Door Knock Detector
SENIOR DESIGN 10/16.
Introduction.
Microprocessors Tutorial 2: Arduino Robotics
Embedded Programming and Robotics Lesson 2 C Programming Refresher C Programming1.
Physics 120B: Lecture 2 Topics and Techniques for Week 1 Lab.
Introduction to Arduino Prepared by R. Lamond.  “Arduino is an open-source electronics prototyping platform based on flexible, easy- to-use hardware.
Basic Circuits – Lab 2 Arduino and Sensors Xmedia Spring 2011.
1 Servo Motor. 2 Overview A servo motor is a motor that is only capable of rotating 180 degrees A servo motor is controlled by giving it an angle to proceed.
Dean Brock, Rebecca Bruce and Susan Reiser, CCSC SE 2009 Using Arduino Material taken from Todbot blog Bionic Arduino Todbot blog Bionic ArduinoTodbot.
Microcontroller Hands-on Workshop #3 Ahmad Manshad New Mexico State University Institute of Electrical and Electronics Engineers November 7, 2009.
ProtoSnap Introduction to Arduino Casey Haskell, Pete Lewis, David Stillman, Jim Lindblom, Pete Dokter, Lindsay Levkoff, Trevor Zylstra.
Arduino Week 2 Lab ECE 1020 Prof. Ahmadi. Objectives 1. Control the rotation of standard servo motor  A standard servo motor is limited in its rotation.
Lecture 15: Digital to Analog Converters Lecturers: Professor John Devlin Mr Robert Ross.
Pulse Width Modulation (PWM). 100% Pulse Width Modulation (PWM) 0% On the chipKIT there are 490 periods per second. Use analogWrite(pin, value) to control.
Servos The material presented is taken from a variety of sources including:
BM-305 Mikrodenetleyiciler Güz 2015 (3. Sunu) (Yrd. Doç. Dr. Deniz Dal)
Microprocessors Tutorial 2: Arduino Robotics. Agenda 1. Robot Anatomy 2. Sensor Review 3. PWM 4. MAKE: Fade 5. Motors 6. H Bridge 7. Robot Control library.
1 - Remove LED from 13 and GND - Bring out your breadboard from HW#4 Arduino Overview:
Microcontroller Hands-on Workshop #2 Ahmad Manshad New Mexico State University Institute of Electrical and Electronics Engineers October 31, 2009.
Rebecca Bruce and Susan Reiser, May 2015 Analog Input and Output.
INTERNET OF EVERYTHING SDU 2016 Week 4. Simple Digital and Analog Inputs  The Arduino’s ability to sense digital and analog inputs allows it to respond.
PWM: Pulse Width Modulation © 2014 Project Lead The Way, Inc.Digital Electronics.
[Lab10] Output PWM  Output PWM Signal  Example  Exercise(Optional)
Throttle Arduino RC Receiver Stock Golf Cart Motor Controller Motor 1 PWM signal: Voltage: 0 – 5V Period = 22ms Positive Pulse Width: 1ms – 2ms Digital.
Closed Loop Temperature Control Circuit with LCD Display Mike Wooldridge ECE 4330 Embedded Systems.
Microcontroller basics Embedded systems for mortals.
Servo Motor Control Using Arduino Instructor: Dr Matthew Khin Yi Kyaw.
Istituto Tecnico Industriale A.Monaco EURLAB Moving a robot simple example program to control a DC-Motor Next - Press the button (left)
Istituto Tecnico Industriale A.Monaco EURLAB Control a Servo Motor If you want to swing an robot arm or … steer a robot you need a special motor (Servo).
Pulse-Width Modulation: Simulating variable DC output
Microcontroller basics Embedded systems for mortals.
Pulse Width Modulation Instructor Dr Matthew Khi Yi Kyaw.
1 Microcontrollers. 2 Programmers work in the virtual world Machinery works in the physical world Microcontrollers connect the virtual and physical world.
BM-305 Mikrodenetleyiciler Güz 2016 (3. Sunu)
Introduction to Motors, servos and steppers
Outline Introduction to digital-to-analog converter (DAC)
Microcontroller basics
If you want to swing an robot arm or …
Microprocessors Tutorial 1: Arduino Basics
Arduino - Introduction
BM-305 Mikrodenetleyiciler Güz 2017 (3. Sunu)
Analog Input through POT
Introduction to Arduinos
IoT Programming the Particle Photon.
CBC Fundamentals Lecture is based on material from Robotic Explorations: A Hands-on Introduction to Engineering, Fred Martin, Prentice Hall, 2001.
Secret Door Knock Detector
Arduino : Introduction & Programming
Sensors and actuators Sensors Resistive sensors
UNIT 11: RC-SERVOMOTOR CONTROL
UNIT 5 Analog signals.
Introduction to Arduinos
Pulse-Width Modulation: Simulating variable DC output
Servo Motor.
Presentation transcript:

EMS1EP Lecture 8 Pulse Width Modulation (PWM) Dr. Robert Ross

Overview (what you should learn today) Analog v’s digital Theory behind PWM PWM sample circuit/Demo Worked examples Servo Control

Digital Revision – Analog/Digital Analog Voltages: Continuous in time and value Digital Voltages: Discrete in time and value

Analog/Digital The real world is analog Most things we measure or control can be described my continuous values Pressure, temperature, acceleration, sound, light Computers are digital Need to convert these analog voltages as digital values

Analog/Digital ADC DAC Control Physical Variable Physical Variable Digital Voltages Control Physical Variable (Sound, light, pressure, temp, ect) ADC Analog to Digital Converter Microcontroller (LArduino) DAC Digital to Analog Converter Physical Variable (Sound, light, pressure, temp, ect) Transducer (Sensor) Actuator Analog Voltages

ADC and DAC Analog to Digital Converters (ADCs) are used to convert the analog voltages into a digital value Digital to Analog Converters (DACs) are used to generate analog voltages using digital values The LArduino board has internal ADCs and has pins which can be configured as analog outputs using Pulse Width Modulation

Quantisation The analog values produced by a DAC look analog but are actually quantised values (not continuous) These values are in small steps The LArduino has 256 steps (0-255) over the range 0-5V 19.6mV Steps (5V/255=0.0196) To improve resolution: Lower the voltage range (0-3V) Increase the number of bits: 8Bits = 255 Steps 16Bits = 65535 Steps

PWM Characteristics Create a square-wave Constant period Varying duty cycle (proportional to required analog voltage) 5V 0V

Generating Analog Voltages analogWrite(pin, 0); 0% Duty cycle - Average Voltage: 0V 5V 0V analogWrite(pin, 63); 25% Duty cycle - Average Voltage: 1.25V 5V 0V analogWrite(pin, 127); 50% Duty cycle - Average Voltage: 2.5V 5V 0V analogWrite(pin, 191); 75% Duty cycle - Average Voltage: 3.75V 5V 0V analogWrite(pin, 255); 100% Duty cycle - Average Voltage: 5V

Filtering PWM Signal Without filtering circuitry With filtering circuitry:

Pulse Width Modulation (PWM) Use: analogWrite(pin, <AnalogVoltage>); AnalogVoltage can vary from 0-255 Will toggle the pin really fast high and low – to produce something more like an analog voltage need to smooth this out Use a Low Pass Filter to smooth the voltage out to approximate an analog voltage

PWM Applications Communication – length of pulse specifies 1’s and 0’s Voltage Regulation LED brightness control Controlling the speed of motors Servo control

PWM on the LArduino PWM can be performed on any of the pins marked with a ‘P’ Use pins 5, 6, 9, 10, 11 Pins used for PWM don’t need to be setup – analogWrite does this automatically

Class Challenge Write some code to do the following: A switch is connected to Pin 8 A LED is connected to Pin 6 If the button is pressed the LED should be at 75% brightness If the button is not pressed the LED should be at 25% brightness

Worked example – Sawtooth signal Create a sawtooth signal on Pin 5 When connected to an LED the LED should successively fade brighter and dimmer When connected to a scope should give output (when connected to filter):

Sawtooth - Code int PWMOUT1 = 5; // PIN ASSIGNMENTS void setup() { //PWM pins don't require initialisation } void loop() { int onTime = 0; while(onTime < 255){ onTime++; analogWrite(PWMOUT1, onTime); delay(10); while(onTime > 0){ onTime--;

Sawtooth - Results No Filtering (Value increased and then decreased) LED connected – goes brighter then dimmer

Servo Control Remote control aircraft (and some robotics) are operated using servos

Servo Control Servos need to be attached to pin 9 or 10 on the LArduino board Servos are controlled using a PWM signal Period: 20ms On time: 1.25 to 1.75ms On time sets the position of the servo arm

Servo Control: Hardware connections Red – Power (4-6V) Black (or Brown) – GND Yellow (or White or Orange) – PWM signal pin Arduino 5V

Servo Worked Example If button on Pin 5 is pressed servo to go to 30O If button is not pressed servo to go to 120O Servo connected to Pin 9 Using Arduino Servo library Allows desired angle of servo to be specified

Servo Worked Example #include <Servo.h> Servo servo1; // create servo object to control a servo int button1 = 5; void setup() { servo1.attach(9); // Servo on Pin 9 pinMode(button1, INPUT); } void loop() if (digitalRead(button1) == LOW){ //Button pressed servo1.write(30); else{ //Button not pressed servo1.write(120);

Continuous Rotation Servos By default servo motors only have about 180O of motion that they can travel over Servos can be modified for continuous rotation (they can go right around) PWM signal controls speed not position of continuous rotation servos Involves: Removing feedback potentiometer (variable resistor) Soldering in resistors Cutting notch out of gears

Summary (What you learnt in this session) The real world is analog, but our microcontrollers are digital PWM is one type of DAC to generate analog like voltages from a microcontroller Use analogWrite() to set PWM value Servos use PWM to set the position of the servo arm – can use the servo library