User manual

LPCXpresso Experiment Kit - User’s Guide
Page 58
Copyright 2013 © Embedded Artists AB
7.7 Pulse Width Modulation
In this experiment you will learn how to generate a pulse width modulated (PWM) signal. The PWM
signals will be generated purely in software. A more hardware oriented implementation with the help of
timers will be investigated in later experiments. Figure 27 below outline the breadboard design that
allows performing all experiments around PWM signals. Start with building this. All resistors are 330
ohm.
Figure 27 Breadboard Connections for PWM Experiments
7.7.1 Lab 6a: PWM Control of a LED
In this experiment you shall investigate how to generate a signal with a given duty cycle and how the
LED intensity varies with duty cycle. Figure 28 illustrates the PWM signal structure. The high-time
defines the duty cycle. It this signals directly drives a LED, the LED will be fully on when duty cycle is 0
and fully off when the duty cycle is 1 (100%).
Figure 28 PWM Signal
Below is a code structure that can be used to generate a signal with a specified duty cycle. The loop
should be repeated as often as possible in order to keep generating the signal. As seen the loop below
will perform 100 iterations so the resolution of the duty cycle control is 1%. Higher resolution is
d
D
Duty = d/D
Frequency = 1/D