17.1 Power 17.2 EE 109 Unit 17 -Pulse Width Modulation Recall (or learn) that Power is a measure of: In an electronic circuit, P = Power = Current & Voltage (each may be w/ time) A circuit that draws a constant 2 ma of current at a constant would consume Since voltage and current may change rapidly, it is often helpful to calculate the average power Just sum the total power and divide by the total time 1 s 1 s I = 1A.5s.3s Average Power = 17.3 17.4 Output Devices What do the following have in common? Servo motor that can rotate to any angle w/in 180 degrees with various power levels hey are controlled by Pulse Width Modulation (PWM) Usually a 3-pin interface: Power (Vcc), GND, PWM Signal Duty Cycle A pulse is just a short window of time when a signal is 'on' We could repeat the pulse at some regular period, We define the duty cycle as Duty Cycle = % Duty Cycle % = /2 Duty Cycle = % /4
17.5 17.6 Power & Duty Cycle In-Class Activity When we light up an LED we often just turn a PORxxoutput 'on' and leave it 'on' his supplies the power possible to the LED We could the output at some duty cycle (say 50%) at a fast rate Fast so that the human eye can't Average power would be ½ the original always 'on' power Result would be a PORXX uc PORxx 'on' constantly Vs /2 i + V1 - R1 + VLED - PORxx 'on' 50% of time Write a program with a loop that turns on the LED (POR B5) for x milliseconds and then turns it off for 100-x milliseconds Initially set x = 100 Now set x = 50 Now set x = 20 Now set x = 10 Now set x = 2 Notice result may be non-linear A similar tactic is used in your when you want to cook something at etc. power. 17.7 17.8 PWM Simple Digital-o-Analog Modulation refers to a value based on some (i.e. changing one signal based on another) Pulse width modulation refers to modifying the width of a pulse based on another signal It can be used to one signal into another Example below of sine wave represented as pulses w/ different widths Or it can just be used to alter average power as in the last activity Connecting a PWM output to a resistor-capacitor circuit as shown causes the voltage at Vcto "integrate" the digital PWM signal (charge the capacitor) Analogy: Imagine you have a leaky bucket (i.e. capacitor) and you want to produce a variable level (i.e. ) of water by only turning the hose ( output) on or off V PWM V c
Servo Motors 17.9 Standard Servo Motor 17.10 Many embedded systems use servo motors to move or rotate mechanical devices Most servo motors use some form of pulse width modulation to control the direction and speed of their rotation 2 Kinds servo motors: can only rotate through a certain (usually 180 degrees) : can keep spinning round and round while pulses are provided Pulse width determines of servo motor Must continue to give pulses for the duration of time it takes to No pulses = Full left Centered Full right 20 ms 20 ms Pulse width = 750us 20 ms 20 ms Pulse width = 1500us 20 ms 20 ms Pulse width = 2250us Do an Internet search for Standard Servo Motors & try to find the appropriate pulse width for each position Continuous Servo Motors Pulse width determines of rotation Controlled via PWM (Pulse Width Modulation) Short pulse = Rotate one direction Medium pulse = Stop Long pulse = Rotate other direction 20 ms 20 ms 20 ms 17.11 Implementing PWM Can use delays or timers to make your own pulse signals Most microcontrollers have hardware to automatically generate PWM signals based on the contents of some control registers Many microcontrollers use the imers to also serve as PWM signals Recall the timer module gave us a counter that would increment until it hit some 'modulus' (MAX) count which would cause it to restart and also generate an interrupt 17.12 Pulse Width = us = Full Speed Clockwise Pulse Width = us = Stopped Pulse Width = us = Full Speed Counter- Clockwise
Using imers for PWM For PWM we can use that counter to just count 0 to some MAX count making the: PWM output = '1' while the count < threshold (OCRxx) and PWM output = '0' when the count >= modulus (OCRxx) MAX (255) OCRxA 0 time MAX (255) OCRxB 0 time 17.13 PWM Control Registers In this slide packet we will use the 8-bit imer/counter0 rather than the 16-bit imer/counter1 Refer to imer Slides w/ following additions Set WGM0[2:0] bits for Fast PWM mode as opposed to CC imer/counter0 can produce two PWM outputs on Arduino pins D5 and D6, each with its own threshold value, so you need to pick which one you want to use Bits A[1:0] and threshold register OCRA control operation of output D6 (PORD6) Bits B[1:0] and threshold register OCRB control operation of output D5 (PORD5) 17.14 PWM Output 1 PWM Output 2 See datasheet, textbook or other documentation for further explanation PWM Control Registers 17.15 Exercise 17.16 Set WGM bits for PWM mode [usually Fast PWM mode] as opposed to CC Pick?[1:0] for desired waveform Still need to pick a prescalerto slow down the clock Set OCRA or OCRB to the desired threshold which will effectively control the duty cycle of the PWM output A1 FOC 0A A0 CCR0A Reg. imer/counter0 Control Register FOC 0B B1 B0 - - WGM 02 - - WGM WGM 01 00 CS02 CS01 CCR0B Reg. imer/counter0 Control Register CS00 ry to use PWM to make your LED glow at various brightness levels similar to what you did earlier with normal digital I/O CS0 [2:0] Prescaler 010 Clk/ 8 011 Clk/ 64 100 Clk/ 256 101 Clk/ 1024?1,?0 Output Compare pin (assume WGM02=0) 00 Don't use Pin 01 Don't use Pin 10 SetPin on CR=0x00, Clear pin on match=ocr? 11 Clear Pin on CR=0x00, Set pin on match=ocr? WGM01, WGM00 WGM02=0 00 Normal (Counter) 01 Phase Correct PWM WGM02=1 (Ignore ) Unused Phase Correct PWM (op=ocra) 10 CC (imer) Unused 11 Fast PWM (op=255) Fast PWM (op=ocra)
17.17 A Few Big Ideas 1 17.18 Review of some key concepts from the first half of the semester and revisit what CECS prepares you to do in the future. A BRIEF SUMMARY bits in a register tells the hardware what do and when (this is SW interacting with HW) matters Your software is executing compared to how fast a human can do something You can use that to your advantage: blinking an LED at a fast rate can give the illusion it's always on but just more dim Or it can work to your disadvantage: One button press may look like because a loop may see one press on multiple iterations. We must write our software with this in mind A Few Big Ideas 2 Clocking or enables are necessary to say Digital signals are always 1's and 0's so just looking at the bits doesn't tell us how many we have We usually need (pulses) to tell the hardware when we want it to grab the data 17.19 Just looking at this set of digital values, are we sending 0101 once, twice, three times, how many? Once because we use the clock/enable to indicate that. But without the clock we'd have no clue how many times we are trying to write 0101 A Few Big Ideas 3 External events happen with your software (don't know "when" something has happened) Your software program is the brains for how to process information but it doesn't magically know "when" something has happened? We have to keep checking it (polling) or Hardware designers built "interrupt" mechanisms to help Many tasks can be done in ; SW may be easier to code/use but HW provides parallelism A 0.1 second timer can be done in SW using delays but then software can't do much else Or in HW using timers allowing SW to do other tasks 17.20
Remember Day 1 Computer engineering prepares you for a broad set of fields You could work in the SW industry You could work in the HW industry You will be most qualified for jobs that combine that knowledge We've been focused on the software/hardware interaction embodied in embedded systems 17.21 Cloud & Distributed Computing (CyberPhysical, Databases, Data Mining,etc.) Applications (AI, Robotics, Graphics, Mobile) Systems & Networking (Embedded Systems, Networks) You Can Do hat What we've been focusing on thus far Architecture (Processor & Embedded HW) Devices & Integrated Circuits (Semiconductors & Fabrication) HW SW Scripting & Interfaces C / C++ / Java Assembly / Machine Code Logic Gates ransistors Networked Applications Applications OS Processor / Memory / I/O 17.22 Libraries Functional Units (Registers, Adders, Muxes) http://www.cmu.edu/news/image-archive/boss.jpg http://prisonerofclass-5933.zippykid.netdna-cdn.com/wp-content/uploads/2013/05/iphone.jpg http://firstcallappliance.com/wp-content/uploads/image/microwave.jpg http://www.amazon.com/fisher-price--m-x-ickle-me-elmo/dp/b000ere0q http://oeatech.net/wp-content/uploads/2011/03/radarsa2-satellite.jpg Voltage / Currents Dive Into a SmartPhone 17.23 What's Inside Your SmartPhone 17.24 Here's a picture of what's inside the iphone M 6 Both sides of the circuit board are populated with chips 2-sided Circuit Board Battery https://d3nevzfk7ii3be.cloudfront.net/igi/6mazk5cee2tm1ucj.huge What's inside an iphone 6? Microcontrollers/microprocessors Apple A8 APL1011 SoC+ Elpida1 GB LPDDR3 RAM SoC= Not just a processor but a processor with custom hardware to do specialized tasks onboard graphics processor in this case NXP LPC18B1UK ARM Cortex-M3 Microcontrollers Similar on-board I/O modules as the. ake a look http://www.nxp.com/products/microcontrollers/cortex_m3/ Modem + Amplifiers + ransceivers for wireless communication Qualcomm MDM9625M LE Modem + many others http://www.techinsights.com/teardown.com/apple-iphone-6/ http://www.techinsights.com/teardown.com/apple-iphone-6/
What's Inside? 17.25 Computer Engineering & HW 17.26 A gyroscope, accelerometer, and touchscreen InvenSenseMP67B 6-axis gyroscope and accelerometer combo Broadcom BCM5976 ouchscreen Controller Both use some form of to sense motion or touch Memory Storage SK Hynix H2JDG8UD1BMS 128 Gb (16 GB) NAND Flash Other specialized HW I/O modules Murata 339S0228 Wi-Fi Module Qualcomm PM8019 power management IC Cirrus Logic 338S1201 audio codec http://www.techinsights.com/teardown.com/apple-iphone-6/ Computer engineering prepares you to work in jobs that design these kinds of systems by: Learning how to design digital circuits using logic gates [AND, OR, NO] (EE 154 and EE 254 Digital System Design) Learning how to optimize processors to execute software as efficiently as possible (EE 457 Computer Architecture) Learn how to assemble many HW pieces (processor cores, RAM, specialized HW) to form systems-on-chip (EE 454L SoCDesign) Learn some of the physics and science of fabricating these designs on silicon (EE 277L and EE 477L VLSI Design) Die Photo of the Apple A8 SoC Processor http://www.anandtech.com/show/8562/chipworks-a8