beautypg.com

1 pwm programming examples, 1 example, 2 static programming (pwm is not running) example – Cirrus Logic EP93xx User Manual

Page 734: 1 pwm programming examples -2, Table 24-1. static programming steps -2

background image

24-2

DS785UM1

Copyright 2007 Cirrus Logic

Pulse Width Modulator
EP93xx User’s Guide

2

4

2

4

24

With those two counters specified, a fixed pulse is generated. The two channels are totally
independent. This is a DC-level PWM.

Either PWM channel can be utilized to create reoccurring pulses at the PWMx output pins.
Depending upon how a PWM is programmed, its output can vary from a continuous level
(100% duty-cycle), to a square wave (50% duty-cycle), to a narrow pulse approaching a 0%
duty-cycle. Both PWMs offer 16-bit resolution of the input clock signal.

The outputs of both PWM channels are programmed in terms of PWM input clock cycles.
Each PWM may be programmed statically (when it is halted) or dynamically (while it is
running). The output of either PWM may be programmed as normal or inverted. With the
exception of inversion, if a PWM is programmed statically, no change to the output will occur
until the PWM is enabled. If a PWM is reprogrammed while it is running (enabled), the output
is updated to the new programming (total period, total period asserted) at the beginning of the
next PWM cycle. The exception for inverted operation is explained below. Both PWMs are
reset to the halted condition.

The output of either PWM can be programmed for either normal or inverted operation.
Inversion affects the output pin when the PWM peripheral is halted and also when it is
running. Both outputs are reset to the normal (non-inverted) configuration, which places the
output pins in a LOW condition at reset. When the output is reprogrammed to be inverted (or
to be normal), the new programming does not become effective until the rising edge of the
PWM input clock signal.

Note: In the design, because of the use of clock gating on PCLK, the write enable and read

enable were altered to work correctly within the design.

24.2.1 PWM Programming Examples

The reference clock for PWM is XTALI.

24.2.1.1 Example

To produce a PWM output of 100 kHz (10

μ

sec) and 20% duty cycle with a system clock of

66 MHz (15 nsec):

1. Calculate PWMxTermCnt = (66 MHz / 0.1 MHz) – 1 = 659 (decimal).

2. Calculate PWMxDutyCycle = (0.2 × (659 + 1)) – 1 = 131 (decimal).

24.2.1.2 Static Programming (PWM is Not Running) Example

Table 24-1. Static Programming Steps

Step

Register

Value

Stop PWM

PWMxEn

0x0000

Wait for PWM to finish current cycle

-----------------

Program TC value with 659 (decimal)

PWMxTermCnt

0x0293

Program DC value with 131 (decimal)

PWMxDutyCycle

0x0083

Program PWM output to invert

PWMxInvert

0x0001

Enable/Start PWM

PWMxEn

0x0001