10.07.2015 Views

pic24fj128ga010 family - Microchip

pic24fj128ga010 family - Microchip

pic24fj128ga010 family - Microchip

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

PIC24FJ128GA010 FAMILY13.4 Pulse-Width Modulation ModeThe following steps should be taken when configuringthe output compare module for PWM operation:1. Set the PWM period by writing to the selectedTimer Period register (PRy).2. Set the PWM duty cycle by writing to the OCxRSregister.3. Write the OCxR register with the initial dutycycle.4. Enable interrupts, if required, for the timer andoutput compare modules. The output compareinterrupt is required for PWM Fault pinutilization.5. Configure the output compare module for one oftwo PWM operation modes by writing to theOutput Compare mode bits OCM(OCxCON).6. Set the TMRy prescale value and enable thetime base by setting TON (TxCON) = 1.Note:The OCxR register should be initializedbefore the output compare module is firstenabled. The OCxR register becomes aRead-Only Duty Cycle register when themodule is operated in the PWM modes.The value held in OCxR will become thePWM duty cycle for the first PWM period.The contents of the Duty Cycle Bufferregister, OCxRS, will not be transferredinto OCxR until a time base period matchoccurs.13.4.1 PWM PERIODThe PWM period is specified by writing to PRy, theTimer Period register. The PWM period can becalculated using Equation 13-1.EQUATION 13-1:Note:CALCULATING THE PWMPERIOD (1)PWM Period = [(PRy) + 1] • TCY • (Timer Prescale Value)where:PWM Frequency = 1/[PWM Period]Note 1:Based on TCY = TOSC * 2, Doze mode andPLL are disabled.A PRy value of N will produce a PWMperiod of N + 1 time base count cycles. Forexample, a value of 7 written into the PRyregister will yield a period consisting of8 time base cycles.13.4.2 PWM DUTY CYCLEThe PWM duty cycle is specified by writing to theOCxRS register. The OCxRS register can be written toat any time, but the duty cycle value is not latched intoOCxR until a match between PRy and TMRy occurs(i.e., the period is complete). This provides a doublebuffer for the PWM duty cycle and is essential for glitchlessPWM operation. In the PWM mode, OCxR is aread-only register.Some important boundary parameters of the PWM dutycycle include:• If the Duty Cycle register, OCxR, is loaded with0000h, the OCx pin will remain low (0% duty cycle).• If OCxR is greater than PRy (Timer Period register),the pin will remain high (100% duty cycle).• If OCxR is equal to PRy, the OCx pin will be lowfor one time base count value and high for allother count values.See Example 13-1 for PWM mode timing details.Table 13-1 shows example PWM frequencies andresolutions for a device operating at 10 MIPS.EQUATION 13-2: CALCULATION FOR MAXIMUM PWM RESOLUTION (1)Maximum PWM Resolution (bits) =FCY( )log 10FPWM • (Timer Prescale Value)log 10 (2)bitsNote 1:Based on FCY = FOSC/2, Doze mode and PLL are disabled.© 2009 <strong>Microchip</strong> Technology Inc. DS39747E-page 117

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!