Rabbit 4000 Microprocessor
User's Manual
PREV INDEX NEXT


23. Pulse Width Modulator

23.1 Overview

The Pulse Width Modulator (PWM) consists of a 10-bit free running counter and four width registers. A PWM output consists of a train of periodic pulses within a 1024-count frame with a duty cycle that varies from 1/1024 to 1024/1024. Each PWM output is high for n + 1 counts out of the 1024-clock count cycle, where n is the value held in the width register. The PWM is clocked by the output of Timer A9 which is used to set the period.

Each PWM output high time can optionally be spread throughout the cycle to reduce ripple on the externally filtered PWM output. The PWM outputs can be passed through a filter and used as a 10-bit D/A converter. The outputs can also be used to directly drive devices such as motors or solenoids that have intrinsic filtering.

The PWM outputs can trigger a PWM interrupt on every PWM cycle, every other cycle, every fourth cycle, or every eighth cycle. In addition, the PWM output can be suppressed every other cycle, three out of every four cycles, or seven out of every eight cycles. These options provide support for driving servos and to generate audio signals. The setup for this interrupt is done in the PWL0R and PWL1R registers. The timing is shown below.


The spreading function is implemented by dividing each 1024-clock cycle into four quadrants of 256 clocks each. Within each quadrant, the Pulse-Width Modulator uses the eight MSBs of each pulse-width register to select the base width in each of the quadrants. This is the equivalent to dividing the contents of the pulse-width register by four and using this value in each quadrant. To get the exact high time, the Pulse-Width Modulator uses the two LSBs of the pulse-width register to modify the high time in each quadrant according to the table below. The "n/4" term is the base count, formed from the eight MSBs of the pulse-width register.

Pulse-Width LSBs

1st

2nd

3rd

4th

00
n/4 + 1
n/4
n/4
n/4
01
n/4 + 1
n/4
n/4 + 1
n/4
10
n/4 + 1
n/4 + 1
n/4 + 1
n/4
11
n/4 + 1
n/4 + 1
n/4 + 1
n/4 + 1


The diagram below shows a PWM output for several different width values, for both modes of operation. Operation in the spread mode reduces the filtering requirements on the PWM output in most cases.


The DMA channels on the Rabbit 4000 are designed to work with fixed I/O addresses. To allow DMA control of the PWM, a separate PWM Block Access Register (PWBAR) and PWM Block Pointer Register (PWBPR) are available. The pointer register contains the address of the PWM register to be accessed via the access register. Each read or write of the access register automatically increments the pointer register through the sequence shown below. Note that only the lower three bits of the pointer register actually change. This allows the DMA to write to a fixed internal I/O location but still program all of the PWM registers. The pointer register can be written and read if necessary. Normally the pointer register is initialized to 0x88 (the first PWM register) and the DMA then transfers blocks of eight bytes to completely reprogram the PWM.

When the DMA destination address is the PWBAR, the DMA request from the PWM is automatically connected to the DMA.

23.1.1 Block Diagram


23.1.2 Registers

Register Name

Mnemonic

I/O Address

R/W

Reset

PWM LSB 0 Register
PWL0R
0x0088
R/W
xxxxx00x
PWM MSB 0 Register
PWM0R
0x0089
R/W
xxxxxxxx
PWM LSB 1 Register
PWL1R
0x008A
R/W
xxxxx00x
PWM MSB 1 Register
PWM1R
0x008B
R/W
xxxxxxxx
PWM LSB 2 Register
PWL2R
0x008C
R/W
xxxxx00x
PWM MSB 2 Register
PWM2R
0x008D
R/W
xxxxxxxx
PWM LSB 3 Register
PWL3R
0x008E
R/W
xxxxx00x
PWM MSB 3 Register
PWM3R
0x008F
R/W
xxxxxxxx
PWM Block Access Register
PWBAR
0x00E8
W
xxxxxxxx
PWM Block Pointer Register
PWBPR
0x00E9
W
10001000


23.2 Dependencies

23.2.1 I/O Pins

Each PWM channel can be output on up one of three pins, which can be selected via the parallel port alternate output registers.

PWM

Output Pins

Channel 0
PC4, PD4, PE4
Channel 1
PC5, PD5, PE5
Channel 2
PC6, PD6, PE6
Channel 3
PC7, PD7, PE7


23.2.2 Clocks

The PWM counter is clocked from the output of Timer A9, and can run at rates from perclk/2 down to perclk/512 by writing the appropriate value to TAT9R.

23.2.3 Other Registers

Register

Function

TAT9R
Time constant for PWM clock
PCFR, PCAHR
PDFR, PDAHR
PEFR, PEAHR
Alternate port output selection


23.2.4 Interrupts

The PWM can generate an interrupt for every PWM counter rollover, every second rollover, every fourth rollover, or every eighth rollover. This option is selected in PWL1R. The interrupt request is cleared by a write to any PWM register.

The PWM interrupt vector is in the IIR at offset 0x170. It can be set as Priority 1, 2, or 3 by writing to PWL0R.

23.3 Operation

The following steps explain how to set up a PWM channel.

  1. Configure Timer A9 via TAT9R to provide the desired PWM clock frequency.

  2. Configure PWLxR to select whether to spread the PWM output throughout the cycle.

  3. Configure PWLxR to select whether to suppress the PWM output.

  4. Configure the duty cycle by writing to PWLxR and PWMxR.

23.3.1 Handling Interrupts

The following steps explain how an interrupt is set up and used.

  1. Write the vector to the interrupt service routine to the internal interrupt table.

  2. Configure PWL0R to select the PWM interrupt priority and PWL1R to select PWM interrupt suppression (if an interrupt is desired).

The following actions occur within the interrupt service routine.

23.3.2 Example ISR

A sample interrupt handler is shown below.

23.4 Register Descriptions

PWM LSB 0 Register (PWL0R) (Address = 0x0088)

Bit(s)

Value

Description

7:6
Least significant two bits for the Pulse Width Modulator count.
5:4
00
Normal PWM operation.
01
Suppress PWM output seven out of eight iterations of PWM counter.
10
Suppress PWM output three out of four iterations of PWM counter.
11
Suppress PWM output one out of two iterations of PWM counter.
3
This bit is ignored and should be written with zero.
2:1
00
Pulse Width Modulator interrupts are disabled.
01
Pulse Width Modulator interrupts use Interrupt Priority 1.
10
Pulse Width Modulator interrupts use Interrupt Priority 2.
11
Pulse Width Modulator interrupts use Interrupt Priority 3.
0
0
PWM output High for single block.
1
Spread PWM output throughout the cycle.


PWM LSB 1 Register (PWL1R) (Address = 0x008A)

Bit(s)

Value

Description

7:6
Least significant two bits for the Pulse Width Modulator count.
5:4
00
Normal PWM operation.
01
Suppress PWM output seven out of eight iterations of PWM counter.
10
Suppress PWM output three out of four iterations of PWM counter.
11
Suppress PWM output one out of two iterations of PWM counter.
3
This bit is ignored and should be written with zero.
2:1
00
Normal PWM interrupt operation.
01
Suppress PWM interrupts seven out of eight iterations of PWM counter.
10
Suppress PWM interrupts three out of four iterations of PWM counter.
11
Suppress PWM interrupts one out of two iterations of PWM counter.
0
0
PWM output High for single block.
1
Spread PWM output throughout the cycle.

PWM LSB x Register (PWL2R) (Address = 0x008C)
(PWL3R) (Address = 0x008E

Bit(s)

Value

Description

7:6
Least significant two bits for the Pulse Width Modulator count.
5:4
00
Normal PWM operation.
01
Suppress PWM output seven out of eight iterations of PWM counter.
10
Suppress PWM output three out of four iterations of PWM counter.
11
Suppress PWM output one out of two iterations of PWM counter.
3:1
These bits are ignored and should be written with zero.
0
0
PWM output High for single block.
1
Spread PWM output throughout the cycle.


PWM MSB x Register (PWM0R) (Address = 0x0089)
(PWM1R) (Address = 0x008B)
(PWM2R) (Address = 0x008D)
(PWM3R) (Address = 0x008F)

Bit(s)

Value

Description

7:0
Most significant eight bits for the Pulse Width Modulator count. With a count of "n", the PWM output will be High for "n + 1" clocks out of the 1024 clocks of the PWM counter.


PWM Block Access Register (PWBAR) (Address = 0x00E8)

Bit(s)

Value

Description

7:0
Access the PWM register pointed to by the PWBPR. The PWBPR is automatically updated to the next PWM register address in the sequence.


PWM Block Pointer Register (PWBPR) (Address = 0x00E9)

Bit(s)

Value

Description

7:3
These bits are ignored and should be written with zero.
2:0
Three least significant bits of the PWM register address for indirect access.



Rabbit Semiconductor
www.rabbit.com
PREV INDEX NEXT