ENG2008 Lab 6
1 Overview
ENG2008 Lab exercise 6 Analogue interface
In this lab you will use analogue interface modules in KL25Z to complete two tasks. Assessment: Complete the missing code for Task 1 in Lab 6 answer sheet.
2 Hardware
2.1 mbed Application Shield
In this task, you will use the mbed Application Shield as shown in Fig. 1 together with the Freedom KL25Z board. A circuit schematic diagram of the shield can be found on ELE page.
Figure 1. mbed Application Shield. The mbed Application Shield integrates the following components:
128×32 Graphics LCD
5 way joystick
2 x Potentiometers
Speaker, PWM Conencted
3 Axis ±1.5g Accelerometer
RGB LED, PWM connected
Temperature sensor
Socket for for Xbee (Zigbee) or RN‐XV (Wifi) 1/5
ENG2008 Lab 6
You will be using the LCD and one of the potentiometers in this exercise.
Plug the mbed Application Shield into the Freedom KL25Z board. POT1 is now connected to ADC0_SE8. You can change the voltage on this pin by turning the knob.
2.2 Disable Non‐Maskable Interrupt
To use this board, you must first disable NMI (Non‐Maskable Interrupt). Please follow the following steps carefully. Create a project and locate the file startup_MKL25Z4.s in the Project window on the left (Fig. 2). Double click the file and scroll down to line 229. Comment this line by adding a semicolon (;) at the beginning of this line. Then, add the following code in line 230:
FOPT EQU 0xFB
Make sure this line is aligned left as shown in Fig. 2. Save the file using Ctrl+S. Now NMI is disabled.
THIS MUST BE DONE FOR EVERY PROJECT THAT USES MBED APPLICATION SHIELD!
Figure 2. Disable NMI.
4 ADC
4.1 Task 1: Voltage controlled LEDs
In this task, you will compose C code to control the colour of the RGB LED according to measured voltage on POT1 (ADC0_SE8). The RGB LED on mbed Application Shield is the same as the one on Freedom KL25Z board, i.e. a logic low will turn on the relevant LED. The connection is different though. On this board, connection of RGB LED is show in Table 1. Colours of RGB LED and their respective voltage ranges is listed in Table 2.
2/5
ENG2008 Lab 6
You can find 3 partially completed files in the folder “Lab6/Lab6a”, i.e. LEDs.c, LEDs.h and main.c.
Table 1. Connection of RGB LED on mbed Application Shield.
Table 2. Colours of RGB LED and their respective voltage ranges
Colour KL25Z pin
Red
PTA5
Blue
PTA13
Green
PTD5
Colour KL25Z pin
Off
0 to Vref/8
Blue
Vref/8 to Vref/4
Green
Vref/4 to 3*Vref/8
Sky blue (green and blue)
3*Vref/8 to Vref/2
Red
Vref/2 to 5*Vref/8
Pink (red and blue)
5*Vref/8 to 3*Vref/4
Yellow (red and green)
3*Vref/4 to 7*Vref/8
White (all)
7*Vref/8 to Vref
The following task is not part of the assessment.
4.2 Task 2: Voltmeter 4.2.1 LCD
In this task, you will use code given to display characters on the LCD.
Create project, add the following files (downloadable from ELE page, folder “Lab6/LCD”) into the project.
c12832.c c12832.h Small_7.h LCD.c
Among these files, the first three files are drivers for LCD. You can add these files to projects that require LCD display. Do not modify them. LCD.c contains the main() function which you can edit. Build the files and download the code to the KL25z board. Press the reset button on the mbed Application Shield and you should see the display as in Fig. 3.
3/5
ENG2008 Lab 6
(POT1) ADC0_SE8
Figure 3. LCD test display.
The LCD is configured to have 3 rows and each row can display up to 21 characters. To display
one character, use function putchar(x, y, c).
x – row number (1‐2)
y – column number (1‐21)
c – character or ASCII code of the character
For example, putchar(1 , 1 , ‘a’) can display letter ‘a’ in Column 1 in Row 1, To display a string of characters, use function putstr(x, y, s).
x – row number (1‐2)
y – column number of the first character (1‐21) c – character
For example, putstr(1 , 1 , “abc”) can display letters ‘a’, ‘b’ and ‘c’ in Columns 1, 2 and 3 in Row 1 respectively.
Now, modify the code to display your name and student number in Rows 1 and 2 respectively.
4.2.2 Voltmeter
In this task, you will compose C code to measure the voltage on POT1 (ADC0_SE8) using KL25Z and display the result using the LCD display. Show 2 decimal places. When displaying the numerical results, you will actually display characters. For example, to display the number 2.34, you need to display four characters, i.e. ‘2’, ‘3’, ‘.’ and ‘4’. Here is a tip to display decimal numbers:
4/5
ENG2008 Lab 6
Try to process the decimal numbers using integers. For example if the measured voltage is 2.34, multiply it by 100 and it becomes 234. First, display the hundred digit, i.e. 234/100 = 2. Then, display the decimal point, ‘.’. Second, display the ten digit, i.e. (234‐2*100)/10 = 3. Finally, display the unit digit, i.e. 234‐2*100‐3*10 = 4. To display the characters of numbers, use the function putchar(x, y, c) but make sure the ASCII of the number is used. To covert a number to its ASCII code, follow this rule:
putchar(x, y, number+48)
For example, if you want to display the character ‘2’, in column 1, row 1, use:
putchar(1, 1, 50)
Note that 50 is the result of 2+48.
Measure 5 different voltages on POT1 (shown in Fig. 3) using a multimeter and compare them with measurement by KL25Z. Complete the table below.
Measurement Multimeter KL25Z measurement
1
2
3
4
5
5/5