chap12_timers_pwm

chap12_timers_pwm - Timers Recall that a timer on a C is...

Info iconThis preview shows pages 1–14. Sign up to view the full content.

View Full Document Right Arrow Icon
V 0.7 1 Timers • Recall that a timer on a μ C is simply a counter Basic equations that we have used: General: Time = Ticks * Clock period of counter Ticks = Time/Clock period of counter PIC24 specific: Time = Ticks * 1/FCY * timer_prescale Ticks = Time * FCY/timer_prescale
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
V 0.7 2 Period Register Recall that the timer period register controls the amount of time for setting the TxIF flag (controls the Timer roll-over time): TxIF period = (PRx + 1) * 1/FCY * Prescale To generate a periodic interrupt of Y milliseconds, we have done: PR x = msToU16Ticks( Y , getTimerPrescale(T x CONbits)) – 1; The msToU16Ticks function converts Y milliseconds to Timer ticks, the decrement by 1 is needed because rollover time is PR x + 1.
Background image of page 2
V 0.7 3 Input Capture, Output Compare Modules • The Input Compare and Output compare modules are peripherals that use Timer2, Timer3 for time- related functions • The Output compare module can generate pulses of a specified pulse width and period • The Input compare module is used for measuring pulse width and period (elapsed time)
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
V 0.7 4 Output Compare Module Pulses are generated are OCx pin. The PIC24HJ32GP202 has two Output compare modules (OC1, OC2). The OC x RS, OC x R registers control when the output pin is affected by comparing against either Timer2 or Timer3 values.
Background image of page 4
V 0.7 5 Output Compare Modes
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
V 0.7 6 Generating a Square Wave using Toggle Mode Steps (assume using Timer2, and OC1) a. Configure Timer2 for a period that greater than ½ period of the square wave. b. Init OC1R register OC1R = TimerTicks_onehalfSquareWavePeriod c. Each match of OC1R register generates OC1 interrupt, toggles OC1 pin. d. In OC1 ISR, assign new OC1R register value as: OC1R = OC1R + TimerTicks_onehalfSquareWavePeriod
Background image of page 6
V 0.7 7 Toggle Mode, OC1 square wave
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
V 0.7 8 Pulse Width Modulation (PWM) High pulse width varies (i.e., duty cycle varies) period is fixed Current to LED is proportional to high pulse width
Background image of page 8
V 0.7 9 LED PWM Code
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
V 0.7 10 LED PWM Code main() While(1) loop just prints debugging information, work is actually done by Timer2 ISR that updates pulse width from ADC converted value.
Background image of page 10
V 0.7 11 DC Motor Speed Control
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
V 0.7 12 Half-bridge Driver Integrates MOSFET/BJT drivers, protection diodes, switches.
Background image of page 12
V 0.7
Background image of page 13

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 14
This is the end of the preview. Sign up to access the rest of the document.

This document was uploaded on 09/15/2009.

Page1 / 46

chap12_timers_pwm - Timers Recall that a timer on a C is...

This preview shows document pages 1 - 14. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online