Pulse Width Modulation (PWM)

Slides:



Advertisements
Similar presentations
INVERTERS (DC-AC Converters).
Advertisements

SHIFT REGISTERS: CONVERTING BETWEEN SERIAL AND PARALLEL DATA Mark Neil - Microprocessor Course 1 Serial versus Parallel Data Transfers.
Logic Families.
SPI Serial Peripheral Interface. SPI Serial Peripheral Interface is communication between two devices, one bit at a time sequential one bit at time over.
Lecture 8: Serial Interfaces
Guitar Effects Processor Critical Design Review October, 07, 2003 Groups Members: Adam Bernstein Hosam Ghaith Jasenko Alagic Matthew Iyer Yousef Alyousef.
Serial Peripheral Interface (SPI)
SPISPI Term Dr Abdelhafid Bouhraoua Term Dr Abdelhafid Bouhraoua.
Discovery Lab School of Computing & Information System Florida International University.
SPI By Alexander Maroudis. Outline What is SPI? SPI Configuration SPI Operation Master Slave Setup SPI Transactions SPI Digital Potentiometer Example.
Microprocessor Block Diagram
Serial Peripheral Interface (SPI) Bus. SPI Bus There is no official specification for the SPI bus. It is necessary to consult the data sheets of the devices.
LSU 10/22/2004Serial I/O1 Programming Unit, Lecture 5.
CRKit RF Control WINLAB – Rutgers University Date : June Authors : Prasanthi Maddala, Khanh Le,
CRKit RF Control WINLAB – Rutgers University Date : June Authors : Prasanthi Maddala, Khanh Le,
4.0 rtos implementation part II
DEVICES AND COMMUNICATION BUSES FOR DEVICES NETWORK–
CRKit RF Control WINLAB – Rutgers University Date : June Authors : Prasanthi Maddala, Khanh Le,
CRKit RF Control WINLAB – Rutgers University Date : June Authors : Prasanthi Maddala, Khanh Le,
AT91 Embedded Peripherals
Chapter 8 Serial and Parallel Port Interfacing Valvano’s Intro. To Embedded Systems.
© 2009 Pearson Education, Upper Saddle River, NJ All Rights ReservedFloyd, Digital Fundamentals, 10 th ed Digital Fundamentals with PLD Programming.
Other Chapters From the text by Valvano: Introduction to Embedded Systems: Interfacing to the Freescale 9S12.
PWM Circuit Based on the 555 Timer. Introduction In applications LED Brightness Control we may want to vary voltage given to it. Most often we use a variable.
OCRP RF Control WINLAB – Rutgers University Date : June Authors : Prasanthi Maddala, Khanh Le,
DsPIC30F4011 Fall DIP Switches  The upper four switches of SW1 are used to enable LEDs connected to PORTB/C, PORTA/D, PORTE and PORTF. For example,
OCRP RF Control WINLAB – Rutgers University Date : June Authors : Prasanthi Maddala, Khanh Le,
Essentials of Communication This simple model requires many guarantees. Sender Receiver Communication Link Data.
Department of Electronic & Electrical Engineering Serial interfaces Serial Interfaces allow communication between devices sending one bit at a time. In.
Serial Peripheral Interface SPI I2C (i-squared cee)
SHIFT REGISTERS: CONVERTING BETWEEN SERIAL AND PARALLEL DATA Mark Neil - Microprocessor Course 1 Serial versus Parallel Data Transfers.
Networked Embedded Systems Sachin Katti & Pengyu Zhang EE107 Spring 2016 Lecture 9 Serial Buses – SPI, I2C.
BIRLA VISHVAKARMA MAHAVIDYALAY SUBJECT: SPI PROTOCOL & MAX7221 DISPLAY INTERFACING SUBMITTED BY: KISHAN AVASTHI( ) MANSI CHANDEGARA( )
میکرو کنترلرهای AVR Serial Interfaces, I2C and SPI
MICROCONTROLLER AND INTERFACING Presented by: Shefali Jethva ( ) Shivali Panchal ( ) Komal Soni ( ) Roll no. :- 14EC308.
©F.M. Rietti Communication Lines Fundamentals. ©F.M. Rietti LM-18 Computer Science SSI Embedded Systems I 2 Communication Lines Generally used to connect.
Application Case Study Christmas Lights Controller
Serial Communication Originally created by Anurag Dwidedi and Rudra Pratap Suman.
Outline Analog to digital conversion (ADC) of NuMaker TRIO
Microcontrollers, Basics Fundamentals of Designing with Microcontrollers 16 January 2012 Jonathan A. Titus.
Serial Communication Buses: I2C and SPI
EI205 Lecture 8 Dianguang Ma Fall 2008.
EE 107 Fall 2017 Lecture 5 Serial Buses – UART & SPI
Chapter 11: Inter-Integrated Circuit (I2C) Interface
Digital Fundamentals Floyd Chapter 1 Digital concepts Tenth Edition
ECE 3430 – Intro to Microcomputer Systems
Chapter D – Serial Connections to the RPi and Analog-to-Digital Converters
1 Input-Output Organization Computer Organization Computer Architectures Lab Peripheral Devices Input-Output Interface Asynchronous Data Transfer Modes.
Inverters Dr John Fletcher.
E3165 DIGITAL ELECTRONIC SYSTEM
Atmega32 Serial Programming Basics
Communication Lines Fundamentals.
BJ Furman ME 106 Fundamentals of Mechatronics 15NOV2012
Introduction to Microprocessors and Microcontrollers
DC Choppers 1 MH1032/brsr/A.Y /pe/DC CHOPPERS
Interrupts, Tasks and Timers
Power Electronic Drives - DC to AC converter / Inverter
Inverters Dr John Fletcher.
Serial Communication Interface: Using 8251
Parallel communication interface 8255
UNIT-8 INVERTERS 11/27/2018.
Acronyms Galore: Wired for Success
Digital Fundamentals Floyd Chapter 1 Tenth Edition
Dr. Unnikrishnan P.C. Professor, EEE
Manual Robotics ..
8253 – PROGRAMMABLE INTERVAL TIMER (PIT). What is a Timer? Timer is a specialized type of device that is used to measure timing intervals. Timers can.
Introduction to Arduino
Integrated Circuits Computer Signals
INVERTERS. What is an Inverter? A static device that converts DC power into AC power at desired output voltage and frequency is called an Inverter. Applications.
Presentation transcript:

Pulse Width Modulation (PWM) Simple method of using rectangular digital waveform to control an analog variable Used in a variety of applications, from communications to automatic control Usually keep period constant, and vary the pulse width, or “on” time The duty cycle is the proportion of time that the pulse is “on”, expressed as a percentage

Pulse Width Modulation (PWM) The average value of the signal will be determined by the duty cycle By controlling the duty cycle, can control the average value If “on” time is small, average value is low; if “on” time is large, average value is higher The average value can be extracted from the PWM signal with a low pass filter – then Vout is an analog output

Pulse Width Modulation (PWM) On the mbed, there are 6 PWM outputs, on pins 21-26 In the lab, you generated various PWM signals. 20% duty cycle 80% duty cycle Can do quite a few other things with PWM………..

Pulse Width Modulation (PWM) Controlling LED brightness by changing PWM duty cycle, controlled from host computer keyboard – also shows the use of host terminal emulator. #include "mbed.h" Serial pc(USBTX, USBRX); //sets up communication with PC PwmOut led(LED1); float brightness=0.0; int pc.printf("Control LED brightness from PC \n\r"); main(){ pc.printf("Press 'u' or 'd' to change brightness while(1){ char c=pc.getc(); wait(0.001); if((c=='u') && (brightness <=1.0)){ brightness+=0.05; led=brightness; } if((c=='d') && (brightness>0)){ brightness-=0.05; led=brightness; pc.printf("%c %1.3f \n \r",c,brightness); \n\r"); }

Pulse Width Modulation (PWM) Controlling stepper motor from a potentiometer Vs #include "mbed.h” AnalogIn A2(p20); float period; float duty; PwmOut PWM(p21); “Freewheeling” Motor coil int main(){ while(1) { period duty = diode Inductance L - cannot get + Resistance R = 0.01; instant change (period * A2); PWM.period(period); PWM.pulsewidth(duty); wait(0.1); in current thru L, so when transistor switches off, current } } has somewhere to go PWM output from mbed MOSFET essentially a switch MOSFET – Metal-Oxide-Semiconductor Field Effect Transistor

Pulse Width Modulation (PWM) Driving a speaker Setting duty cycle to 50%, results in a square wave whose frequency can be varied by changing the PWM period You will learn later that any periodic waveform can be constructed from a combination of sinusoidal signals – Fourier Series Square wave with frequency fo can be synthesised from sinusoidal signals at frequencies nfo, where n is an odd integer (ie n=1,3,5 etc) ie a square wave of frequency fo “contains” sin waves at frequencies fo, 3fo, 5fo etc

Pulse Width Modulation (PWM) Higher “harmonics” of the “fundamental” frequency f0 have lower amplitude, and as a speaker has resistance and capacitance which make it look a bit like a low pass filter, the higher frequency, lower amplitude harmonics are attenuated and so the speaker is effectively driven by something approaching a sin wave at the PWM frequency. By changing the PWM period (and hence frequency) and duration of the PWM signal, we can make sweet(ish) music !

Pulse Width Modulation (PWM) Could of course, just generate PWM from a digital output by switching it on and off, and changing the time for which the digital signal is “high” or “low”, but that would take up the time and effort of the CPU. The advantage of handling over responsibility of the PWM signal generation to the specific peripheral in the microcontroller chip, is that the CPU is then available to do other stuff. This is one of the powerful aspects of a highly functionalised microcontroller – devolving responsibility for things low PWM, D/A and A/D to the peripherals frees up the time of the CPU.

Serial Communication As mentioned before, the mbed has a lot of serial communications capability SPI; I2C, CAN, USB For communicating externally and to control other hardware Lets take a tour around SPI to get a feel for how these types of protocol work. Further details can be found on the mbed website. Serial Peripheral Interface (SPI) bus operates with a master/slave configuration SPI is a synchronous serial data communication protocol

Clock Bit 0 Bit 1 Bit 2 Bit 3 Bit 4 Bit 5 Bit 6 Bit 7 Serial Data Data is synchronised to the clock When there is no data being sent, there is no signal on the clock line Every time the clock pulses, one bit is output by the transmitter and should be read by the receiver The receiver synchronises its reading of the data with an edge of the clock. In the picture above, this is to the rising edge. Parallel Read/write Parallel Read/write SDO SDI SDO – serial data out SDI – serial data in SCLK – serial clock Shift Register Shift Register SDI SDO msb lsb msb lsb SCLK SCLK Clock Master Slave

Each SDO is connected to the lsb of the other shift register (SDI) Parallel Read/write Parallel Read/write SDO SDI SDO – serial data out SDI – serial data in SCLK – serial clock Shift Register Shift Register SDI SDO msb lsb msb lsb SCLK SCLK Clock Master Slave Assume the shift registers in the Master and Slave are 8-bit – each has 8 D-type flip-flops Each register is loaded with a new word via the parallel I/O lines The Master then produces 8 clock pulses. For each clock pulse, data is output from the msb of each register (SDO) Each SDO is connected to the lsb of the other shift register (SDI) As each bit is clocked out of one register, it is clocked into the other. After 8 clock cycles, the word that was in the master shift register as been transferred to the slave shift register, and vice versa.

The SPI protocol uses 4 signals clock (SCLK) master data output/slave data input (MOSI) master data input/slave data output (MISO) slave chip select (CS) – usually active low When multiple slave devices exist, the master must output a unique CS signal for each slave. MOSI

SPI The master device starts an SPI data transfer by doing the following : Configures to SPI clock (SCLK) to be a frequency that the recipient slave device can handle (max is 70 MHz) Sets the chip select line (CS) of the intended recipient to 0 V Starts the clock pulses on SCLK to indicate that that data is to be transferred Simultaneously sends data as consecutive bits on MOSI Number of bits in each data frame can be configured, but is usually between 4 and 16 bits The slave returns data in the same manner on MISO

SPI /* Sets up the a single byte mbed as SPI master, and continuously sends */ #include "mbed.h" SPI ser_port(p11, p12, p13); // mosi, miso, sclk char switch_word ; //word we will send int main() { ser_port.format(8,0); Mode 0 operation ser_port.frequency(1000000); while (1){ switch_word=0xA1; // Setup the SPI for 8 bit // Clock frequency is 1MHz data, //set up word to be transmitted //send switch_word ser_port.write(switch_word); wait_us(50); }

CLK DATA 1 1 1 A 1