User manual

LPCXpresso Experiment Kit - User’s Guide
Page 59
Copyright 2013 © Embedded Artists AB
possible by increasing the number of iterations but the trade-off is lower frequency of the duty cycle.
This may, or may not, be a problem as we will investigate in later experiments.
//Set wanted duty cycle
wantedDutyCycle = ...
//Set output high
...
//Enter duty cycle generating loop
for (loopCounter=0; loopCounter<100; loopCounter++)
{
if (loopCounter == wantedDutyCycle)
//Set output low
...
}
Create a program that generate a fixed duty cycle and controls a LED. Define the duty cycle with a
constant in the program.
About what frequency does the PWM signal have? _________________________
(measure with an oscilloscope of logic analyzer, if possible)
Draw a diagram of the perceived LED intensity with different duty cycles:
7.7.2 Lab 6b: PWM Control of a LED, cont. 1
In this experiment let the value from the trimming potentiometer control the duty cycle. Build on the
code that was developed in Lab 6a. Read the AIN0 value and set duty cycle between 0-100%
accordingly.
As an extra experiment, let the light sensor control the duty cycle. If the room is dark have full intensity
on the LED and vice versa.
7.7.3 Lab 6c: PWM Control of a LED, cont. 2
In Lab 6a, the duty cycle frequency was fixed to a relatively high value. In this experiment you shall
investigate how this frequency affects the LED intensity. At some point (when lowering the frequency)
you will notice a flickering on the LED.
Create a program where one trimming potentiometer controls the duty cycle and another trimming
potentiometer controller the frequency.
Tip: Add a variable delay in the loop. Let the delay be 1 us, or multiples of it. At 1 us delay, a total of
100us delay will be added per cycle. This equals 10 kHz. Measure and verify that you get about this
0 20 40 60 80 100 Duty cycle
Intensity Full
None