PWM Pic18f16q40
PWM Pic18f16q40
P1 Buffer
Duty Cycle
Reset
PR Buffer
PWMx_SaP1_out
Q
Set
Set
PWMxCLK PWMx_SaP2_out
Q
Reset
Duty Cycle
P2 Buffer
PWMx_clk
PWMx_timer 0 1 2 3 4 5 0 1 2 3 4 5 0 1
SaP1_out
SaP2_out
SaP1IF
PWMxPIF
PWMxIF
P1 Buffer
Duty Cycle
Set
PR Buffer
PWMx_SaP1_out
Q
Reset
PWMx_clk
Clock Prescale Timer
Period
Event
Sources
Reset
PWMxCLK PWMx_SaP2_out
Q
Set
Duty Cycle
P2 Buffer
PWMx_clk
PWMx_timer 0 1 2 3 4 5 0 1 2 3 4 5 0 1
SaP1_out
SaP2_out
SaP2IF
The parameter register specifies the number of PWM clock periods that the output goes Active
before the period center. The output goes inactive the same number of prescaled PWM clock
periods after the period center. Block and timing diagrams follow.
P1 Buffer
Duty Cycle
Reset
PR Buffer PWMx_SaP1_out
Q
Set
PWMx_clk
Clock Prescale Timer
Period
Event
Sources
Set
PWMxCLK
PWMx_SaP2_out
Q
Reset
Duty Cycle
P2 Buffer
PWMx_clk
PWMx_timer 0 1 2 3 4 5 0 1 2 3 4 5 0 1
SaP1_out
SaP2_out
SaP2IF
P1 Buffer
=
PR Buffer
Set
PWMx_SaP1_out
Q
PWMxCLK
=
P2 Buffer
PWMx_clk
PWMx_timer 0 1 2 3 4 5 0 1 2 3 4 5 0 1
SaP1_out
SaP2_out
SaP1IF
PWMxPIF
P1 Buffer
=
Pulse
PWMx_SaP1_out
Q
PR Buffer
PWMx_clk
Clock Prescale Timer
Period PWMx_SaP2_out
Sources
Event Q
Pulse
PWMxCLK
=
P2 Buffer
PWMx_clk
PWMx_timer 0 1 2 3 4 5 0 1 2 3 4 5 0 1
SaP1_out
SaP2_out
SaP1IF
PWMxPIF
P1 Buffer
=
Toggle
PWMx_SaP1_out
Q
PR Buffer
PWMx_clk
Clock Prescale Timer
Period PWMx_SaP2_out
Sources
Event Q
Toggle
PWMxCLK
=
P2 Buffer
PWMx_clk
PWMx_timer 0 1 2 3 4 5 0 1 2 3 4 5 0 1
SaP1_out
SaP2_out
SaP1IF
PWMxPIF
PWMx_clk
PWMx_timer 0 1 2 3 4 5 0 1 2 3 4 5 0 1
SaP1_out
SaP2_out
SaP1IF
SaP2IF
Reset by software
Note: MODE = ‘b000, PR = 5, P1 = 4, P2 = 2, PPEN = 1.
PWMx_clk
PWMx_timer 0 1 2 3 4 5 0 1 2 3 4 5 0 1
SaP1_out
SaP2_out
SaP2IF
Loading the buffers of multiple PWM instances can be coordinated using the PWMLOAD register.
See the Buffered Period and Parameter Registers section for more details.
PWMx_clk
PWMx_timer 0 1 2 3 4 5 0 1 2 3 0 0 0 1
PWMx_ers
SaP1_out
SaP2_out
Note: PR = 5, P1 = 4, P2 = 2.
PWMx_clk
PWMx_timer 0 1 2 3 4 5 0 0 0 1 2 3 4 5
PWMx_ers
SaP1_out
SaP2_out
Note: PR = 5, P1 = 4, P2 = 2.
Important: No changes are allowed after the LD bit is set until after the LD bit is cleared
by hardware. Unexpected behavior may result if the LD bit is cleared by software.
30.7 Interrupts
Each PWM instance has a period interrupt and interrupts associated with the mode and parameter
settings.
30.9.1 PWMxERS
Name: PWMxERS
Address: 0x460,0x46F,0x47E
PWMx External Reset Source
Bit 7 6 5 4 3 2 1 0
ERS[3:0]
Access R/W R/W R/W R/W
Reset 0 0 0 0
30.9.2 PWMxCLK
Name: PWMxCLK
Address: 0x461,0x470,0x47F
PWMx Clock Source
Bit 7 6 5 4 3 2 1 0
CLK[3:0]
Access R/W R/W R/W R/W
Reset 0 0 0 0
30.9.3 PWMxLDS
Name: PWMxLDS
Address: 0x462,0x471,0x480
PWMx Auto-load Trigger Source Select Register
Bit 7 6 5 4 3 2 1 0
LDS[3:0]
Access R/W R/W R/W R/W
Reset 0 0 0 0
30.9.4 PWMxPR
Name: PWMxPR
Address: 0x463,0x472,0x481
PWMx Period Register
Determines the PWMx period
Bit 15 14 13 12 11 10 9 8
PR[15:8]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
PR[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Notes: The individual bytes in this multibyte register can be accessed with the following register
names:
• PWMxPRH: Accesses the high byte PR[15:8]
• PWMxPRL: Accesses the low byte PR[7:0]
30.9.5 PWMxCPRE
Name: PWMxCPRE
Address: 0x465,0x474,0x483
PWMx Clock Prescaler Register
Bit 7 6 5 4 3 2 1 0
CPRE[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
30.9.6 PWMxPIPOS
Name: PWMxPIPOS
Address: 0x466,0x475,0x484
PWMx Period Interrupt Postscaler Register
Bit 7 6 5 4 3 2 1 0
PIPOS[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
30.9.7 PWMxGIR
Name: PWMxGIR
Address: 0x467,0x476,0x485
PWMx Interrupt Register
Bit 7 6 5 4 3 2 1 0
S1P2 S1P1
Access R/W/HS R/W/HS
Reset 0 0
30.9.8 PWMxGIE
Name: PWMxGIE
Address: 0x468,0x477,0x486
PWMx Interrupt Enable Register
Bit 7 6 5 4 3 2 1 0
S1P2 S1P1
Access R/W R/W
Reset 0 0
30.9.9 PWMxCON
Name: PWMxCON
Address: 0x469,0x478,0x487
PWM Control Register
Bit 7 6 5 4 3 2 1 0
EN LD ERSPOL ERSNOW
Access R/W R/W/HC R/W R/W
Reset 0 0 0 0
30.9.10 PWMxSaCFG
Name: PWMxSaCFG
PWM Slice “a” Configuration Register(1)
Bit 7 6 5 4 3 2 1 0
POL2 POL1 PPEN MODE[2:0]
Access R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0
Bits 2:0 – MODE[2:0] PWM Module Slice “a” Operating Mode Select
Selects operating mode for both PWMx_SaP1_out and PWMx_SaP2_out
Value Description
11x Reserved. Outputs go to Reset state.
101 Compare mode: Toggle PWMx_SaP1_out and PWMx_SaP2_out on PWM timer match with corresponding
parameter register
100 Compare mode: Set PWMx_SaP1_out and PWMx_SaP2_out high on PWM timer match with corresponding
parameter register
011 Variable Aligned mode
010 Center-Aligned mode
001 Right Aligned mode
000 Left Aligned mode
Note:
1. Changes to this register must be done only when the EN bit is cleared.
30.9.11 PWMxSaP1
Name: PWMxSaP1
PWM Slice “a” Parameter 1 Register
Determines the active period of slice “a”, parameter 1 output
Bit 15 14 13 12 11 10 9 8
P1[15:8]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
P1[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Notes: The individual bytes in this multibyte register can be accessed with the following register
names:
• PWMxSaP1H: Accesses the high byte P1[15:8]
• PWMxSaP1L: Accesses the low byte P1[7:0]
30.9.12 PWMxSaP2
Name: PWMxSaP2
PWM Slice “a” Parameter 2 Register
Determines the active period of slice “a”, parameter 2 output
Bit 15 14 13 12 11 10 9 8
P2[15:8]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
P2[7:0]
Access R/W R/W R/W R/W R/W R/W R/W R/W
Reset 0 0 0 0 0 0 0 0
Notes: The individual bytes in this multibyte register can be accessed with the following register
names:
• PWMxSaP2H: Accesses the high byte P2[15:8]
• PWMxSaP2L: Accesses the low byte P2[7:0]
30.9.13 PWMLOAD
Name: PWMLOAD
Address: 0x49C
Mirror copies of all PWMxLD bits
Bit 7 6 5 4 3 2 1 0
MPWM3LD MPWM2LD MPWM1LD
Access R/W R/W R/W
Reset 0 0 0
30.9.14 PWMEN
Name: PWMEN
Address: 0x49D
Mirror copies of all PWMxEN bits
Bit 7 6 5 4 3 2 1 0
MPWM3EN MPWM2EN MPWM1EN
Access R/W R/W R/W
Reset 0 0 0