User manual

LPCXpresso Experiment Kit - User’s Guide
Page 74
Copyright 2013 © Embedded Artists AB
uint32_t matchValue;
matchValue = (LPC_TMR16B1->MR2 * (100 value)) / 100;
if (channel == 0)
LPC_TMR16B1->MR0 = matchValue;
else if (channel == 1)
LPC_TMR16B1->MR1 = matchValue;
}
Place the PWM related functions in file pwm.c.
7.11.1 Lab 10a: Control RGB-LED
In this experiment we will repeat the experiment in section 7.8 (Control an RGB-LED), specifically
section Lab 7b: Control RGB-LED. Start by recreating the breadboard hardware in Figure 31 (see page
62). The red LED is controlled by signal GPIO_28-PWM, the green LED is controlled by signal
GPIO_29-PWM and the blue LED is controlled by signal GPIO_30-PWM.
Signal GPIO_28-PWM can carry signal CT16B1_MAT0 (assuming that pin PIO1_9 is configured for
this) and signal GPIO_29-PWM can carry signal CT16B1_MAT1 (assuming that pin PIO1_10 is
configured for this). Note that signal GPIO_30-PWM (pin PIO1_11) is not connected to any timer
match output. It was not possible to design the pcb to allow this. For breadboard experiments, it is
however possible to for example select signal GPIO_2-MISO (pin P0_8) that can carry signal
CT16B0_MAT0. Note that this is timer #0 (and not timer #1 as the code above configures).
Either you generate the third PWM signal in software (as we have done before) or you create functions
for generating PWM signals from timer #0 also. In the latter case the breadboard connections must be
updated (connect signal GPIO_30-PWM to pin GPIO_2-MISO).
Repeat the exact functionality in Lab 7b: Control RGB-LED, i.e., create a program that can control the
intensity of each (of the three) LED. Select with color to adjust with a push-button (rotate around the
three main colors, red, blue, green, at each press) and set intensity level with the trimming
potentiometer.
Test to blend the three colors and see which colors it is possible to create.
7.11.2 Lab 10b: Buzzer and Melodies
In this experiment we shall use the buzzer to output tones and in the end a melody. The buzzer self-
resonates with a tone of (about) 2.3kHz. What you will do is to modulate the buzzer (turn it on/off) with
the frequency of the tone to produce. This tone will be audible as well as the self-resonate tone.
The code segment below illustrates how to generate a tone. Note the table with constants for
producing two octaves of notes. Study the code below.
uint16_t notesInUs[] = {
2272, // A - 440 Hz
2024, // B - 494 Hz
3816, // C - 262 Hz
3401, // D - 294 Hz
3030, // E - 330 Hz
2865, // F - 349 Hz
2551, // G - 392 Hz
1136, // a - 880 Hz
1012, // b - 988 Hz
1912, // c - 523 Hz
1703, // d - 587 Hz
1517, // e - 659 Hz
1432, // f - 698 Hz
1275, // g - 784 Hz
};
/*****************************************************************************