21.07.2013 Views

Introduction to Microcontrollers Lab Manual - Microchip

Introduction to Microcontrollers Lab Manual - Microchip

Introduction to Microcontrollers Lab Manual - 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.

LABS<br />

FIGURE 7-2: USING PWM TO CREATE A SINE WAVE<br />

7.2.3 Output Compare Blocks<br />

The PIC24FJ256GB110 has 9 Output Compare Blocks. Each of these blocks can be<br />

configured as any of the following:<br />

• Center-Aligned PWM mode<br />

• Edge-Aligned PWM Mode<br />

• Double Compare Continuous Pulse mode<br />

• Double Compare Single-Shot mode<br />

• Single Compare mode<br />

• Single Compare Single-Shot mode<br />

In PWM mode, the output compare module can be configured for edge-aligned or center-aligned<br />

pulse waveform generation. All PWM operations are double-buffered (buffer<br />

registers are internal <strong>to</strong> the module and are not mapped in<strong>to</strong> SFR space).<br />

To configure the output compare module for PWM operation:<br />

1. Configure the OCx output for one of the available Peripheral Pin Select pins.<br />

2. Calculate the desired duty cycles and load them in<strong>to</strong> the OCxR register.<br />

3. Calculate the desired period and load it in<strong>to</strong> the OCxRS register.<br />

4. Select the current OCx as the sync source by writing 0x1F <strong>to</strong> SYNCSEL<br />

(OCxCON2), and clearing OCTRIG (OCxCON2).<br />

5. Select a clock source by writing the OCTSEL (OCxCON) bits.<br />

6. Enable interrupts, if required, for the timer and output compare modules. The<br />

output compare interrupt is required for PWM Fault pin utilization.<br />

7. Select the desired PWM mode in the OCM (OCxCON1) bits.<br />

8. If a timer is selected as a clock source, set the TMRy prescale value and enable<br />

the time base by setting the TON (TxCON) bit.<br />

This peripheral contains input and output functions that may need <strong>to</strong> be configured by<br />

the Peripheral Pin Select.<br />

Registers associated with the Output Compare Block when used as a PWM module:<br />

• OCxCON1: Output Compare x Control Register 1<br />

• OCxCON2: Output Compare x Control Register 2<br />

• OCxR: Compare Register<br />

• OCxRS: Secondary Compare Register<br />

DS51963A-page 52 2011 <strong>Microchip</strong> Technology Inc.

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

Saved successfully!

Ooh no, something went wrong!