Section 15. Motor Control PWM: Highlights
Section 15. Motor Control PWM: Highlights
Section 15. Motor Control PWM: Highlights
HIGHLIGHTS
This section of the manual contains the following topics:
15
Motor Control
PWM
15.1 Introduction
The motor control PWM (MCPWM) module simplifies the task of generating multiple,
synchronized pulse width modulated outputs. In particular, the following power and motion
control applications are supported:
• Three-Phase AC Induction Motor
• Switched Reluctance (SR) Motor
• Brushless DC (BLDC) Motor
• Uninterruptable Power Supply (UPS)
The PWM module has the following features:
• Dedicated time base supports TCY/2 PWM edge resolution
• Two output pins for each PWM generator
• Complementary or independent operation for each output pin pair
• Hardware dead time generators for complementary mode
• Output pin polarity programmed by device configuration bits
• Multiple output modes:
- Edge aligned mode
- Center aligned mode
- Center aligned mode with double updates
- Single event mode
• Manual override register for PWM output pins
• Duty cycle updates are configurable to be immediate or synchronized to the PWM
• Hardware fault input pins with programmable function
• Special Event Trigger for synchronizing A/D conversions
• Each output pin associated with the PWM can be individually enabled
The 6-output MCPWM module is useful for single or 3-phase power application, while the 8
MCPWM can support 4-phase motor applications. Table 15-1 provides a feature summary for
6- and 8-output MCPWM modules. Both modules can support multiple single phase loads. The
8-output MCPWM also provides increased flexibility in an application because it supports two
fault pins and two programmable dead times. These features are discussed in greater detail in
subsequent sections.
A simplified block diagram of the MCPWM module is shown in Figure 15-1.
PWMCON1
PWM enable and mode SFRs
PWMCON2
DTCON1
Dead time control SFRs
DTCON2
FLTACON
Fault pin control SFRs
FLTBCON
PWM Generator #1
PDC1
16-bit data bus
Channel 1
Comparator Dead Time PWM1H
Generator and
Override Logic PWM1L
Comparator
PWM Generator Channel 3 PWM3H
#3 Dead Time
Generator and PWM3L
PTMR period register
Override Logic
FLTA
FLTB
Special Event
Comparator Postscaler Special Event Trigger for A/D converter
SEVTCMP 15
Motor Control
PWM
Note 1: Details of PWM Generator #2, #3 and #4 not shown for clarity.
2: Logic within dashed lines not present on 6-output MCPWM module.
Lower Byte:
R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0
PTOPS<3:0> PTCKPS<1:0> PTMOD<1: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
15
Motor Control
PWM
Lower Byte:
R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0
PTMR <7:0>
bit 7 bit 0
bit 15 PTDIR: PWM Time Base Count Direction Status bit (Read Only)
1 = PWM time base is counting down
0 = PWM time base is counting up
bit 14-0 PTMR <14:0>: PWM Timebase Register Count Value
Legend:
R = Readable bit W = Writable bit U = Unimplemented, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Lower Byte:
R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0
PTPER <7:0>
bit 7 bit 0
Legend:
R = Readable bit W = Writable bit U = Unimplemented, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Lower Byte:
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, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Lower Byte:
R/W-1 R/W-1 R/W-1 R/W-1 R/W-1 R/W-1 R/W-1 R/W-1
PEN4H PEN3H PEN2H PEN1H PEN4L PEN3L PEN2L PEN1L
bit 7 bit 0
Note 1: Reset condition of the PENxH and PENxL bits depend on the value of the PWM/PIN device
configuration bit in the FBORPOR Device Configuration Register.
PWM
Legend:
R = Readable bit W = Writable bit U = Unimplemented, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Lower Byte:
U-0 U-0 U-0 U-0 U-0 R/W-0 R/W-0 R/W-0
— — — — — IUE OSYNC UDIS
bit 7 bit 0
Lower Byte:
R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0
DTAPS<1:0> DTA<5:0>
bit 7 bit 0
Legend:
R = Readable bit W = Writable bit U = Unimplemented, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
15
Motor Control
PWM
Lower Byte:
R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0
DTS4A DTS4I DTS3A DTS3I DTS2A DTS2I DTS1A DTS1I
bit 7 bit 0
Legend:
R = Readable bit W = Writable bit U = Unimplemented, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Lower Byte:
R/W-0 U-0 U-0 U-0 R/W-0 R/W-0 R/W-0 R/W-0
FLTAM — — — FAEN4 FAEN3 FAEN2 FAEN1
bit 7 bit 0
Legend:
R = Readable bit W = Writable bit U = Unimplemented, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
15
Motor Control
PWM
Lower Byte:
R/W-0 U-0 U-0 U-0 R/W-0 R/W-0 R/W-0 R/W-0
FLTBM — — — FBEN4 FBEN3 FBEN2 FBEN1
bit 7 bit 0
Legend:
R = Readable bit W = Writable bit U = Unimplemented, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Lower Byte:
R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0
POUT4H POUT4L POUT3H POUT3L POUT2H POUT2L POUT1H POUT1L
bit 7 bit 0
Legend:
R = Readable bit W = Writable bit U = Unimplemented, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Lower Byte:
R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0
PWM Duty Cycle #1 bits 7-0
bit 7 bit 0
Legend:
R = Readable bit W = Writable bit U = Unimplemented, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
15
Motor Control
PWM
Lower Byte:
R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0
PWM Duty Cycle #2 bits 7-0
bit 7 bit 0
Legend:
R = Readable bit W = Writable bit U = Unimplemented, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Lower Byte:
R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0
PWM Duty Cycle #3 bits 7-0
bit 7 bit 0
Legend:
R = Readable bit W = Writable bit U = Unimplemented, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Lower Byte:
R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0
PWM Duty Cycle #4 bits 7-0
bit 7 bit 0
Legend:
R = Readable bit W = Writable bit U = Unimplemented, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Middle Byte:
U-0 U-0 U-0 U-0 U-0 R/P R/P R/P
— — — — — PWMPIN HPOL LPOL
bit 15 bit 8
Lower Byte:
R/P U-0 R/P R/P U-0 U-0 R/P R/P
BOREN — BORV<1:0> — — FPWRT<1:0>
bit 7 bit 0
Legend:
R = Readable bit W = Writable bit U = Unimplemented, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
P = Programmable configuration bit
Zero match
Period match PTEN
Clock
PTMOD1
Control
PTMOD0
TCY Prescaler
1:1, 1:4, 1:16, 1:64
Timer reset
Up/Down
Gated
Time Base period register Duty Cycle
Load
Gated Period load Immediate
Period load
Update
Enable (IUE)
PTPER
Zero Postscaler
match 1:1-1:16
Interrupt
PTIF
Control
Period
match
PTMOD1
PTMOD0
The PWM time base can be configured for four different modes of operation:
1. Free Running mode
2. Single Event mode
3. Continuous Up/Down Count mode
4. Continuous Up/Down Count mode with interrupts for double-updates.
These four modes are selected by the PTMOD<1:0> control bits (PTCON<1:0>).
Note: The mode of the PWM time base determines the type of PWM signal that is
generated by the module. (See Section 15.4.2, Section 15.4.3 and Section 15.4.4
for more details.)
15
Motor Control
PWM
Figure 15-3: PWM Period Buffer Updates in Free Running Count Mode
PTMR Value
New PTPER value
FCY
PTPER = -1
FPWM • (PTMR Prescaler)
Example:
FCY = 20 MHz
FPWM = 20,000 Hz
PTMR Prescaler = 1:1
20,000,000
PTPER = -1
20,000 • 1
= 1000 -1
= 999
FCY
PTPER = -1
FPWM • (PTMR Prescaler) • 2
Example:
FCY = 20 MHz
FPWM = 20,000 Hz
PTMR Prescaler = 1:1
20,000,000
PTPER = -1
20,000 • 1 • 2
= 500 -1
= 499
log ⎛⎝ ------------------⎞⎠
2T PWM
T CY
Resolution = --------------------------------
log ( 2 )
The PWM resolutions and frequencies are shown in Table 15-2 for a selection of execution
speeds and PTPER values. The PWM frequencies in Table 15-2 are for edge-aligned (Free
Running PTMR) PWM mode. For center aligned modes (Up/Down PTMR mode), the PWM
frequencies will be 1/2 the values as indicated in Table 15-3.
Table 15-2: Example PWM Frequencies and Resolutions, 1:1 Prescaler, Edge Aligned
PWM
PDCx Value for PWM
TCY (FCY) PTPER Value PWM Frequency
100% Resolution
33 ns (30 MHz) 0x7FFF 0xFFFF 16 bits 915 Hz
33 ns (30 MHz) 0x3FF 0x7FF 11 bits 29.3 kHz
50 ns (20 MHz) 0x7FFF 0xFFFF 16 bits 610 Hz
50 ns (20 MHz) 0x1FF 0x3FF 10 bits 39.1 kHz
100 ns (10 MHz) 0x7FFF 0xFFFF 16 bits 305 Hz
100 ns (10 MHz) 0xFF 0x1FF 9 bits 39.1 kHz
200 ns (5 MHz) 0x7FFF 0xFFFF 16 bits 153 Hz
200 ns (5 MHz) 0x7F 0xFF 8 bits 39.1 kHz
Table 15-3: Example PWM Frequencies and Resolutions, 1:1 Prescaler, Center
Aligned PWM
PDCx Value for PWM
TCY (FCY) PTPER Value PWM Frequency
100% Resolution
33 ns (30 MHz) 0x7FFF 0xFFFF 16 bits 458 Hz
33 ns (30 MHz) 0x3FFF 0x7FFF 15 bits 916 Hz
50 ns (20 MHz) 0x7FFF 0xFFFF 16 bits 305 Hz
50 ns (20 MHz) 0x1FFF 0x3FFF 14 bits 1.22 kHz
100 ns (10 MHz) 0x7FFF 0xFFFF 16 bits 153 Hz
100 ns (10 MHz) 0xFFF 0x1FFF 13 bits 1.22 kHz
200 ns (5 MHz) 0x7FFF 0xFFFF 16 bits 76.3 Hz
200 ns (5 MHz) 0x7FF 0xFFF 12 bits 1.22 kHz
The MCPWM module has the ability to produce PWM signal edges with TCY/2 resolution. PTMR
increments every TCY with a 1:1 prescaler. To achieve TCY/2 edge resolution, PDCx<15:1> is
compared to PTMR<14:0> to determine a duty cycle match. PDCx<0> determines whether the
PWM signal edge will occur at the TCY or the TCY/2 boundary. When a 1:4, 1:16 or a 1:64
prescaler is used with the PWM time base, PDCx<0> is compared to the MSbit of the prescaler
counter clock to determine when the PWM edge should occur.
PTMR and PDCx resolutions are depicted in Figure 15-5. It is shown that PTMR resolution is TCY
and PDCx resolution is TCY/2 for 1:1 prescaler selection.
Figure 15-5: PTMR and PDCx Resolution Timing Diagram. Free Running Mode and 1:1
Prescaler Selection
TCY
PTPER = 10
TCY
PTMR
PDCx = 14 TCY/2
PDCx = 15
15
Motor Control
PWM
14 0 N-bit Prescaler
PTMR N 2 1 TCY
15
15-bit Edge
PWM Edge Event
comparison Logic
15 15 1 0 1-Bit Comparison
PDCx
Note: PDCx<0> is compared to the FOSC/2 signal when the prescaler is 1:1.
PTPER
PDC2
PWM2H
Period
PDC1
PDC2
PTEN
PWM2H
PWM1H
PWMIF
15
Motor Control
PWM
Period/2
PTPER
PTMR
PDC1 Value
PDC2
PWM1H
PWM2H
PDCx
Value
Period
Note: Any write to the PDCx registers will immediately update the duty cycle when the
PWM time base is disabled (PTEN = 0). This allows a duty cycle change to take
effect before PWM signal generation is enabled.
When the PWM time base is operating in the Up/Down Counting mode (PTMOD<1:0> = 10),
duty cycles are updated when the value of the PTMR register is zero and the PWM time base
begins to count upwards. Figure 15-10 indicates the times when the duty cycle updates occur
for this mode of the PWM time base.
When the PWM time base is in the Up/Down Counting mode with double updates
(PTMOD<1:0> = 11), duty cycles are updated when the value of the PTMR register is zero and
when the value of the PTMR register matches the value in the PTPER register. Figure 15-11
indicates the times when the duty cycle updates occur for this mode of the PWM time base.
PWM output
PTMR Value
PTIF
Figure 15-11: Duty Cycle Update Times in Up/Down Count Mode with Double Updates
PWM output
PTMR Value
Figure 15-12: Duty Cycle Update Times When Immediate Updates Are Enabled (IUE = 1)
PWM Output
PTMR Value
+V
3 Phase
1H 2H 3H Load
1L 2L 3L
The Complementary mode is selected for each PWM I/O pin pair by clearing the appropriate
PMODx bit in PWMCON1. The PWM I/O pins are set to complementary mode by default upon a
device reset.
Figure 15-15: Dead Time Unit Block Diagram for One Output Pin Pair
Zero Compare
Dead Time
Select Logic
PWM
Generator
Input
PWM Generator
PWMxH
Dead time = 0
PWMxL
PWMxH
Non-zero
dead time
PWMxL
Note: The dead time assignment logic is only applicable to dsPIC variants that contain the
8-output PWM module. The 6-output PWM module uses dead time A only.
The DTCON2 register contains control bits that allow the two programmable dead times to be
assigned to each of the complementary outputs. There are two dead time assignment control
bits for each of the complementary outputs. For example, the DTS1A and DTS1I control bits
select the dead times to be used for the PWM1H/PWM1L complementary output pair. The pair
of dead time selection control bits are referred to as the ‘dead-time-select-active’ and
‘dead-time-select-inactive’ control bits, respectively. The function of each bit in a pair is as
follows:
• The DTSxA control bit selects the dead time that is to be inserted before the high-side
output is driven active.
• The DTSxI control bit selects the dead time that is to be inserted before the low-side PWM
active is driven active.
Table 15-4 summarizes the function of each dead time selection control bit.
Dead Time
DT =
Prescale Value • TCY 15
Motor Control
Table 15-5 shows example dead time ranges as a function of the input clock prescaler selected
and the device operating frequency.
1H
1L
Figure 15-18: PWM Block Diagram for One Output Pin Pair, Independent Mode
PWMxL
Note: Dead time insertion is still performed when PWM channels are overridden manually.
15
Motor Control
PWM
1 2 3 4 5 6
PWM3H
PWM3L
PWM2H
PWM2L
PWM1H
PWM1L
Note: Switching times between states 1-6 are controlled by user software.
The state switch is controlled by writing a new value to OVDCON.
STATE
1 2 3 4
PWM4H
PWM4L
PWM3H
PWM3L
PWM2H
PWM2L
PWM1H
PWM1L
Note: Switching times between states 1-4 are controlled by user software. The state switch
is controlled by writing a new value to OVDCON. The PWM outputs are operated in the
independent mode for this example.
15
Motor Control
PWM
When a fault pin is enabled and driven low, the PWM pins are immediately driven to their
programmed fault states regardless of the values in the PDCx and OVDCON registers. The fault
action has priority over all other PWM control registers.
A fault condition must be cleared by the external circuitry driving the fault input pin high and
clearing the fault interrupt flag (Latched mode only). After the fault pin condition has been
cleared, the PWM module will restore the PWM output signals on the next PWM period or
half-period boundary. For edge aligned PWM generation, the PWM outputs will be restored when
PTMR = 0. For center aligned PWM generation, the PWM outputs will be restored when PTMR
= 0 or PTMR = PTPER, whichever event occurs first.
An exception to these rules will occur when the PWM time base is disabled (PTEN = 0). If the
PWM time base is disabled, the PWM module will restore the PWM output signals immediately
after the fault condition has been cleared.
15
Motor Control
PWM
Note: When the FLTA pin is programmed for Latched mode, the PWM outputs will not
return to the Fault B states or normal operation until the Fault A interrupt flag has
been cleared and the FLTA pin is de-asserted.
Note: The user should exercise caution when controlling the fault inputs in software. If the
TRIS bit for the fault pin is cleared, then the fault input cannot be driven externally.
PWM Period
PTMR
FLTA
Note: Arrows indicate the time when normal PWM operation is restored.
PTMR
Return to
normal
Duty cycle = 50% operation
FLTA
FLTAIF
PTMR
Return to
normal
Duty cycle = 50% operation
FLTA
FLTB
Note: Immediate updates must be disabled (IUE = 0) in order to use the PWM update
lockout feature.
; This code example drives all PWM pins to the inactive state
; before executing the PWRSAV instruction.
The Fault A and Fault B input pins, if enabled to control the PWM pins via the FLTxCON registers,
will continue to function normally when the device is in Sleep mode. If one of the fault pins is
driven low while the device is in Sleep, the PWM outputs will be driven to the programmed fault
states in the FLTxCON register.
The fault input pins also have the ability to wake the CPU from Sleep mode. If the fault interrupt
enable bit is set (FLTxIE = 1), then the device will wake from Sleep when the fault pin is driven
low. If the fault pin interrupt priority is greater than the current CPU priority, then program
execution will start at the fault pin interrupt vector location upon wake-up. Otherwise, execution
will continue from the next instruction following the PWRSAV instruction.
15
Motor Control
PWM
DS70062D-page 15-40
IPC10 00A8 — FLTAIP<2:0> — — — — — — — — — — — — 0100 0100 0100 0100
IPC11 00AA — — — — — — — — — — — — — FLTBIP<2:> 0000 0000 0000 0000
PTCON 01C0 PTEN — PTSIDL — — — — — PTOPS<3:0> PTCKPS<1:0> PTMOD<1:0> 0000 0000 0000 0000
PTMR 01C2 PTDIR PWM Time Base register 0000 0000 0000 0000
PTPER 01C4 — PWM Time Base Period register 0111 1111 1111 1111
SEVTCMP 01C6 SEVTDIR PWM Special Event Compare register 0000 0000 0000 0000
PWMCON1 01C8 — — — — PMOD4 PMOD3 PMOD2 PMOD1 PEN4H PEN3H PEN2H PEN1H PEN4L PEN3L PEN2L PEN1L 0000 0000 0000 0000
PWMCON2 01CA — — — — SEVOPS<3:0> — — — — — IUE OSYNC UDIS 0000 0000 0000 0000
DTCON1 01CC DTBPS<1:0> Dead Time B Value register DTAPS<1:0> Dead Time A Value register 0000 0000 0000 0000
DTCON2 01CE — — — — — — — — DTS4A DTS4I DTS3A DTS3I DTS2A DTS2I DTS1A DTS1I 0000 0000 0000 0000
FLTACON 01D0 FAOV4H FAOV4L FAOV3H FAOV3L FAOV2H FAOV2L FAOV1H FAOV1L FLTAM — — — FAEN4 FAEN3 FAEN2 FAEN1 0000 00-0 0000 0000
FLTBCON 01D2 FBOV4H FBOV4L FBOV3H FBOV3L FBOV2H FBOV2L FBOV1H FBOV1L FLTBM — — — FBEN4 FBEN3 FBEN2 FBEN1 0000 0000 0000 0000
OVDCON 01D4 POVD4H POVD4L POVD3H POVD3L POVD2H POVD2L POVD1H POVD1L POUT4H POUT4L POUT3H POUT3L POUT2H POUT2L POUT1H POUT1L 1111 1111 00-0 0000
PDC1 01D6 PWM Duty Cycle #1 register 0000 0000 0000 0000
PDC2 01D8 PWM Duty Cycle #2 register 0000 0000 0000 0000
PDC3 01DA PWM Duty Cycle #3 register 0000 0000 0000 0000
PDC4 01DC PWM Duty Cycle #4 register 0000 0000 0000 0000
Note 1: Reset state of PENxx control bits depends on the state of the PWMPIN device configuration bit.
dsPIC30F Family Reference Manual
2: Shaded register and bit locations not implemented for the 6-output MCPWM module.
3: The IUE bit is not implemented on the dsPIC30F6010 device.
DS70062D-page 15-41
PWM
15
Motor Control
dsPIC30F Family Reference Manual
Note: Please visit the Microchip web site (www.microchip.com) for additional Application
Notes and code examples for the dsPIC30F Family of devices.
NOTES: