power
play

Power Recall (or learn) that Power is a measure of: - PowerPoint PPT Presentation

17.1 17.2 Power Recall (or learn) that Power is a measure of: _____________________________________ EE 109 Unit 17 - Pulse Width In an electronic circuit, P = ______________ Power = Current & Voltage (each may be


  1. 17.1 17.2 Power • Recall (or learn) that Power is a measure of: – _____________________________________ EE 109 Unit 17 - Pulse Width • In an electronic circuit, P = ______________ – Power = Current & Voltage (each may be ______________ w/ time) Modulation • A circuit that draws a constant 2 mA of current at a constant 5V 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 5V Average Power .5s .3s I = 1A = _______________ 0V 17.3 17.4 Output Devices Duty Cycle • A pulse is just a short window of time when a signal is 'on' • What do the following have in common? – Servo motor that can rotate to any angle w/in 180 degrees • We could repeat the pulse at some regular period, T – ____________________ • We define the duty cycle as – ___________________________ with various power levels Duty Cycle % = _________________________ • They are controlled by Pulse Width Modulation (PWM) T T T T – Usually a 3-pin interface: Power (Vcc), GND, PWM Signal 5V T/2 Duty Cycle = ____% 0V T 5V Duty Cycle = ____% 0V T/4

  2. 17.5 17.6 Power & Duty Cycle In-Class Activity • When we light up an LED we 5V • Write a program with a loop that turns on the LED often just turn a PORTxx output (PORT B5) for x milliseconds and then turns it off for 'on' and leave it 'on' 0V 100-x milliseconds – This supplies the ____________ PORTxx 'on' constantly power possible to the LED – Initially set x = 100 � ������ • We could _________ the output ������ – Now set x = 50 �� at some duty cycle (say 50%) at a �� ��� ��� � – Now set x = 20 �� fast rate – Now set x = 10 – Fast so that the human eye can't – Now set x = 2 ___________________ – Average power would be ½ the T T • Notice result may be non-linear original always 'on' power 5V • A similar tactic is used in your _______________ T/2 – Result would be a _____________ __________________ when you want to cook something at __________ 0V etc. power. PORTxx 'on' 50% of time 17.7 17.8 PWM Simple Digital-To-Analog • Modulation refers to _____________ a value based on some • Connecting a PWM output to a resistor-capacitor circuit ___________ (i.e. changing one signal based on another) as shown causes the voltage at Vc to "integrate" the • Pulse width modulation refers to modifying the width of a digital PWM signal (charge the capacitor) pulse based on another signal – Analogy: Imagine you have a leaky bucket (i.e. capacitor) and • It can be used to _______________ one signal into another you want to produce a variable level (i.e. _______________) of – Example below of water by only turning the hose (___________ output) on or off sine wave represented as pulses w/ different 5V widths V PWM • Or it can just be used 0V to alter average power 5V as in the last activity V c 0V

  3. 17.9 17.10 Servo Motors Standard Servo Motor • Pulse width determines ________________ of servo motor • Many embedded systems use servo • Must continue to give pulses for the duration of time it takes motors to move or rotate mechanical to ________________________________________ devices • No pulses = _____________ • Most servo motors use some form of 20 ms 20 ms Full left pulse width modulation to control the direction and speed of their rotation Pulse width = 750us Centered 20 ms 20 ms Do an Internet search • 2 Kinds for Standard Servo Motors & try to find – ____________ servo motors: can only rotate the appropriate pulse Pulse width = 1500us width for each through a certain _____ (usually 180 position Full right 20 ms 20 ms degrees) – _______________: can keep spinning round and round while pulses are provided Pulse width = 2250us 17.11 17.12 Continuous Servo Motors Implementing PWM • Pulse width determines ________________ of • Can use delays or timers to make your own pulse rotation signals • Controlled via PWM (Pulse Width Modulation) • Most microcontrollers have hardware to – Short pulse = Rotate one direction automatically generate PWM signals based on the – Medium pulse = Stop contents of some control registers – Long pulse = Rotate other direction • Many microcontrollers use the Timers to also serve as PWM signals – Recall the timer module gave us a counter that would 20 ms 20 ms increment until it hit some 'modulus' (MAX) count which 20 ms would cause it to restart and also generate an interrupt Pulse Width = _______ us = Pulse Width = ________ us = Pulse Width = ________ us = Full Speed Clockwise Stopped Full Speed Counter- Clockwise

  4. 17.13 17.14 Using Timers for PWM PWM Control Registers • For PWM we can use that counter to just count 0 to some • In this slide packet we will use the 8-bit Timer/Counter0 rather MAX count making the: than the 16-bit Timer/Counter1 – PWM output = '1' while the count < threshold (OCRxx) and • Refer to Timer Slides w/ following additions – PWM output = '0' when the count >= modulus (OCRxx) • Set WGM0[2:0] bits for Fast PWM mode as opposed to CTC time time MAX MAX • Timer/Counter0 can produce two PWM outputs on Arduino pins (255) (255) D5 and D6, each with its own threshold value, so you need to pick OCRxA which one you want to use OCRxB – Bits COM0A[1:0] and threshold register OCRA control operation of output D6 (PORTD6) 0 0 – Bits COM0B[1:0] and threshold register OCRB control operation of output D5 (PORTD5) See datasheet, textbook or other documentation for further explanation PWM Output 1 PWM Output 2 17.15 17.16 PWM Control Registers Exercise • Set WGM bits for PWM mode [usually COM0 COM0 COM0 COM0 - - WGM WGM A1 A0 B1 B0 01 00 Fast PWM mode] as opposed to CTC • Try to use PWM to make your LED glow at TCCR0A Reg. • Pick COM0?[1:0] for desired waveform various brightness levels similar to what you Timer/Counter0 Control Register • Still need to pick a prescaler to slow down the clock did earlier with normal digital I/O FOC FOC - - WGM CS02 CS01 CS00 0A 0B 02 • Set OCRA or OCRB to the desired threshold which will effectively control TCCR0B Reg. Timer/Counter0 Control Register the duty cycle of the PWM output WGM01, WGM02=0 WGM02=1 CS0 Prescaler COM0?1, Output Compare pin COM0?0 (assume WGM02=0) WGM00 (Ignore ) [2:0] 00 Normal Unused 010 Clk / 8 00 Don't use Pin (Counter) 01 Don't use Pin 011 Clk / 64 01 Phase Phase Correct Correct PWM PWM 100 Clk / 256 10 Set Pin on CTR=0x00, Clear (Top=OCRA) pin on match=OCR? 101 Clk / 1024 10 CTC (Timer) Unused 11 Clear Pin on CTR=0x00, Set pin on match=OCR? 11 Fast PWM Fast PWM (Top=255) (Top=OCRA)

  5. 17.17 17.18 A Few Big Ideas 1 • _________________________ 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 Review of some key concepts from the first half of the semester and give the illusion it's always on but just more dim revisit what CECS prepares you to do in the future…. – Or it can work to your disadvantage: One button press may look like A BRIEF SUMMARY __________ because a loop may see one press on multiple iterations. – We must write our software with this in mind 17.19 17.20 A Few Big Ideas 2 A Few Big Ideas 3 • Clocking or enables are necessary to say ________ • External events happen __________________ with your – Digital signals are always 1's and 0's so just looking at the software (don't know "when" something has happened) bits doesn't tell us how many we have – Your software program is the brains for how to process – We usually need ____________ (pulses) to tell the information but it doesn't magically know "when" something hardware when we want it to grab the data 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 Just looking at this set of digital values, – A 0.1 second timer can be done in SW using delays but then are we sending 0101 once, twice, three times, how many? Once because we use the clock/enable to indicate that. software can't do much else But without the clock we'd have no clue how many times we are trying to write – Or in HW using timers allowing SW to do other tasks 0101

Recommend


More recommend