PWM in Arm Lpc2148
PWM in Arm Lpc2148
Introduction
Pulse Width Modulation (PWM) is a technique by which width of a pulse is varied while
keeping the frequency constant.
A period of a pulse consists of an ON cycle (HIGH) and an OFF cycle (LOW). The fraction for
which the signal is ON over a period is known as duty cycle.
E.g. Consider a pulse with a period of 10ms which remains ON (high) for 2ms.The duty cycle of
this pulse will be
Through PWM technique, we can control the power delivered to the load by using ON-OFF
signal.
Single Edge Controlled PWM : All the rising (positive going) edges of the output waveform
are positioned/fixed at the beginning of the PWM period. Only falling (negative going) edge
position can be controlled to vary the pulse width of PWM.
Double Edge Controlled PWM : All the rising (positive going) and falling (negative going)
edge positions can be controlled to vary the pulse width of PWM. Both the rising as well as the
falling edges can be positioned anywhere in the PWM period.
LPC2148 PWM
The PWM in LPC2148 is based on standard 32-bit Timer Counter, i.e. PWMTC (PWM
Timer Counter). This Timer Counter counts the cycles of peripheral clock (PCLK).
Also, we can scale this timer clock counts using 32-bit PWM Prescale Register
(PWMPR).
LPC2148 has 7 PWM match registers (PWMMR0 – PWMMR06).
One match register (PWMMR0) is used to set PWM frequency.
Remaining 6 match registers are used to set PWM width for 6 different PWM signals in
Single Edge Controlled PWM or 3 different PWM signals in Double Edge Controlled
PWM.
Whenever PWM Timer Counter (PWMTC) matches with these Match Registers then,
PWM Timer Counter resets, or stops, or generates match interrupt, depending upon
settings in PWM Match Control Register (PWMMCR).
As shown in above figure, PWMMR0 = 6 i.e. PWM period is 6 counts, after which PWM Timer
Counter resets.
PWM2 & PWM3 are configured as Single Edge Controlled PWM and PWM5 is configured as
Double Edge Controlled PWM.
Prescaler is set to increment PWM Timer Counter after every two Peripheral clocks (PCLK).
Match registers (PWMMR2 & PWMMR3) are used to set falling edge position for PWM2 &
PWM3.
PWMMR4 & PWMMR5 are used to set rising & falling edge positions respectively for PWM5.
Let’s see the different PWM that can be generated using LPC2148
The table given below shows when the PWM is Set (Rising Edge) and Reset (Falling Edge) for
different PWM channels using 7 Match Register.
PWM Channel Single Edge Controlled Double Edge Controlled
Set by Reset by Set by Reset by
1 Match 0 Match 1 Match 0 Match 1
2 Match 0 Match 2 Match 1 Match 2
3 Match 0 Match 3 Match 2 Match 3
4 Match 0 Match 4 Match 3 Match 4
5 Match 0 Match 5 Match 4 Match 5
6 Match 0 Match 6 Match 5 Match 6
Let’s see the various PWM registers that are useful in controlling and generating PWM.
PWM Registers configuration for LPC2148
1. PWMIR (PWM Interrupt Register)
It is a 16-bit register.
It is an 8-bit register.
It is used to control the operation of the PWM Timer Counter.
P
WMTCR (PWM Timer Control Register)
It is a 32-bit register.
It is incremented when the PWM Prescale Counter (PWMPC) reaches its terminal count.
It is a 32-bit register.
It holds the maximum value of the Prescale Counter.
It is a 32-bit register.
It controls the division of PCLK by some constant value before it is applied to the PWM
Timer Counter.
It is incremented on every PCLK.
When it reaches the value in PWM Prescale Register, the PWM Timer Counter is
incremented and PWM Prescale Counter is reset on next PCLK.
It is a 32-bit register.
It controls what action is to be taken on a match between the PWM Match Registers and
PWM Timer Counter.
PWMMCR (PWM Match Control Register)
It is a 16-bit register.
It is used to enable and select each type of PWM.
Bit 2 – PWMSEL2
0 = Single edge controlled mode for PWM2
1 = Double edge controlled mode for PWM2
All other PWMSEL bits have similar operation as PWMSEL2 above.
Bit 10 – PWMENA2
0 = PWM2 output disabled
1 = PWM2 output enabled
All other PWMENA bits have similar operation as PWMENA2 above.
It is an 8-bit register.
It is used to control the update of the PWM Match Registers when they are used for
PWM generation.
When a value is written to a PWM Match Register while the timer is in PWM mode, the
value is held in the shadow register. The contents of the shadow register are transferred to
the PWM Match Register when the timer resets (PWM Match 0 event occurs) and if the
corresponding bit in PWMLER is set.
Bit 6 – Enable PWM Match 6 Latch
Writing a 1 to this bit allows the last written value to PWMMR6 to become effective
when timer next is reset by the PWM match event.
Similar description as that of Bit 6 for the remaining bits.