Microchip dsPIC33EV256GM003 Manual

Microchip Ikke kategoriseret dsPIC33EV256GM003

Læs nedenfor 📖 manual på dansk for Microchip dsPIC33EV256GM003 (130 sider) i kategorien Ikke kategoriseret. Denne guide var nyttig for 11 personer og blev bedømt med 4.5 stjerner i gennemsnit af 2 brugere

Side 1/130
© 2010-2011 Microchip Technology Inc. DS70645C-page 14-1
High-Speed PWM
14
Section 14. High-Speed PWM
HIGHLIGHTS
This section of the manual contains the following major topics:
14.1 Introduction .................................................................................................................. 14-2
14.2 Features....................................................................................................................... 14-2
14.3 Control Registers ......................................................................................................... 14-3
14.4 Architecture Overview................................................................................................ 14-24
14.5 Module Description .................................................................................................... 14-27
14.6 PWM Operating Modes.............................................................................................. 14-33
14.7 PWM Generator......................................................................................................... 14-71
14.8 PWM Trigger.............................................................................................................. 14-87
14.9 PWM Interrupts.......................................................................................................... 14-98
14.10 PWM Fault Pins ......................................................................................................... 14-99
14.11 Special Features ...................................................................................................... 14-105
14.12 PWM Output Pin Control...........................................................................................14-111
14.13 Immediate Update of PWM Duty Cycle ................................................................... 14-113
14.14 Power-Saving Modes............................................................................................... 14-114
14.15 External Control of Individual Time Base(s)............................................................. 14-114
14.16 Application Information ............................................................................................ 14-115
14.17 Register Map............................................................................................................ 14-126
14.18 Related Application Notes........................................................................................ 14-127
14.19 Revision History ....................................................................................................... 14-128
dsPIC33E/PIC24E Family Reference Manual
DS70645C-page 14-2 © 2010-2011 Microchip Technology Inc.
14.1 INTRODUCTION
This section describes the High-Speed Pulse-Width Modulator (PWM) module and its
associated operational modes. The High-Speed PWM module in the dsPIC33E/PIC24E
device family supports a wide variety of PWM modes and is ideal for power
conversion/motor control applications. Some of the common applications include:
AC-to-DC converters
DC-to-DC converters
AC and DC motors: BLDC, PMSM, ACIM, SRM, etc.
• Inverters
Battery chargers
Digital lighting
Uninterrupted Power Supply (UPS)
Power Factor Correction (PFC) (e.g., Interleaved PFC and Bridgeless PFC)
14.2 FEATURES
The High-Speed PWM module consists of the following major features:
Up to seven PWM generators, each with an individual time base
Two PWM outputs per PWM generator
Individual period and duty cycle for each PWM output
Duty cycle, dead time, phase shift and frequency resolution equal to the system clock
source (TOSC)
Independent fault and current-limit inputs for up to 14 PWM outputs
Redundant Output mode
Independent Output mode (this feature is not available on all devices)
Push-Pull Output mode
Complementary Output mode
Center-Aligned PWM mode
Output override control
Special Event Trigger
PWM capture feature
Prescaler for input clock
ADC triggering with PWM
Independent PWM frequency, duty cycle and phase shift changes
Leading-Edge Blanking (LEB) functionality
Dead time compensation
Output clock chopping
Note: This family reference manual section is meant to serve as a complement to device
data sheets. Depending on the device variant, this manual section may not apply to
all dsPIC33E/PIC24E devices.
Please consult the note at the beginning of the “High-Speed PWM” chapter in the
current device data sheet to check whether this document supports the device you
are using.
Device data sheets and family reference manual sections are available for
download from the Microchip Worldwide Web site at: http://www.microchip.com
© 2010-2011 Microchip Technology Inc. DS70645C-page 14-3
Section 14. High-Speed PWM
High-Speed PWM
14
14.3 CONTROL REGISTERS
The following registers control the operation of the High-Speed PWM module:
PTCON: PWM Time Base Control Register
- Enables or disables the High-Speed PWM module
- Sets the Special Event Trigger for the ADC
- Enables or disables immediate period updates
- Selects the synchronizing source for the master time base
- Specifies synchronization settings
PTCON2: PWM Clock Divider Select Register 2
Provides the clock prescaler to the PWM master time base
PTPER: Primary Master Time Base Period Register
Provides the PWM time period value
STCON: PWM Secondary Master Time Base Control Registe (1)
- Enables or disables immediate period updates based on the secondary master time base
- Selects the synchronization source for the secondary master time base
- Specifies the synchronization setting for secondary master time base control
STCON2: PWM Secondary Clock Divider Select Register 2(1)
Provides the clock prescaler to the PWM secondary master time base
STPER: Secondary Master Time Base Period Register(1)
Provides the secondary master time base period value
MDC: PWM Master Duty Cycle Register
Provides the PWM master duty cycle value
SEVTCMP: PWM Special Event Compare Register
Provides the compare value that is used to trigger the ADC module
SSEVTCMP: PWM Secondary Special Event Compare Register(1)
Provides the compare value that is used to trigger the ADC module based on the
secondary master time base
CHOP: PWM Chop Clock Generator Register
- Provides the chop clock frequency
- Enables or disables the chop clock generator
PWMKEY: PWM Unlock Register(1)
Writes the unlock sequence to allow writes to the IOCONx and FCLCONx registers
PWMCONx: PWM Control Register
- Enables or disables fault interrupt, current-limit interrupt and primary trigger interrupt
- Provides the interrupt status for fault interrupt, current-limit interrupt and primary trigger
interrupt
- Selects the type of time base (master time base or independent time base)
- Selects the type of duty cycle (master duty cycle or independent duty cycle)
- Controls Dead Time mode
- Enables or disables Center-Aligned mode
- Controls the external PWM Reset operation
- Enables or disables immediate updates of the duty cycle, phase offset, independent time
base period
IOCONx: PWM I/O Control Register
- Enables or disables PWM pin control feature (PWM control or GPIO)
- Controls fault/current limit override values
- Enables PWMxH and PWMxL pin swapping
- Controls the PWMxH and PWMxL output polarity
- Controls the PWMxH and PWMxL output if any of the following modes is selected:
Complementary mode
Push-Pull mode
True Independent mode
Note: Not all registers are available on all devices. Refer to the “High-Speed PWM”
chapter in the specific device data sheet for availability.
dsPIC33E/PIC24E Family Reference Manual
DS70645C-page 14-4 © 2010-2011 Microchip Technology Inc.
FCLCONx: PWM Fault Current-Limit Control Register
- Selects the current-limit control signal source
- Selects the current-limit polarity
- Enables or disables Current-Limit mode
- Selects the fault control signal source
- Configures the fault polarity
- Enables or disables Fault mode
PDCx: PWM Generator Duty Cycle Register(1)
- Provides the duty cycle value for the PWMxH and PWMxL outputs, if master time base is
selected
- Provides the duty cycle value for the PWMxH output, if independent time base is selected
PHASEx: PWM Primary Phase Shift Register
- Provides the phase shift value for the PWMxH and PWMxL output, if master time base is
selected
- Provides the independent time base period for the PWMxH output, if independent time
base is selected
SDCx: PWM Secondary Duty Cycle Register(1,2)
Provides the duty cycle value for the PWMxL output, if independent time base is selected
SPHASEx: PWM Secondary Phase Shift Register(1,2,3)
- Provides the phase shift for the PWMxL output, if the master time base is selected
- Provides the independent time base period value for the PWMxL output, if the independent
time base is selected
DTRx: PWM Dead Time Register
- Provides the dead time value for the PWMxH output, if positive dead time is selected
- Provides the dead time value for the PWMxL output, if negative dead time is selected
ALTDTRx: PWM Alternate Dead Time Register
- Provides the dead time value for the PWMxL output, if positive dead time is selected
- Provides the dead time value for the PWMxH output, if negative dead time is selected
TRIGx: PWM Primary Trigger Compare Value Register
Provides the compare value to generate the primary PWM trigger
TRGCONx: PWM Trigger Control Register
- Enables the PWMx trigger postscaler start event
- Specifies the number of PWM cycles to skip before generating the first trigger
LEBCONx: Leading-Edge Blanking Control Register
- Selects the rising or falling edge of the PWM output for LEB
- Enables or disables LEB for fault and current-limit inputs
LEBDLYx: Leading-Edge Blanking Delay Register
Provides leading-edge blanking delay for the fault and current-limit inputs
PWMCAPx: Primary PWM Time Base Capture Register
Provides the captured independent time base value when a leading edge is detected on
the current-limit input, and when LEB processing on the current-limit input signal is
completed
AUXCONx: PWM Auxiliary Control Register
- Selects PWM state blank and chop clock sources
- Selects PWMxH and PWMxL output chopping functionality
dsPIC33E/PIC24E Family Reference Manual
DS70645C-page 14-6 © 2010-2011 Microchip Technology Inc.
Register 14-2: PTCON2: PWM Clock Divider Select Register 2
U-0 U-0 U-0 U-0 U-0 U-0 U-0 U-0
— —
bit 15 bit 8
U-0 U-0 U-0 U-0 U-0 R/W-0 R/W-0 R/W-0
— — PCLKDIV<2:0>(1)
bit 7 bit 0
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at POR 1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
bit 15-3 Unimplemented: Read as ‘0
bit 2-0 PCLKDIV<2:0>: PWM Input Clock Prescaler (Divider) Select bits(1)
111 = Reserved
110 = Divide by 64
101 = Divide by 32
100 = Divide by 16
011 = Divide by 8
010 = Divide by 4
001 = Divide by 2
000 = Divide by 1, maximum PWM timing resolution (power-on default)
Note 1: These bits should be changed only when PTEN = 0. Changing the clock selection during operation will
yield unpredictable results.
Register 14-3: PTPER: Primary Master Time Base Period Register
R/W-1 R/W-1 R/W-1 R/W-1 R/W-1 R/W-1 R/W-1 R/W-1
PTPER<15:8>(1)
bit 15 bit 8
R/W-1 R/W-1 R/W-1 R/W-1 R/W-1 R/W-0 R/W-0 R/W-0
PTPER<7:0>(1)
bit 7 bit 0
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at POR 1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
bit 15-0 PTPER<15:0>: Primary Master Time Base (PMTMR) Period Value bits(1)
Note 1: 1 LSb = 1 Tosc. For example, 7.14 ns for 70 MIPS operation.
© 2010-2011 Microchip Technology Inc. DS70645C-page 14-7
Section 14. High-Speed PWM
High-Speed PWM
14
Register 14-4: STCON: PWM Secondary Master Time Base Control Registe (1)
U-0 U-0 U-0 HS/HC-0 R/W-0 R/W-0 R/W-0 R/W-0
SESTAT SEIEN EIPU(2) SYNCPOL SYNCOEN
bit 15 bit 8
R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0
SYNCEN SYNCSRC<2:0> SEVTPS<3:0>
bit 7 bit 0
Legend: HC = Cleared in Hardware HS = Set in Hardware
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
bit 15-13 Unimplemented: Read as 0
bit 12 SESTAT: Special Event Interrupt Status bit
1 = Secondary Special Event Interrupt is pending
0 = Secondary Special Event Interrupt is not pending
bit 11 SEIEN: Special Event Interrupt Enable bit
1 = Secondary Special Event Interrupt is enabled
0 = Secondary Special Event Interrupt is disabled
bit 10 EIPU: Enable Immediate Period Updates bit(2)
1 = Active Secondary Period register is updated immediately
0 = Active Secondary Period register updates occur on PWM cycle boundaries
bit 9 SYNCPOL: Synchronize Input and Output Polarity bit
1 = SYNCO2 output is active-low
0 = SYNCO2 output is active-high
bit 8 SYNCOEN: Secondary Master Time Base Sync Enable bit
1 = SYNCO2 output is enabled
0 = SYNCO2 output is disabled
bit 7 SYNCEN: External Secondary Master Time Base Synchronization Enable bit
1 = External synchronization of secondary time base is enabled
0 = External synchronization of secondary time base is disabled
bit 6-4 SYNCSRC<2:0>: Secondary Time Base Sync Source Selection bits
These bits select the SYNCIx or PTGOx input as the synchronous source. Refer to the “High-Speed
PWM” chapter in the specific device data sheet for availability.
bit 3-0 SEVTPS<3:0>: PWM Secondary Special Event Trigger Output Postscaler Select bits
1111 = 1:16 Postscale
0001 = 1:2 Postscale
0000 = 1:1 Postscale
Note 1: This register is not available on all devices. Refer to the “High-Speed PWM” chapter of the specific
device data sheet for availability.
2: This bit only applies to the secondary master time base period.
dsPIC33E/PIC24E Family Reference Manual
DS70645C-page 14-8 © 2010-2011 Microchip Technology Inc.
Register 14-5: STCON2: PWM Secondary Clock Divider Select Register 2
(1)
U-0 U-0 U-0 U-0 U-0 U-0 U-0 U-0
— —
bit 15 bit 8
U-0 U-0 U-0 U-0 U-0 R/W-0 R/W-0 R/W-0
— — PCLKDIV<2:0>(2)
bit 7 bit 0
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
bit 15-3 Unimplemented: Read as ‘0
bit 2-0 PCLKDIV<2:0>: PWM Input Clock Prescaler (Divider) Select bits(2)
111 = Reserved
110 = Divide by 64
101 = Divide by 32
100 = Divide by 16
011 = Divide by 8
010 = Divide by 4
001 = Divide by 2
000 = Divide by 1, maximum PWM timing resolution (power-on default)
Note 1: This register is not available on all devices. Refer to the “High-Speed PWM” chapter of the specific
device data sheet for availability.
2: These bits should be changed only when PTEN = 0. Changing the clock selection during operation will
yield unpredictable results.
© 2010-2011 Microchip Technology Inc. DS70645C-page 14-9
Section 14. High-Speed PWM
High-Speed PWM
14
Register 14-6: STPER: Secondary Master Time Base Period Register
(1)
R/W-1 R/W-1 R/W-1 R/W-1 R/W-1 R/W-1 R/W-1 R/W-1
STPER<15:8>
bit 15 bit 8
R/W-1 R/W-1 R/W-1 R/W-1 R/W-1 R/W-1 R/W-1 R/W-1
STPER<7:0>
bit 7 bit 0
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
bit 15-0 STPER<15:0>: Secondary Master Time Base Period Value bits
Note 1: This register is not available on all devices. Refer to the “High-Speed PWM” chapter of the specific
device data sheet for availability.
Register 14-7: MDC: PWM Master Duty Cycle Register
R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0
MDC<15:8>
bit 15 bit 8
R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0
MDC<7:0>
bit 7 bit 0
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
bit 15-0 MDC<15:0>: Master PWM Duty Cycle Value bits
Register 14-8: SEVTCMP: PWM Special Event Compare Register
R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0
SEVTCMP<15:8>
bit 15 bit 8
R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0
SEVTCMP<7:0>
bit 7 bit 0
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
bit 15-0 SEVTCMP<15:0>: Special Event Compare Count Value bits
dsPIC33E/PIC24E Family Reference Manual
DS70645C-page 14-10 © 2010-2011 Microchip Technology Inc.
Register 14-9: SSEVTCMP: PWM Secondary Special Event Compare Register
(1)
R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0
SSEVTCMP<15:8>
bit 15 bit 8
R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0
SSEVTCMP<7:0>
bit 7 bit 0
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
bit 15-0 SSEVTCMP<15:0>: Secondary Special Event Compare Count Value bits
The optional SSEVTCMP register and the optional secondary master time base provide an additional
Special Event Trigger. The secondary special event trigger also has its own postscaler controlled by
the SEVTPS<3:0> bits in the STCON register.
Note 1: This register is not available on all devices. Refer to the “High-Speed PWM” chapter of the specific
device data sheet for availability.
Register 14-10: CHOP: PWM Chop Clock Generator Register
R/W-0 U-0 U-0 U-0 U-0 U-0 R/W-0 R/W-0
CHPCLKEN — CHOPCLK<9:8>
bit 15 bit 8
R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0
CHOPCLK<7:0>
bit 7 bit 0
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
bit 15 CHPCLKEN: Enable Chop Clock Generator bit
1 = Chop clock generator is enabled
0 = Chop clock generator is disabled
bit 14-10 Unimplemented: Read as ‘0
bit 9-0 CHOPCLK<9:0>: Chop Clock Divider bits
Chop Frequency = (FP/PLKDIV) / (CHOPCLK<9:0> + 1)
As an example, for devices running at 60 MIPS, a value of all zeros will yield a 60 MHz chop clock
(period = 16.7 ns) with the PWM clock prescaler configured for fastest clock. A value of 0000000001
in the CHOPCLK<9:0> bits will yield a 30 MHz chop clock with the PWM clock prescaler configured
for fastest clock.
Note: The chop clock generator operates with the Primary PWM Clock Prescaler bits (PCLKDIV<2:0>) in the
PTCON2 register.
dsPIC33E/PIC24E Family Reference Manual
DS70645C-page 14-14 © 2010-2011 Microchip Technology Inc.
Register 14-13: IOCONx: PWM I/O Control Register
R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0
PENH PENL POLH POLL PMOD<1:0> OVRENH OVRENL
bit 15 bit 8
R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0
OVRDAT<1:0> FLTDAT<1:0>(1,2) CLDAT<1:0> SWAP OSYNC
bit 7 bit 0
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
bit 15 PENH: PWMxH Output Pin Ownership bit
1 = PWM module controls PWMxH pin
0 = GPIO module controls PWMxH pin
bit 14 PENL: PWMxL Output Pin Ownership bit
1 = PWM module controls PWMxL pin
0 = GPIO module controls PWMxL pin
bit 13 POLH: PWMxH Output Pin Polarity bit
1 = PWMxH pin is active-low
0 = PWMxH pin is active-high
bit 12 POLL: PWMxL Output Pin Polarity bit
1 = PWMxL pin is active-low
0 = PWMxL pin is active-high
bit 11-10 PMOD<1:0>: PWM # I/O Pin Mode bits
11 = PWM I/O pin pair is in True Independent PWM Output mode
(3)
10 = PWM I/O pin pair is in Push-Pull Output mode
01 = PWM I/O pin pair is in Redundant Output mode
00 = PWM I/O pin pair is in Complementary Output mode
bit 9 OVRENH: Override Enable for PWMxH Pin bit
1 = OVRDAT<1> provides data for output on PWMxH pin
0 = PWM generator provides data for PWMxH pin
bit 8 OVRENL: Override Enable for PWMxL Pin bit
1 = OVRDAT<0> provides data for output on PWMxL pin
0 = PWM generator provides data for PWMxL pin
bit 7-6 OVRDAT<1:0>: State(2) for PWMxH, PWMxL Pins if Override is Enabled bits
If OVERENH = 1, OVRDAT<1> provides data for PWMxH
If OVERENL = 1, OVRDAT<0> provides data for PWMxL
Note 1: These bits must not be changed after the PWM module is enabled (PTEN = 1).
2: State represents Active/Inactive state of the PWM, depending on the POLH and POLL bits. For example, if
FLTDAT<1> is set to 1’ and POLH is set to 1, the PWMxH pin will be at logic level 0 (active level) when a
fault occurs.
3: This feature is not available on all devices. Refer to the “High-Speed PWM” chapter of the specific device
data sheet for availability.
© 2010-2011 Microchip Technology Inc. DS70645C-page 14-15
Section 14. High-Speed PWM
High-Speed PWM
14
bit 5-4 FLTDAT<1:0>: State(2) for PWMxH and PWMxL Pins if FLTMOD is Enabled bits(1)
IFLTMOD (FCLCONx<15>) = 0: Normal Fault mode:
If fault is active, FLTDAT<1> provides the state for PWMxH.
If fault is active, FLTDAT<0> provides the state for PWMxL.
IFLTMOD (FCLCONx<15>) = 1: Independent Fault mode:
If current-limit is active, FLTDAT<1> provides the state for PWMxH.
If fault is active, FLTDAT<0> provides the state for PWMxL.
bit 3-2 CLDAT<1:0>: State(2) for PWMxH and PWMxL Pins if CLMOD is Enabled bits
IFLTMOD (FCLCONx<15>) = 0: Normal Fault mode:
If current-limit is active, CLDAT<1> provides the state for PWMxH.
If current-limit is active, CLDAT<0> provides the state for PWMxL.
IFLTMOD (FCLCONx<15>) = 1: Independent Fault mode:
The CLDAT<1:0> bits are ignored.
bit 1 SWAP: SWAP PWMxH and PWMxL Pins bit
1 = PWMxH output signal is connected to PWMxL pin; PWMxL output signal is connected to PWMxH
pin
0 = PWMxH and PWMxL output signals pins are mapped to their respective pins
bit 0 OSYNC: Output Override Synchronization bit
1 = Output overrides via the OVRDAT<1:0> bits are synchronized to the PWM time base
0 = Output overrides via the OVRDAT<1:0> bits occur on next CPU clock boundary
Register 14-13: IOCONx: PWM I/O Control Register (Continued)
Note 1: These bits must not be changed after the PWM module is enabled (PTEN = 1).
2: State represents Active/Inactive state of the PWM, depending on the POLH and POLL bits. For example, if
FLTDAT<1> is set to ‘1’ and POLH is set to ‘1’, the PWMxH pin will be at logic level 0 (active level) when a
fault occurs.
3: This feature is not available on all devices. Refer to the “High-Speed PWM” chapter of the specific device
data sheet for availability.
© 2010-2011 Microchip Technology Inc. DS70645C-page 14-17
Section 14. High-Speed PWM
High-Speed PWM
14
Register 14-15: PDCx: PWM Generator Duty Cycle Register(1)
R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0
PDCx<15:8>
bit 15 bit 8
R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0
PDCx<7:0>
bit 7 bit 0
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
bit 15-0 PDCx<15:0>: PWM Generator # Duty Cycle Value bits
Note 1: In Independent PWM mode, PMOD<1:0> (IOCONx<11:10>) = 11, the PDCx register controls the PWMxH
duty cycle only. In Complementary, Redundant and Push-Pull PWM modes (PMOD<1:0>
(IOCONx<11:0>) = 00 01, , or 10), the PDCx register controls the duty cycle of both the PWMxH and
PWMxL.
Register 14-16: PHASEx: PWM Primary Phase Shift Register
R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0
PHASEx<15:8>
bit 15 bit 8
R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0
PHASEx<7:0>
bit 7 bit 0
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
bit 15-0 PHASEx<15:0>: PWM Phase Shift Value or Independent Time Base Period bits for the PWM Generator
Note 1: If the ITB bit = 0 (PWMCONx<9>), the following applies based on the mode of operation:
Complementary, Redundant and Push-Pull Output mode (PMOD<1:0> (IOCONx<11:10>) = 00,
01 10, or ) PHASEx<15:0> = Phase shift value for PWMxH and PWMxL outputs
True Independent Output mode (PMOD<1:0> (IOCONx<11:10>) = 11) PHASEx<15:0> = Phase
shift value for PWMxH only
2: If the ITB bit = 1(PWMCONx<9>), the following applies based on the mode of operation:
Complementary, Redundant, and Push-Pull Output mode (PMOD<1:0> (IOCONx<11:10>) = 00,
01 10, or ) PHASEx<15:0> = Independent time base period value for PWMxH and PWMxL
True Independent Output mode (PMOD<1:0> (IOCONx<11:10>) = 11) PHASEx<15:0> = Independent
time base period for PWMxH only
dsPIC33E/PIC24E Family Reference Manual
DS70645C-page 14-18 © 2010-2011 Microchip Technology Inc.
Register 14-17: SDCx: PWM Secondary Duty Cycle Register(1,2)
R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0
SDCx<15:8>
bit 15 bit 8
R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0
SDCx<7:0>
bit 7 bit 0
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
bit 15-0 SDCx<15:0>: Secondary Duty Cycle bits for PWMxL output pin
Note 1: The SDCx register is used in Independent PWM mode only (PMOD<1:0> (IOCONx<11:10>) = 11. When
used in Independent PWM mode, the SDCx register controls the PWMxL duty cycle.
2: This register is not available on all devices. Refer to the “High-Speed PWM” chapter of the specific
device data sheet for availability.
Register 14-18: SPHASEx: PWM Secondary Phase Shift Register
(1,2,3)
R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0
SPHASEx<15:8>
bit 15 bit 8
R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0
SPHASEx<7:0>
bit 7 bit 0
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
bit 15-0 SPHASEx<15:0>: Secondary Phase Offset bits for PWMxL Output Pin
Note 1: If the ITB bit = 0 (PWMCONx<9>), the following applies based on the mode of operation:
Complementary, Redundant and Push-Pull Output mode (PMOD<1:0> (IOCONx<11:10>) = 00,
01 10, or ) SPHASEx<15:0> = Not used
True Independent Output mode (PMOD<1:0> (IOCONx<11:10>) = 11) SPHASEx<15:0> = Phase
shift value for PWMxL only
2: If the ITB bit = 1 (PWMCONx<9>), the following applies based on the mode of operation:
Complementary, Redundant and Push-Pull Output mode (PMOD<1:0> (IOCONx<11:10>) = 00,
01 10, or ) SPHASEx<15:0> = Not used
True Independent Output mode (PMOD<1:0> (IOCONx<11:10>) = 11) SPHASEx<15:0> =
Independent time base period value for PWMxL only
3: This register is not available on all devices. Refer to the “High-Speed PWM” chapter of the specific device
data sheet for availability.
dsPIC33E/PIC24E Family Reference Manual
DS70645C-page 14-20 © 2010-2011 Microchip Technology Inc.
Register 14-22: TRGCONx: PWM Trigger Control Register
R/W-0 R/W-0 R/W-0 R/W-0 U-0 U-0 U-0 U-0
TRGDIV<3:0> — —
bit 15 bit 8
U-0 U-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0
— — TRGSTRT<5:0>
bit 7 bit 0
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
bit 15-12 TRGDIV<3:0>: Trigger # Output Divider bits
1111 = Trigger output for every 16th trigger event
0010 = Trigger output for every 3rd trigger event
0001 = Trigger output for every 2nd trigger event
0000 = Trigger output for every trigger event
bit 11-6 Unimplemented: Read as 0
bit 5-0 TRGSTRT<5:0>: Trigger Postscaler Start Enable Select bits
111111 = Wait 63 PWM cycles before generating the first trigger event after the module is enabled
000010 = Wait 2 PWM cycles before generating the first trigger event after the module is enabled
000001 = Wait 1 PWM cycles before generating the first trigger event after the module is enabled
000000 = Wait 0 PWM cycles before generating the first trigger event after the module is enabled
© 2010-2011 Microchip Technology Inc. DS70645C-page 14-25
Section 14. High-Speed PWM
High-Speed PWM
14
The High-Speed PWM module contains multiple PWM generators. Each PWM generator
provides two PWM outputs: PWMxH and PWMxL. A master time base generator provides a
synchronous signal as a common time base to synchronize the various PWM outputs. Each
generator can operate independently or in sync with the master time base.
The individual PWM
outputs are available on the output pins of the device. The input fault signals and current-limit
signals, when enabled, monitor and protect the system by placing the PWM outputs into a known
“safe” state.
Each PWM generator can create a trigger to the ADC module to sample the analog signal at a
specific instance during the PWM period. In addition, the High-Speed PWM module also
generates a Special Event Trigger to the ADC module based on the master time base.
The High-Speed PWM module can synchronize itself with an external signal or can act as a
synchronizing source to any external device. The SYNCIx is the input pin, which can synchronize
the High-Speed PWM module with an external signal. The SYNCOx pin is an output pin that
provides a synchronous signal to an external device.
The High-Speed PWM module can be used for a wide variety of power conversion/motor control
applications that require:
High operating frequencies with good resolution
Ability to dynamically control PWM parameters such as duty cycle, period and dead time
Ability to independently control each PWM
Ability to synchronously control all PWMs
Independent resource allocation for each PWM generator
Fault handling capability
CPU load staggering to execute multiple control loops
Each function of the High-Speed PWM module is described in detail in subsequent sections.
Figure 14-2 illustrates the interconnections between various registers in the High-Speed PWM
module.
dsPIC33E/PIC24E Family Reference Manual
DS70645C-page 14-26 © 2010-2011 Microchip Technology Inc.
Figure 14-2: High-Speed PWM Module Register Interconnection Diagram
MUX
PTMRx
PDCx
PWMCONx TRGCONx
PTCON, PTCON2
IOCONx
DTRx
PWMxL
PWMxH
FLTx
PWM1L
PWM1H
FCLCONx
MDC
PHASEx
LEBCONx
MUX
STMRx
SDCx
SPHASEx ALTDTRx
PWMCAPx
User Override Logic
Current-Limit
PWM Output Mode
Control Logic
Dead
Logic
Pin
Control
Logic
Fault and
Current-Limit
Logic
PWM Generator 1
FLTx
PWM Generator x
Interrupt
Logic
ADC Trigger
Module Control and Timing
Master Duty Cycle Register
Synchronization Synchronization
Master PeriodMaster Period
Master Duty CycleMaster Duty Cycle
Secondary PWM
SYNCI2
SYNCI1
SYNCO1
SEVTCMP
Comparator Special Event Trigger
Special Event
Postscaler
PTPER
PMTMR Primary Master Time Base
Master Time Base Counter
Special Event Compare Trigger
Comparator
Clock
Prescaler
Comparator
Comparator
Comparator
16-bit Data Bus
Time
TRIGx Fault Override Logic
Override Logic
SYNCO2
SEVTCMP
Comparator Special Event Trigger
Special Event
Postscaler
PTPER
PMTMR Secondary Master Time Base
Master Time Base Counter
Special Event Compare Trigger
Comparator
Clock
Prescaler
DTCMPx
DTCMP1
Note 1: Not all of the features and registers listed in this block diagram are available on all devices. Refer to the
“High-Speed PWM” chapter of the specific device data sheet for availability.
dsPIC33E/PIC24E Family Reference Manual
DS70645C-page 14-28 © 2010-2011 Microchip Technology Inc.
14.5.4 Standard Edge-Aligned PWM
The standard edge-aligned PWM waveforms are illustrated in Figure 14-3. To create the
edge-aligned PWM, a timer or counter circuit counts upward from zero to a specified maximum
value, called Period. Another register contains the duty cycle value, which is constantly
compared with the timer value. When the timer or counter value is less than or equal to the duty
cycle value, the PWM output signal is asserted. When the timer value exceeds the duty cycle
value, the PWM signal is deasserted. When the timer value is greater than or equal to the period
value, the timer resets itself and the process repeats.
Figure 14-3: Standard Edge-Aligned PWM Mode
14.5.5 Center-Aligned PWM
The center-aligned PWM waveforms illustrated in Figure 14-4, align the PWM signals with
respect to a reference point so that half of the PWM signal occurs before the reference point and
the remaining half of the signal occurs after the reference point. The Center-Aligned mode is
enabled when the CAM bit (PWMCONx<2>) is set.
When operating in Center-Aligned mode, the effective PWM period is twice the value specified
in the PHASEx registers, because the independent time base counter in the PWM generator is
counting up and then counting down during the cycle. The up/down count sequence doubles the
effective PWM cycle period. This mode is used in many motor control applications.
Note: The Independent Time Base mode (ITB = 1) must be enabled to use the
Center-Aligned mode. If ITB = 0, the CAM bit is ignored.
PDC1
Period
Value
Timer
Value
Duty Cycle Match Timer Resets
Period
Duty Cycle
0
Period
TOFFTON
PWMxH
PWMxH
© 2010-2011 Microchip Technology Inc. DS70645C-page 14-29
Section 14. High-Speed PWM
High-Speed PWM
14
Figure 14-4: Center-Aligned PWM Mode
Example 14-2: Edge-Aligned or Center-Aligned Mode Selection
PWM1H
PWM2H
0
PDC1
PDC2
PHASEx
Period
2 x Period
/* Select Edge-Aligned PWM Time Base */
PWMCON1bits.CAM = 0; /* For Edge-Aligned mode */
/* Select Center-Aligned PWM Time Base */
PWMCON1bits.CAM = 1; /* For Center-Aligned mode */
PWMCON1bits.ITB = 1; /* Must be set for Center-Aligned mode */
© 2010-2011 Microchip Technology Inc. DS70645C-page 14-31
Section 14. High-Speed PWM
High-Speed PWM
14
An external device can also be synchronized with the master time base using the
Synchronization Output (SYNCOx) signal. The SYNCOx signal is generated when the PTPER
register resets the PMTMR register. The SYNCOx signal pulse is 12 * TCY to ensure other
devices reliably sense the signals. The polarity of the SYNCOx signal is determined by the
SYNCPOL bit (PTCON<9>). The SYNCOx signal can be enabled or disabled by selecting the
SYNCOEN bit (PTCON<8>).
The advantage of synchronization is that it ensures the beat frequencies are not generated when
multiple power controllers are in use.
Example 14-3: Synchronizing Master Time Base with External Signal
Example 14-4: Synchronizing External Device with Master Time Base
14.5.8 Special Event Trigger
The High-Speed PWM module has a master Special Event Trigger that can be used for
synchronization of analog-to-digital conversions with the PWM time base. The analog-to-digital
sampling and conversion time can be programmed to occur within the PWM period. The Special
Event Trigger allows the user-assigned application to minimize the delay between the time the
conversion results are acquired and the time the duty cycle value is updated. The Special Event
Trigger is based on the master time base.
The master Special Event Trigger value is loaded into the PWM Special Event Compare register
(SEVTCMP). In addition, the SEVTPS<3:0> bits (PTCON<3:0>), control the Special Event
Trigger operation. To generate a trigger to the ADC module, the value in the PTPER register is
compared with the value in the SEVTCMP register. The master Special Event Trigger has a
postscaler that allows a 1:1 to 1:16 postscaler ratio. The postscaler is configured by writing to the
SEVTPS<3:0> bits (PTCON<3:0>).
The Special Event Trigger pulses are always generated during the following instances:
On a match condition regardless of the status of the Special Event Interrupt Enable bit
(SEIEN)
If the compare value in the SEVTCMP register is a value from zero to a maximum value of
the PTPER register
Note 1: The SYNCIx pulse should be greater than the PWM period value.
2: The SYNCIx pulse should be continuous with a minimum pulse-width of 200 ns.
3: The PWM cycles are expected to be distorted for the first two SYNCIx pulses.
4: The period value should be a multiple of 8 (Least Significant 3 bits set to ‘0) for the
external synchronization to work in the Push-Pull mode.
5: There is a delay from the input of a SYNC signal until the internal time base counter
is Reset. This will be approximately 2.5 * prescale clock period.
6: The External Time Base Synchronization must not be used with phase shifted PWM
as the synchronization signal may not maintain the phase relationships between the
multiple PWM channels.
7: The External Time Base Synchronization cannot be used in Independent Time
Base mode.
/* Synchronizing Master Time Base with External Signal */
PTCONbits.SYNCSRC = 0; /* Select SYNC1 input as synchronizing source */
PTCONbits.SYNCPOL = 0; /* Rising edge of SYNC1 resets the PWM Timer */
PTCONbits.SYNCEN = 1; /* Enable external synchronization */
/* Synchronizing External Device with Master Time Base */
PTCONbits.SYNCPOL = 0; /* SYNCO output is active-high */
PTCONbits.SYNCOEN = 1; /* Enable SYNCO output */
© 2010-2011 Microchip Technology Inc. DS70645C-page 14-33
Section 14. High-Speed PWM
High-Speed PWM
14
14.6 PWM OPERATING MODES
The High-Speed PWM module supports the following operation modes:
Push-Pull Output mode
Complementary Output mode
Redundant Output mode
Independent Output mode (this feature is not available on all devices)
These operating modes can be selected using the PMOD<1:0> bits (IOCONx<11:10>).
In the following sections, figures and examples are provided, which show the PWM outputs in
multiple operating modes. Table 14-1 provides a list of the available modes and settings, with
references to the figures by number.
Table 14-1: Mode and Code Cross-reference Table
PWM Mode Mode Settings Related
Figure
Push-Pull Independent Duty Cycle and Phase, Fixed Primary Period, Edge-Aligned 14-7
Independent Duty Cycle and Phase, Fixed Secondary Period, Edge-Aligned 14-8
Master Duty Cycle and Independent Phase, Fixed Primary Period, Edge-Aligned 14-9
Master Duty Cycle and Independent Phase, Fixed Secondary Period, Edge-Aligned 14-10
Independent Duty Cycles and Periods, No Phase-Shifting, Edge-Aligned 14-11
Master Duty Cycles and Independent Periods, No Phase-Shifting, Edge-Aligned 14-12
Independent Duty Cycles and Periods, No Phase-Shifting, Center-Aligned Mode 14-13
Master Duty Cycles and Independent Periods, No Phase-Shifting, Center-Aligned Mode 14-14
Complementary Independent Duty Cycle and Phase, Fixed Primary Period, Edge-Aligned 14-15
Independent Duty Cycle and Phase, Fixed Secondary Period, Edge-Aligned 14-16
Master Duty Cycle and Independent Phase, Fixed Primary Period, Edge-Aligned 14-17
Master Duty Cycle and Independent Phase, Fixed Secondary Period, Edge-Aligned 14-18
Independent Duty Cycles and Periods, No Phase-Shifting, Edge-Aligned 14-19
Master Duty Cycles and Independent Periods, No Phase-Shifting, Edge-Aligned 14-20
Independent Duty Cycles and Periods, No Phase-Shifting, Center-Aligned 14-21
Master Duty Cycles and Independent Periods, No Phase-Shifting, Center-Aligned 14-22
Redundant Independent Duty Cycle and Phase, Fixed Primary Period, Edge-Aligned 14-23
Independent Duty Cycle and Phase, Fixed Secondary Period, Edge-Aligned 14-24
Master Duty Cycle and Variable Phase, Fixed Primary Period, Edge-Aligned 14-25
Master Duty Cycle and Variable Phase, Fixed Secondary Period, Edge-Aligned 14-26
Independent Duty Cycles and Periods, No Phase-Shifting, Edge-Aligned 14-27
Master Duty Cycles and Independent Periods, No Phase-Shifting, Edge-Aligned 14-28
Independent Duty Cycles and Periods, No Phase-Shifting, Center-Aligned 14-29
Master Duty Cycles and Independent Periods, No Phase-Shifting, Center-Aligned 14-30
Independent Independent Duty Cycle and Phase, Fixed Primary Period, Edge-Aligned 14-31
Independent Duty Cycle and Phase, Fixed Secondary Period, Edge-Aligned 14-32
Master Duty Cycle, Variable Phase, Fixed Primary Period, Edge-Aligned 14-33
Master Duty Cycle, Variable Phase, Fixed Secondary Period, Edge-Aligned 14-34
Independent Duty Cycles and Periods, No Phase-Shifting, Edge-Aligned 14-35
Master Duty Cycles, Independent Periods, No Phase-Shifting, Edge-Aligned 14-36
Independent Duty Cycles and Periods, No Phase-Shifting, Center-Aligned 14-37
Master Duty Cycles, Independent Periods, No Phase-Shifting, Center-Aligned 14-38
dsPIC33E/PIC24E Family Reference Manual
DS70645C-page 14-34 © 2010-2011 Microchip Technology Inc.
14.6.1 Push-Pull PWM Mode
In Push-Pull mode, the PWM outputs are alternately available on the PWMxH and PWMxL pins.
Some typical applications of Push-Pull mode are provided in 14.16 “Application Information”.
Figure 14-7 through Figure 14-14 and Example 14-6 through Example 14-13 show the PWM
outputs for Push-Pull PWM mode in multiple operating modes.
Figure 14-7: Push-Pull PWM Mode – Independent Duty Cycle and Phase, Fixed Primary Period,
Edge-Aligned
Note: Not all of the features and registers listed in the Figures and Code Examples in this
section are available on all devices. Refer to the “High-Speed PWM” chapter of the
specific device data sheet for availability.
PTPER
PHASE1 = 0
PHASE2
PHASE3
PDC1
Where:
PHASEx Phase of PWMxH and PWMxL
PDCx Duty Cycle of PWMxH and PWMxL
PTPER Period of PWMxH and PWMxL
DTRx Dead Time for PWMxH Rising Edge
ALTDTRx Dead Time for PWMxL Rising Edge
PWM1H
PWM1L
PWM2H
PWM2L
PWM3H
PWM3L
Start of
PWM Cycle
PDC1
PDC2
PDC2
PDC3
PDC3
Complete
PWM1L Cycle
DTR1
ALTDTR1
ALTDTR2
DTR2
ALTDTR3
DTR3
© 2010-2011 Microchip Technology Inc. DS70645C-page 14-37
Section 14. High-Speed PWM
High-Speed PWM
14
Example 14-8: Push-Pull PWM Mode – Master Duty Cycle and Independent Phase, Fixed Primary Period,
Edge-Aligned
Figure 14-10: Push-Pull PWM Mode – Master Duty Cycle and Independent Phase, Fixed Secondary Period,
Edge-Aligned
/* Set PWM Period on Primary Time Base*/
PTPER = 1000;
/* Set Phase Shift */
PHASE1 = 0;
PHASE2 = 100;
PHASE3 = 200;
/* Set Duty Cycles */
MDC = 200;
/* Set Dead Time Values */
DTR1 = DTR2 = DTR3 = 25;
ALTDTR1 = ALTDTR2 = ALTDTR3 = 25;
/* Set PWM Mode to Push-Pull */
IOCON1 = IOCON2 = IOCON3 = 0xC800;
/* Set Primary Time Base, Edge-Aligned Mode and Master Duty Cycles */
PWMCON1 = PWMCON2 = PWMCON3 = 0x0100;
/* Configure Faults */
FCLCON1 = FCLCON2 = FCLCON3 = 0x0003;
/* 1:1 Prescaler */
PTCON2 = 0x0000;
/* Enable PWM Module */
PTCON = 0x8000;
Where:
PHASEx Phase of PWMxH and PWMxL
MDC Duty Cycle of PWMxH and PWMxL
STPER Period of PWMxH and PWMxL
DTRx Dead Time for PWMxH Rising Edge
ALTDTRx Dead Time for PWMxL Rising Edge
STPER
PHASE1 = 0
PHASE2
PHASE3
MDC
PWM1H
PWM1L
PWM2H
PWM2L
PWM3H
PWM3L
Start of
PWM Cycle
MDC
MDC
MDC
MDC
MDC
Complete
PWM1L Cycle
DTR1
ALTDTR1
ALTDTR2
DTR2
ALTDTR3
DTR3
dsPIC33E/PIC24E Family Reference Manual
DS70645C-page 14-38 © 2010-2011 Microchip Technology Inc.
Example 14-9: Push-Pull PWM Mode – Master Duty Cycle and Independent Phase, Fixed Secondary Period,
Edge-Aligned
Figure 14-11: Push-Pull PWM Mode – Independent Duty Cycles and Independent Periods, No Phase-Shifting,
Edge-Aligned
/* Set PWM Period on Secondary Time Base*/
STPER = 1000;
/* Set Phase Shift */
PHASE1 = 0;
PHASE2 = 100;
PHASE3 = 200;
/* Set Duty Cycles */
MDC = 200;
/* Set Dead Time Values */
DTR1 = DTR2 = DTR3 = 25;
ALTDTR1 = ALTDTR2 = ALTDTR3 = 25;
/* Set PWM Mode to Push-Pull */
IOCON1 = IOCON2 = IOCON3 = 0xC800;
/* Set Secondary Time Base, Edge-Aligned Mode and Master Duty Cycles */
PWMCON1 = PWMCON2 = PWMCON3 = 0x0108;
/* Configure Faults */
FCLCON1 = FCLCON2 = FCLCON3 = 0x0003;
/* 1:1 Prescaler */
PTCON2 = 0x0000;
/* Enable PWM Module */
PTCON = 0x8000;
PWM1H
PWM1L
PWM2H
PWM2L
PWM3H
PWM3L
PDC1
PDC2
PDC3
PHASE1
PHASE2
PHASE3
Start of
PWM Cycle Complete
PWM1L Cycle
Where:
PHASEx Period of PWMxH and PWMxL
PDCx Duty Cycle of PWMxH and PWMxL
DTRx Dead time for PWMxH Rising Edge
ALTDTRx Dead time for PWMxL Rising Edge
ALTDTR3
ALTDTR2
ALTDTR1 DTR1
DTR2
DTR3
© 2010-2011 Microchip Technology Inc. DS70645C-page 14-39
Section 14. High-Speed PWM
High-Speed PWM
14
Example 14-10: Push-Pull PWM Mode – Independent Duty Cycles and Independent Periods, No
Phase-Shifting, Edge-Aligned
Figure 14-12: Push-Pull PWM Mode – Master Duty Cycles and Independent Periods, No Phase-Shifting,
Edge-Aligned
/* Set PWM Periods on PHASEx Registers */
PHASE1 = 1000;
PHASE2 = 900;
PHASE3 = 800;
/* Set Duty Cycles */
PDC1 = 200;
PDC2 = 300;
PDC3 = 400;
/* Set Dead Time Values */
DTR1 = DTR2 = DTR3 = 25;
ALTDTR1 = ALTDTR2 = ALTDTR3 = 25;
/* Set PWM Mode to Push-Pull */
IOCON1 = IOCON2 = IOCON3 = 0xC800;
/* Set Independent Time Bases, Edge-Aligned Mode and Independent Duty Cycles */
PWMCON1 = PWMCON2 = PWMCON3 = 0x0200;
/* Configure Faults */
FCLCON1 = FCLCON2 = FCLCON3 = 0x0003;
/* 1:1 Prescaler */
PTCON2 = 0x0000;
/* Enable PWM Module */
PTCON = 0x8000;
PWM1H
PWM1L
PWM2H
PWM2L
PWM3H
PWM3L
MDC
PHASE1
PHASE2
PHASE3
Start of
PWM Cycle Complete
PWM1L Cycle
Where:
PHASEx Period of PWMxH and PWMxL
MDC Duty Cycle of PWMxH and PWMxL
DTRx Dead Time for PWMxH Rising Edge
ALTDTRx Dead Time for PWMxL Rising Edge
ALTDTR3
ALTDTR2
ALTDTR1 DTR1
DTR2
DTR3
dsPIC33E/PIC24E Family Reference Manual
DS70645C-page 14-40 © 2010-2011 Microchip Technology Inc.
Example 14-11: Push-Pull PWM Mode – Master Duty Cycles and Independent Periods, No Phase-Shifting,
Edge-Aligned
Figure 14-13: Push-Pull PWM ModeIndependent Duty Cycles and Independent Periods, No Phase-Shifting,
Center-Aligned Mode
/* Set PWM Periods on PHASEx Registers */
PHASE1 = 1000;
PHASE2 = 900;
PHASE3 = 800;
/* Set Duty Cycles */
MDC = 200;
/* Set Dead Time Values */
DTR1 = DTR2 = DTR3 = 25;
ALTDTR1 = ALTDTR2 = ALTDTR3 = 25;
/* Set PWM Mode to Push-Pull */
IOCON1 = IOCON2 = IOCON3 = 0xC800;
/* Set Independent Time Bases, Edge-Aligned Mode and Master Duty Cycles */
PWMCON1 = PWMCON2 = PWMCON3 = 0x0300;
/* Configure Faults */
FCLCON1 = FCLCON2 = FCLCON3 = 0x0003;
/* 1:1 Prescaler */
PTCON2 = 0x0000;
/* Enable PWM Module */
PTCON = 0x8000;
Start of
PWM Cycle
PHASE1
PHASE2
PHASE3
PDC1
PDC2
PDC2
PDC3
PDC3
PWM1H
PWM1L
PWM2H
PWM2L
PWM3H
PWM3L
Complete PWM1L
and PWM1H Cycle
Where:
PHASEx Period of PWMxH and PWMxL
PDCx Duty Cycle of PWMxH and PWMxL
DTRx Dead Time before PWMxH Falling Edge
ALTDTRx Dead Time before PWMxL Falling Edge
DTR1
ALTDTR1
DTR2
ALTDTR2
DTR3
ALTDTR3
PDC1
© 2010-2011 Microchip Technology Inc. DS70645C-page 14-43
Section 14. High-Speed PWM
High-Speed PWM
14
14.6.2 Complementary PWM Mode
In Complementary PWM mode, the PWM output PWMxH is the complement of the PWMxL
output. Some typical applications of Complementary PWM mode are provided in
14.16 “Application Information”.
Figure 14-15 through Figure 14-22 and Example 14-14 through Example 14-21 show the PWM
outputs in multiple operating modes when the module operates in Complementary PWM mode.
Figure 14-15: Complementary PWM Mode – Independent Duty Cycle and Phase, Fixed Primary Period,
Edge-Aligned
Note: Not all of the features and registers listed in the Figures and Code Examples in this
section are available on all devices. Refer to the “High-Speed PWM” chapter of the
specific device data sheet for availability.
PTPER
PHASE1 = 0
PHASE2
PHASE3
PDC1
PDC2
PDC3
PWM1H
PWM1L
PWM2H
PWM2L
PWM3H
PWM3L
Start of PWM Cycle
Where: PHASEx Phase of PWMxH and PWMxL
PDCx Duty Cycle of PWMxH and PWMxL
PTPER Period of PWMxH and PWMxL
DTRx Dead Time for PWMxH Rising Edge
ALTDTRx Dead Time for PWMxL Rising Edge
DTR1
DTR2
DTR3
ALTDTR1
ALTDTR2
ALTDTR3
© 2010-2011 Microchip Technology Inc. DS70645C-page 14-45
Section 14. High-Speed PWM
High-Speed PWM
14
Example 14-15: Complementary PWM Mode – Independent Duty Cycle and Phase, Fixed Secondary Period,
Edge-Aligned
Figure 14-17: Complementary PWM Mode – Master Duty Cycle and Independent Phase, Fixed Primary
Period, Edge-Aligned
/* Set PWM Period on Secondary Time Base */
STPER = 1000;
/* Set Phase Shift */
PHASE1 = 0;
PHASE2 = 100;
PHASE3 = 200;
/* Set Duty Cycles */
PDC1 = 150;
PDC2 = 200;
PDC3 = 400;
/* Set Dead Time Values */
DTR1 = DTR2 = DTR3 = 25;
ALTDTR1 = ALTDTR2 = ALTDTR3 = 25;
/* Set PWM Mode to Complementary */
IOCON1 = IOCON2 = IOCON3 = 0xC000;
/* Set Secondary Time Base, Edge-Aligned Mode and Independent Duty Cycles */
PWMCON1 = PWMCON2 = PWMCON3 = 0x0008;
/* Configure Faults */
FCLCON1 = FCLCON2 = FCLCON3 = 0x0003;
/* 1:1 Prescaler */
PTCON2 = 0x0000;
/* Enable PWM Module */
PTCON = 0x8000;
PTPER
PHASE1 = 0
PHASE2
PHASE3
MDC
PWM1H
PWM1L
PWM2H
PWM2L
PWM3H
PWM3L
MDC
MDC
Start of
PWM Cycle
Where:
PHASEx Phase of PWMxH and PWMxL
PDCx Duty Cycle of PWMxH and PWMxL
PTPER Period of PWMxH and PWMxL
DTRx Dead Time for PWMxH Rising Edge
ALTDTRx Dead Time for PWMxL Rising Edge
DTR1
DTR2
DTR3
ALTDTR1
ALTDTR2
ALTDTR3
© 2010-2011 Microchip Technology Inc. DS70645C-page 14-47
Section 14. High-Speed PWM
High-Speed PWM
14
Example 14-17: Complementary PWM Mode – Master Duty Cycle and Independent Phase, Fixed Secondary
Period, Edge-Aligned
Figure 14-19: Complementary PWM Mode – Independent Duty Cycles and Independent Periods, No
Phase-Shifting, Edge-Aligned
/* Set PWM Period on Secondary Time Base*/
STPER = 1000;
/* Set Phase Shift */
PHASE1 = 0;
PHASE2 = 100;
PHASE3 = 200;
/* Set Duty Cycles */
MDC = 200;
/* Set Dead Time Values */
DTR1 = DTR2 = DTR3 = 25;
ALTDTR1 = ALTDTR2 = ALTDTR3 = 25;
/* Set PWM Mode to Complementary */
IOCON1 = IOCON2 = IOCON3 = 0xC000;
/* Set Secondary Time Base, Edge-Aligned Mode and Master Duty Cycles */
PWMCON1 = PWMCON2 = PWMCON3 = 0x0108;
/* Configure Faults */
FCLCON1 = FCLCON2 = FCLCON3 = 0x0003;
/* 1:1 Prescaler */
PTCON2 = 0x0000;
/* Enable PWM Module */
PTCON = 0x8000;
PWM1H
PWM1L
PWM2H
PWM2L
PWM3H
PWM3L
PDC1
PDC2
PDC3
PHASE1
PHASE2
PHASE3
Start of
PWM Cycle
DTR1
DTR2
DTR3
ALTDTR1
ALTDTR2
ALTDTR3
Where:
PHASEx Period of PWMxH and PWMxL
PDCx Duty Cycle of PWMxH and PWMxL
DTRx Dead Time for PWMxH Rising Edge
ALTDTRx Dead Time for PWMxL Rising Edge
dsPIC33E/PIC24E Family Reference Manual
DS70645C-page 14-48 © 2010-2011 Microchip Technology Inc.
Example 14-18: Complementary PWM Mode – Independent Duty Cycles and Independent Periods, No
Phase-Shifting, Edge-Aligned
Figure 14-20: Complementary PWM Mode – Master Duty Cycles and Independent Periods, No Phase-Shifting,
Edge-Aligned
/* Set PWM Periods on PHASEx Registers */
PHASE1 = 800;
PHASE2 = 900;
PHASE3 = 1000;
/* Set Duty Cycles */
PDC1 = 200;
PDC2 = 300;
PDC3 = 400;
/* Set Dead Time Values */
DTR1 = DTR2 = DTR3 = 25;
ALTDTR1 = ALTDTR2 = ALTDTR3 = 25;
/* Set PWM Mode to Complementary */
IOCON1 = IOCON2 = IOCON3 = 0xC000;
/* Set Independent Time Bases, Edge-Aligned Mode and Independent Duty Cycles */
PWMCON1 = PWMCON2 = PWMCON3 = 0x0200;
/* Configure Faults */
FCLCON1 = FCLCON2 = FCLCON3 = 0x0003;
/* 1:1 Prescaler */
PTCON2 = 0x0000;
/* Enable PWM Module */
PTCON = 0x8000;
PWM1H
PWM1L
PWM2H
PWM2L
PWM3H
PWM3L
MDC
PHASE1
PHASE2
PHASE3
Start of
PWM Cycle
DTR1
DTR2
DTR3
ALTDTR1
ALTDTR2
ALTDTR3
Where:
PHASEx Period of PWMxH and PWMxL
MDC Duty Cycle of PWMxH and PWMxL
DTRx Dead Time for PWMxH Rising Edge
ALTDTRx Dead Time for PWMxL Rising Edge
dsPIC33E/PIC24E Family Reference Manual
DS70645C-page 14-58 © 2010-2011 Microchip Technology Inc.
Example 14-27: Redundant PWM Mode – Master Duty Cycles and Independent Periods, No Phase-Shifting,
Edge-Aligned
Figure 14-29: Redundant PWM Mode – Independent Duty Cycles and Independent Periods, No
Phase-Shifting, Center-Aligned
/* Set PWM Periods on PHASEx Registers */
PHASE1 = 800;
PHASE2 = 900;
PHASE3 = 1000;
/* Set Duty Cycles */
MDC = 200;
/* Set Dead Time Values */
DTR1 = DTR2 = DTR3 = 0;
ALTDTR1 = ALTDTR2 = ALTDTR3 = 0;
/* Set PWM Mode to Redundant */
IOCON1 = IOCON2 = IOCON3 = 0xC400;
/* Set Independent Time Bases, Edge-Aligned Mode and Master Duty Cycles */
PWMCON1 = PWMCON2 = PWMCON3 = 0x0300;
/* Configure Faults */
FCLCON1 = FCLCON2 = FCLCON3 = 0x0003;
/* 1:1 Prescaler */
PTCON2 = 0x0000;
/* Enable PWM Module */
PTCON = 0x8000;
PDC1
PDC2
PDC3
PHASE1
PHASE2
PHASE3
PWM1H
PWM1L
PWM2H
PWM2L
PWM3H
PWM3L
Start of
PWM Cycle
Complete
PWM1H and
PWM1L Cycle
Where:
PHASEx Period of PWMxH and PWMxL
PDCx Duty Cycle of PWMxH and PWMxL
© 2010-2011 Microchip Technology Inc. DS70645C-page 14-59
Section 14. High-Speed PWM
High-Speed PWM
14
Example 14-28: Redundant PWM Mode – Independent Duty Cycles and Independent Periods, No
Phase-Shifting, Center-Aligned
Figure 14-30: Redundant PWM Mode – Master Duty Cycles and Independent Periods, No Phase-Shifting,
Center-Aligned
/* Set PWM Periods on PHASEx Registers */
PHASE1 = 1000;
PHASE2 = 900;
PHASE3 = 800;
/* Set Duty Cycles */
PDC1 = 400;
PDC2 = 300;
PDC3 = 200;
/* Set Dead Time Values */
DTR1 = DTR2 = DTR3 = 0;
ALTDTR1 = ALTDTR2 = ALTDTR3 = 0;
/* Set PWM Mode to Redundant */
IOCON1 = IOCON2 = IOCON3 = 0xC400;
/* Set Independent Time Bases, Center-Aligned Mode and Independent Duty Cycles */
PWMCON1 = PWMCON2 = PWMCON3 = 0x0204;
/* Configure Faults */
FCLCON1 = FCLCON2 = FCLCON3 = 0x0003;
/* 1:1 Prescaler */
PTCON2 = 0x0000;
/* Enable PWM Module */
PTCON = 0x8000;
MDC
MDC
PHASE1
PHASE2
PHASE3
PWM1H
PWM1L
PWM2H
PWM2L
PWM3H
PWM3L
MDC
Start of
PWM1H Cycle
Complete
PWM1H and
PWM1L Cycle
Where:
PHASEx Period of PWMxH and PWMxL
MDC Duty Cycle of PWMxH and PWMxL
dsPIC33E/PIC24E Family Reference Manual
DS70645C-page 14-60 © 2010-2011 Microchip Technology Inc.
Example 14-29: Redundant PWM Mode – Master Duty Cycles and Independent Periods,
No Phase-shifting, Center-Aligned
Table 14-2 provides PWM register functionality for the PWM modes.
Table 14-2: Complementary, Push-Pull and Redundant Mode Register Functionality
Function
Configuration in PWMCONx Pins
MDCS ITB MTBS PWMxH PWMxL
PWM Duty Cycle 0xxPDCx PDCx
1xxMDC MDC
PWM Phase Shift x0xPHASEx PHASEx
PWM Period xx0PTPER PTPER
xx1STPER STPER
x1xPHASEx PHASEx
Legend: x = don’t care
/* Set PWM Periods on PHASEx Registers */
PHASE1 = 1000;
PHASE2 = 900;
PHASE3 = 800;
/* Set Duty Cycles */
MDC = 200;
/* Set Dead Time Values */
DTR1 = DTR2 = DTR3 = 0;
ALTDTR1 = ALTDTR2 = ALTDTR3 = 0;
/* Set PWM Mode to Redundant */
IOCON1 = IOCON2 = IOCON3 = 0xC400;
/* Set Independent Time Bases, Center-Aligned Mode and Master Duty Cycles */
PWMCON1 = PWMCON2 = PWMCON3 = 0x0304;
/* Configure Faults */
FCLCON1 = FCLCON2 = FCLCON3 = 0x0003;
/* 1:1 Prescaler */
PTCON2 = 0x0000;
/* Enable PWM Module */
PTCON = 0x8000;
dsPIC33E/PIC24E Family Reference Manual
DS70645C-page 14-62 © 2010-2011 Microchip Technology Inc.
Example 14-30: Independent PWM Mode – Independent Duty Cycle and Phase, Fixed Primary Period,
Edge-Aligned
Figure 14-32: Independent PWM Mode – Independent Duty Cycle and Phase, Fixed Secondary Period,
Edge-Aligned
/* Set PWM Period on Primary Time Base */
PTPER = 1000;
/* Set Phase Shift */
PHASE1 = 0;
SPHASE1 = 100;
PHASE2 = 200;
SPHASE2 = 300;
PHASE3 = 400;
SPHASE3 = 500;
/* Set Duty Cycles */
PDC1 = 100;
SDC1 = 200;
PDC2 = 300;
SDC2 = 400;
PDC3 = 500;
SDC3 = 600;
/* Set Dead Time Values */
DTR1 = DTR2 = DTR3 = 0;
ALTDTR1 = ALTDTR2 = ALTDTR3 = 0;
/* Set PWM Mode to Independent */
IOCON1 = IOCON2 = IOCON3 = 0xCC00;
/* Set Primary Time Base, Edge-Aligned Mode and Independent Duty Cycles */
PWMCON1 = PWMCON2 = PWMCON3 = 0x0000;
/* Configure Faults */
FCLCON1 = FCLCON2 = FCLCON3 = 0x0003;
/* 1:1 Prescaler */
PTCON2 = 0x0000;
/* Enable PWM Module */
PTCON = 0x8000;
STPER
PHASE1 = 0
SPHASE1
PHASE2
SPHASE2
PHASE3
SPHASE3
PDC1
SDC1
PDC2
SDC2
PDC3
SDC3
PWM1H
PWM1L
PWM2H
PWM2L
PWM3H
PWM3L
Start of
PWM Cycle
Where: PHASEx Phase of PWMxH
SPHASEx Phase of PWMxL
PDCx Duty Cycle of PWMxH
SDCx Duty Cycle of PWMxL
STPER Period of PWMxH and PWMxL
© 2010-2011 Microchip Technology Inc. DS70645C-page 14-63
Section 14. High-Speed PWM
High-Speed PWM
14
Example 14-31: Independent PWM Mode – Independent Duty Cycle and Phase, Fixed Secondary Period,
Edge-Aligned
Figure 14-33: Independent PWM Mode – Master Duty Cycle, Variable Phase, Fixed Primary Period,
Edge-Aligned
/* Set PWM Period on Secondary Time Base */
STPER = 1000;
/* Set Phase Shift */
PHASE1 = 0;
SPHASE1 = 100;
PHASE2 = 200;
SPHASE2 = 300;
PHASE3 = 400;
SPHASE3 = 500;
/* Set Duty Cycles */
PDC1 = 100;
SDC1 = 200;
PDC2 = 300;
SDC2 = 400;
PDC3 = 500;
SDC3 = 600;
/* Set Dead Time Values */
DTR1 = DTR2 = DTR3 = 0;
ALTDTR1 = ALTDTR2 = ALTDTR3 = 0;
/* Set PWM Mode to Independent */
IOCON1 = IOCON2 = IOCON3 = 0xCC00;
/* Set Secondary Time Base, Edge-Aligned Mode and Independent Duty Cycles */
PWMCON1 = PWMCON2 = PWMCON3 = 0x0008;
/* Configure Faults */
FCLCON1 = FCLCON2 = FCLCON3 = 0x0003;
/* 1:1 Prescaler */
PTCON2 = 0x0000;
/* Enable PWM Module */
PTCON = 0x8000;
PTPER
PHASE1 = 0
SPHASE1
PHASE2
SPHASE2
PHASE3
SPHASE3
MDC
PWM1H
PWM1L
PWM2H
PWM2L
PWM3H
PWM3L
MDC
MDC
MDC
MDC
MDC
Start of
PWM Cycle
Where: PHASEx Phase of PWMxH
SPHASEx Phase of PWMxL
MDC Duty Cycle of PWMxH and PWMxL
PTPER Period of PWMxH and PWMxL
dsPIC33E/PIC24E Family Reference Manual
DS70645C-page 14-64 © 2010-2011 Microchip Technology Inc.
Example 14-32: Independent PWM Mode – Master Duty Cycle, Variable Phase, Fixed Primary Period,
Edge-Aligned
Figure 14-34: Independent PWM Mode – Master Duty Cycle, Variable Phase, Fixed Secondary Period,
Edge-Aligned
/* Set PWM Period on Primary Time Base */
PTPER = 1000;
/* Set Phase Shift */
PHASE1 = 0;
SPHASE1 = 100;
PHASE2 = 200;
SPHASE2 = 300;
PHASE3 = 400;
SPHASE3 = 500;
/* Set Duty Cycles */
MDC = 300;
/* Set Dead Time Values */
DTR1 = DTR2 = DTR3 = 0;
ALTDTR1 = ALTDTR2 = ALTDTR3 = 0;
/* Set PWM Mode to Independent */
IOCON1 = IOCON2 = IOCON3 = 0xCC00;
/* Set Primary Time Base, Edge-Aligned Mode and Master Duty Cycles */
PWMCON1 = PWMCON2 = PWMCON3 = 0x0100;
/* Configure Faults */
FCLCON1 = FCLCON2 = FCLCON3 = 0x0003;
/* 1:1 Prescaler */
PTCON2 = 0x0000;
/* Enable PWM Module */
PTCON = 0x8000;
STPER
PHASE1 = 0
SPHASE1
PHASE2
SPHASE2
PHASE3
SPHASE3
MDC
PWM1H
PWM1L
PWM2H
PWM2L
PWM3H
PWM3L
MDC
MDC
MDC
MDC
MDC
Start of
PWM Cycle
Where: PHASEx Phase of PWMxH
SPHASEx Phase of PWMxL
MDC Duty Cycle of PWMxH and PWMxL
STPER Period of PWMxH and PWMxL
dsPIC33E/PIC24E Family Reference Manual
DS70645C-page 14-66 © 2010-2011 Microchip Technology Inc.
Figure 14-35: Independent PWM Mode – Independent Duty Cycles and Periods, No Phase-Shifting,
Edge-Aligned
Example 14-34: Independent PWM Mode – Independent Duty Cycles and Periods, No Phase-Shifting,
Edge-Aligned
PWM1H
PWM1L
PWM2H
PWM2L
PWM3H
PWM3L
PDC1
SDC1
PDC2
SDC2
PDC3
SDC3
PHASE1
SPHASE1
PHASE2
SPHASE2
PHASE3
SPHASE3
Start of
PWM Cycle
Where: PHASEx Period of PWMxH
SPHASEx Period of PWMxL
PDCx Duty Cycle of PWMxH
SDCx Duty Cycle of PWMxL
/* Set PWM Periods on PHASEx Registers */
PHASE1 = 800;
SPHASE1 = 900;
PHASE2 = 1000;
SPHASE2 = 1100;
PHASE3 = 1200;
SPHASE3 = 1300;
/* Set Duty Cycles */
PDC1 = 200;
SDC1 = 300;
PDC2 = 400;
SDC2 = 500;
PDC3 = 600;
SDC3 = 700;
/* Set Dead Time Values */
DTR1 = DTR2 = DTR3 = 0;
ALTDTR1 = ALTDTR2 = ALTDTR3 = 0;
/* Set PWM Mode to Independent */
IOCON1 = IOCON2 = IOCON3 = 0xCC00;
/* Set Independent Time Bases, Edge-Aligned Mode and Independent Duty Cycles */
PWMCON1 = PWMCON2 = PWMCON3 = 0x0200;
/* Configure Faults */
FCLCON1 = FCLCON2 = FCLCON3 = 0x0003;
/* 1:1 Prescaler */
PTCON2 = 0x0000;
/* Enable PWM Module */
PTCON = 0x8000;
© 2010-2011 Microchip Technology Inc. DS70645C-page 14-67
Section 14. High-Speed PWM
High-Speed PWM
14
Figure 14-36: Independent PWM Mode – Master Duty Cycles, Independent Periods, No Phase-Shifting,
Edge-Aligned
Example 14-35: Independent PWM Mode – Master Duty Cycles, Independent Periods, No Phase-Shifting,
Edge-Aligned
PWM1H
PWM1L
PWM2H
PWM2L
PWM3H
PWM3L
MDC
PHASE1
SPHASE1
PHASE2
SPHASE2
PHASE3
SPHASE3
Start of
PWM Cycle
Where: PHASEx Period of PWMxH
SPHASEx Period of PWMxL
MDC Duty Cycle of PWMxH and PWMxL
/* Set PWM Periods on PHASEx Registers */
PHASE1 = 800;
SPHASE1 = 900;
PHASE2 = 1000;
SPHASE2 = 1100;
PHASE3 = 1200;
SPHASE3 = 1300;
/* Set Duty Cycles */
MDC = 200;
/* Set Dead Time Values */
DTR1 = DTR2 = DTR3 = 0;
ALTDTR1 = ALTDTR2 = ALTDTR3 = 0;
/* Set PWM Mode to Independent */
IOCON1 = IOCON2 = IOCON3 = 0xCC00;
/* Set Independent Time Bases, Edge-Aligned Mode and Master Duty Cycles */
PWMCON1 = PWMCON2 = PWMCON3 = 0x0300;
/* Configure Faults */
FCLCON1 = FCLCON2 = FCLCON3 = 0x0003;
/* 1:1 Prescaler */
PTCON2 = 0x0000;
/* Enable PWM Module */
PTCON = 0x8000;
© 2010-2011 Microchip Technology Inc. DS70645C-page 14-69
Section 14. High-Speed PWM
High-Speed PWM
14
Figure 14-38: Independent PWM Mode – Master Duty Cycles, Independent Periods, No Phase-Shifting,
Center-Aligned
Example 14-37: Independent PWM Mode – Master Duty Cycles, Independent Periods, No Phase-Shifting,
Center-Aligned
MDC
MDC
MDC
PHASE1
SPHASE1
PHASE2
SPHASE2
PHASE3
SPHASE3
PWM1H
PWM1L
PWM2H
PWM2L
PWM3H
PWM3L
MDC
MDC
MDC
Start of
PWM1H Cycle
Complete
PWM1H Cycle
Where: PHASEx Period of PWMxH
SPHASEx Period of PWMxL
MDC Duty Cycle of PWMxH and PWMxL
/* Set PWM Periods on PHASEx Registers */
PHASE1 = 1300;
SPHASE1 = 1200;
PHASE2 = 1100;
SPHASE2 = 1000;
PHASE3 = 900;
SPHASE3 = 800;
/* Set Duty Cycles */
MDC = 700;
/* Set Dead Time Values */
DTR1 = DTR2 = DTR3 = 0;
ALTDTR1 = ALTDTR2 = ALTDTR3 = 0;
/* Set PWM Mode to Independent */
IOCON1 = IOCON2 = IOCON3 = 0xCC00;
/* Set Independent Time Bases, Center-Aligned Mode and Master Duty Cycles */
PWMCON1 = PWMCON2 = PWMCON3 = 0x0304;
/* Configure Faults */
FCLCON1 = FCLCON2 = FCLCON3 = 0x0003;
/* 1:1 Prescaler */
PTCON2 = 0x0000;
/* Enable PWM Module */
PTCON = 0x8000;
© 2010-2011 Microchip Technology Inc. DS70645C-page 14-71
Section 14. High-Speed PWM
High-Speed PWM
14
14.7 PWM GENERATOR
This section describes the functionality of the PWM generator.
14.7.1 PWM Period
The PWM period value defines the switching frequency of the PWM pulses. The PWM period
value can be controlled by the Primary Master Time Base Period register (PTPER), or by the
Independent Time Period PHASEx and SPHASEx registers for the respective primary and
secondary PWM outputs, if available.
The PWM period value can be controlled in two ways when the High-Speed PWM module
operates in Independent Time Base mode:
In some modes, the PHASEx register controls the PWM period value of the PWM output
signals (PWMxH and PWMxL)
In True Independent Output mode, the PHASEx register controls the PWM period value of
the PWMxH output signal, and the SPHASEx register controls the PWM period value of the
PWMxL output signal
Refer to 14.6 “PWM Operating Modes”, for detailed information about various PWM modes and
their features.
When the High-Speed PWM module operates in Master Time Base mode, the PTPER register
holds the 16-bit value, which specifies the counting period for the PMTMR timer. When the
High-Speed PWM module operates in Independent Time Base mode, the PHASEx and
SPHASEx registers hold the 16-bit value that sp riod for the PTMRx andecifies the counting pe
STMRx timer, respectively. The timer period can be updated at any time by the user-assigned
application. The PWM time period (PTPER) in Edge-Aligned PWM mode (CAM bit
(PWMCONx<2>) is set to ‘0’) can be determined by using the Equation 14-1.
Equation 14-1: PERIOD, PHASEx and SPHASEx Register Value Calculation for
Edge-Aligned Mode
Based on Equation 14-1, while operating in the master time base (PTPER register) or the
independent time base (PHASEx and SPHASEx registers), the register value to be loaded is
shown in Example 14-38.
Example 14-38: PWM Time Period Calculation for Edge-Aligned Mode
Note: Not all registers and features listed in this section are available on all devices. Refer
to the “High-Speed PWM” chapter in the specific device data sheet for availability.
Where:
PTPER, PHASEx,
SPHASEx =
FPWM
* PWM Input Clock Prescaler
FOSC
FPWM = Desired PWM frequency
FOSC = Oscillator output (120 MHz for 60 MIPS)
PWM Input Clock Prescaler = Value defined in the PCLKDIV<2:0> bits (PTCON2<2:0)
PTPER 120MHz
20 1kHz ×
-------------------------- 6000= =
Where:
PWM Input Clock Prescaler = 1:1
System Oscillator Frequency (FOSC) = 120 MHz
Desired PWM Switching Frequency = 20 kHz
dsPIC33E/PIC24E Family Reference Manual
DS70645C-page 14-72 © 2010-2011 Microchip Technology Inc.
The PWM time period (PHASEx or SPHASEx) in Center-Aligned mode (CAM = 1 and ITB = 1),
can be determined using Equation 14-2. The PTPER register does not represent the period in
Center-Aligned mode, since this mode requires independent time bases, which are enabled by
setting ITB = 1.
Equation 14-2: PHASEx or SPHASEx Register Value Calculation in Center-Aligned
Mode
Based on Equation 14-2, when operating in independent time bases (PHASEx and SPHASEx
registers), the register value to be loaded is shown in Example 14-39.
Example 14-39: PWM Time Period Calculation Example in Center-Aligned Mode
The maximum available PWM period resolution is TOSC for Edge-Aligned mode and TOSC * 2 in
Center-Aligned mode. The PCLKDIV<2:0> bits (PTCON2<2:0>), determine the type of PWM
clock. The timer/counter is enabled or disabled by setting or clearing the PTEN bit
(PTCON<15>). The PMTMR timer can also be cleared using the PTEN bit.
If the EIPU bit (PTCON<10>) is set, the active master period register (an internal shadow
register) is updated immediately instead of waiting for the PWM cycle to end. The EIPU bit affects
the PMTMR master time base.
Example 14-40: Clock Prescaler Selection
Example 14-41: PWM Time Period Selection
Example 14-42: PWM Time Period Initialization
PHASEx, SPHASEx FOS C
FPWM PWM Input Clock Prescaler 2⋅ ⋅
-----------------------------------------------------------------------------------------------------=
PHASEx, SPHASEx 120 MHz
20 kHz 1 2⋅ ⋅
------------------------------------- 3000==
Where:
PWM Frequency (FPWM) = 20 kHz
PWM Input Clock Prescaler = 1:1
System Oscillator Frequency (FOSC) = 120 MHz
/* Select PWM time base input clock prescaler */
/* Choose divide ratio of 1:2 */
PTCON2bits.PCLKDIV = 1;
/* Select Time Base Period Control */
/* Choose one of these options */
PWMCON1bits.ITB = 0; /* PTPER provides the PWM time period value */
PWMCON1bits.ITB = 1; /* PHASEx/SPHASEx provides the PWM time period value */
/* Choose PWM time period based on FRC input clock */
/* PWM frequency is 100 kHz */
/* Choose one of the following options */
PTPER = 4808;
PHASEx = 4808;
SPHASEx = 4808;
© 2010-2011 Microchip Technology Inc. DS70645C-page 14-73
Section 14. High-Speed PWM
High-Speed PWM
14
14.7.2 PWM Duty Cycle Control
The duty cycle determines the period of time the PWM output should remain in the active state.
Each duty cycle register allows a 16-bit duty cycle value to be specified. The duty cycle values
can be updated at any time by setting the IUE bit (PWMCONx<0>). If the IUE bit is 0’, the active
register updates at the start of the next PWM cycle.
The Master Duty Cycle register (MDC) enables multiple PWM generators to share a common
duty cycle register.The MDC register has an important role in Master Time Base mode.
In addition, each PWM generator has a Primary Duty Cycle register (PDCx) and on certain
devices, a Secondary Duty Cycle register (SDCx) that provides separate duty cycles to each
PWM.
14.7.2.1 MASTER DUTY CYCLE (MDC)
The master time base generator controls the master duty cycle. The MDCS bit (PWMCONx<8>),
determines whether the duty cycle of each of the PWMxH and PWMxL outputs are controlled by
the PWM Master Duty Cycle register (MDC) or the PWM Primary Duty Cycle (PDCx) and PWM
Secondary Duty Cycle (SDCx) registers.
The MDC register enables sharing of the common duty cycle register among multiple PWM
generators and saves the CPU overhead required in updating multiple duty cycle registers.
14.7.2.2 PRIMARY DUTY CYCLE (PDCx)
The independent time base controls the primary duty cycle when the ITB bit (PWMCONx<9>) is
set to 1’. The PDCx register is an input register that provides the duty cycle value for the primary
PWM output signal (PWMxH).
Figure 14-39: Primary Duty Cycle Comparison
PDCx Register
PMTMR
Compare Logic PWMx Signal
0
15
15
MUX
MDC Register
MDCS Select
0 1
CLK
15
0
0
<=
Note: In Independent Output mode, PDCx affects PWMxH only.
dsPIC33E/PIC24E Family Reference Manual
DS70645C-page 14-74 © 2010-2011 Microchip Technology Inc.
14.7.2.3 SECONDARY DUTY CYCLE (SDCx)
The independent time base in the PWMCONx register controls the Secondary Duty Cycle
register (SDCx) when the ITB bit is set to ‘1’. The SDCx register is an input register that provides
the duty cycle value for the secondary PWM output signal (PWMxL).
Figure 14-40: Secondary Duty Cycle Comparison
The duty cycle can be determined by using Equation 14-3.
Equation 14-3: MDC, PDCx and SDCx Calculation
Based on Equation 14-3, when the master, independent primary, or independent secondary duty
cycle is used, the register value SDCx register, respectively.is loaded in the MDC, PDCx, or
Note: The SDCx register is not available on all devices. Refer to the “High-Speed PWM”
chapter of the specific device data sheet for availability.
Note 1: If a duty cycle value is greater than or equal to the period value, a signal will have
a duty cycle of 100 percent.
2: When dead time compensation is disabled if PDCx does not adhere to (PDCx >
((ALTDTRx/2) -1)) the PWMxH will be constantly high.
3: If PDCx > (ALTDTRx + DTRx - 1) condition is not satisfied it could result in one or
both of the below:
a) Loss of dead time.
b) PWMxH will be constantly high.
SDCx Register
STMRx
Compare Logic PWMx Signal
015
15
MUX
MDC Register
MDCS Select
0 1
Clk
15
0
0
<=
Note: In Independent Output mode, SDCx affects PWMxL only.
MDC, PDCx, and SDCx FOSC
FPWM PWM Input Clock Prescaler
------------------------------------------------------------------------------------------- Desired Duty Cycle=
Where:
FPWM = PWM Frequency
FOSC = System Oscillator Output
PWM Input Clock Prescaler = Value defined in the PCLKDIV<2:0> bits (PTCON<2:0>)
Desired Duty Cycle = Value between 0 and 1 for desired duty cycle
© 2010-2011 Microchip Technology Inc. DS70645C-page 14-75
Section 14. High-Speed PWM
High-Speed PWM
14
14.7.2.4 DUTY CYCLE RESOLUTION
The PWM duty cycle bit resolution for Edge-Aligned mode can be determined using
Equation 14-4, and the PWM duty cycle bit resolution for Center-Aligned mode can be
determined using Equation 14-5.
Equation 14-4: Bit Resolution Calculation for Edge-Aligned Mode
Equation 14-5: Bit Resolution Calculation for Center-Aligned Mode
Example 14-43: PWM Duty Cycle Selection
Example 14-44: PWM Duty Cycle Initialization
Bit Resolution 2FOSC
FPWM PWM Input Clock Prescaler
-------------------------------------------------------------------------------------------
log=
Bit Resolution 2FOSC
FPWM PWM Input Clock Prescaler 2⋅ ⋅
-----------------------------------------------------------------------------------------------------
log=
PWMCON1bits.MDCS = 0; /* PDCx/SDCx provides duty cycle value */
PWMCON1bits.MDCS = 1; /* MDC provides duty cycle value */
/* Initialize PWM Duty Cycle Value */
PDC1 = 2404; /* Independent Primary Duty Cycle is 50% of the period */
SDC1 = 2404; /* Independent Secondary Duty Cycle is 50% of the period */
MDC = 2404; /* Master Duty Cycle is 50% of the period */
dsPIC33E/PIC24E Family Reference Manual
DS70645C-page 14-78 © 2010-2011 Microchip Technology Inc.
14.7.4.1 POSITIVE DEAD TIME
The Positive Dead Time mode describes a period of time when both PWMxH and PWMxL
outputs are not asserted. This mode is useful when the application designer needs to allocate
time to disable some power transistors prior to enabling other transistors. This is similar to a
“Break before Make” switch. When Positive Dead Time mode is specified in Edge-Aligned PWM
mode (CAM = 0), the DTRx register specifies the dead time for the PWMxH output, and the
ALTDTRx register specifies the dead time for the PWMxL output. When Center-Aligned mode is
enabled (CAM = 1), the ALTDTR register specifies the dead time, while the DTRx register is
ignored. These two modes are shown in Figure 14-43 and Figure 14-44.
Figure 14-43: Positive Dead Time in Edge-Aligned Mode and Complementary Mode
Figure 14-44: Positive Dead Time in Center-Aligned Mode and Complementary Mode
14.7.4.2 NEGATIVE DEAD TIME
The Negative Dead Time mode describes a period of time when both PWMxH and PWMxL
outputs are asserted. This mode is useful in current fed topologies that need to provide a path
for current to flow when the power transistors are switching. This is similar to a “Make before
Break” switch. When Negative Dead Time mode is specified in Edge-Aligned mode, the DTRx
register specifies the negative dead time for the PWMxL output, and the ALTDTRx register
specifies the negative dead time for the PWMxH output. When Center-Aligned mode is enabled
(CAM = 1), negative dead time is not supported, and the ALTDTRx and DTRx registers are
ignored. This mode is shown in Figure 14-45.
Figure 14-45: Negative Dead Time in Edge-Aligned Mode and Complementary Mode
PWMxH
PWMxL
Start of
PWM Cycle
DTRx
PDCx or MDC
ALTDTRx
Period Register (PTPER,
STPER or PHASEx)
PWMxH
PWMxL
Start of
PWM Cycle
PDCx or MDC
-ALTDTRx/2
Period Register (PTPER,
STPER or PHASEx)
ALTDTRx/2
Complete PWMxH
and PWMxL Cycle
ALTDTRx/2
ALTDTRx/2ALTDTRx/2
PWMxH
PWMxL
Start of
PWM Cycle
DTRx
PDCx or MDC
ALTDTRx
Period Register (PTPER,
STPER or PHASEx)
© 2010-2011 Microchip Technology Inc. DS70645C-page 14-79
Section 14. High-Speed PWM
High-Speed PWM
14
14.7.4.3 DEAD TIME COMPENSATION
When dead time is applied to the PWM signals in AC motor control applications, the transistors
are disabled. During dead time, motor current continues to flow through the free-wheeling
diodes, but the applied voltage is zero. The zero applied voltage during dead time causes a
distortion of the desired voltage waveform and subsequently a motor current distortion. This
distortion causes torque variations that can affect the stability of the control system, and the
performance of the motor.
Dead Time Compensation mode enables an external signal (DTCMPx) to modify the duty cycle
to overcome motor current distortion caused by the dead time.
When Dead Time Compensation mode is selected via the DTC<1:0> bits (PWMCONx<7:6>), an
external input signal (DTCMPx) will cause the value in the DTRx register to be added to, or
subtracted from, the duty cycle specified by the PDCx or MDC registers. The ALTDTRx register
will specify the dead time for both the PWMxH and PWMxL output signals.
Dead time compensation is available only for Complementary PWM output mode with Positive
Dead Time mode. Negative dead times or any other PWM output mode are not supported by
Dead Time Compensation mode.
Figure 14-46: Dead Time Compensation in Edge-Aligned Mode (DTCMPx Pin = 0 and DTCP = 0 or DTCMPx
Pin = 1 and DTCP = 1)
PWMxH
PWMxL
Start of
PWM Cycle
PDCx
DTRx
PDCx – DTRx
ALTDTRx = 0
PDCx – DTRx
– ALTDTRx
ALTDTRx ALTDTRx
PWMxH
PWMxL
PWMxH
PWMxL
Period Register (PTPER, STPER or PHASEx)
DTRx = 0
ALTDTRx = 0
DTRx 0
ALTDTRx = 0
DTRx 0
ALTDTRx 0
© 2010-2011 Microchip Technology Inc. DS70645C-page 14-81
Section 14. High-Speed PWM
High-Speed PWM
14
Figure 14-48: Dead Time Compensation in Center-Aligned Mode (DTCMPx Pin = 0 and DTCP = 0 or DTCMPx
Pin = 1 and DTCP = 1)
PWMxH
PWMxL
Start of
PWM Cycle
PDCx
DTRx
PDCx – DTRx
ALTDTRx = 0
PWMxH
PWMxL
PWMxH
PWMxL
Period Register PHASEx
Complete PWMxH and PWMxL Cycle
ALTDTRx/2 ALTDTRx/2
PDCx – DTRx
ALTDTRx/2
DTRx = 0
ALTDTRx = 0
DTRx 0
ALTDTRx = 0
DTRx 0
ALTDTRx 0
ALTDTRx/2
dsPIC33E/PIC24E Family Reference Manual
DS70645C-page 14-84 © 2010-2011 Microchip Technology Inc.
14.7.8 Phase Shift
Phase shift is the relative offset between PWMxH or PWMxL with respect to the master time
base. In Independent Output mode, the PHASEx register determines the relative phase shift
between PWMxH and the master time base. The SPHASEx register determines the relative
phase shift between PWMxL and the master time base. The contents of the PHASEx register are
used as an initialization value for the PTMRx register, and the SPHASEx register contents are
used as an initialization value for the STMRx register.
Figure 14-51 and Figure 14-52 provide example waveforms for phase shifting in Complementary
mode and Independent Output mode, respectively.
Figure 14-51: Phase Shifting (Complementary Mode)
Figure 14-52: Phase Shifting (Independent Output Mode)
In addition, there are two shadow registers for the PHASEx and SPHASEx registers that are
updated whenever new values are written by the user-assigned application. These values are
transferred from the shadow registers to the PHASEx and SPHASEx registers on an
independent time base Reset. The actual application of these phase offsets on the PWM output
will occur on a master time base Reset.
Note: The SPHASEx register is not available on all devices. Refer to the “High-Speed
PWM” chapter in the specific device data sheet for availability.
PWMxH without Phase Shift
PWMxH with Phase Shift
PWMxL without Phase Shift
PWMxL with Phase Shift
PHASEx
PWMxH without Phase Shift
PWMxH with Phase Shift
PWMxL without Phase Shift
PWMxL with Phase Shift
(Different Duty Cycle)
PHASEx
SPHASEx


Produkt Specifikationer

Mærke: Microchip
Kategori: Ikke kategoriseret
Model: dsPIC33EV256GM003

Har du brug for hjælp?

Hvis du har brug for hjælp til Microchip dsPIC33EV256GM003 stil et spørgsmål nedenfor, og andre brugere vil svare dig




Ikke kategoriseret Microchip Manualer

Ikke kategoriseret Manualer

Nyeste Ikke kategoriseret Manualer