0% found this document useful (0 votes)
664 views

G2 - Lab 5 - Report

This document contains information about an electronics engineering laboratory experiment completed by 4 students. It includes their names and student IDs. The experiment is on analog-to-digital and digital-to-analog conversions using an ARM Cortex-M3 microcontroller. The document consists of the students' answers to pre-lab questions, activities during the lab, assignments, observations, and a conclusion. It also includes grading rubrics to be filled out by the instructor evaluating the students' work.

Uploaded by

sarah
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
664 views

G2 - Lab 5 - Report

This document contains information about an electronics engineering laboratory experiment completed by 4 students. It includes their names and student IDs. The experiment is on analog-to-digital and digital-to-analog conversions using an ARM Cortex-M3 microcontroller. The document consists of the students' answers to pre-lab questions, activities during the lab, assignments, observations, and a conclusion. It also includes grading rubrics to be filled out by the instructor evaluating the students' work.

Uploaded by

sarah
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

FACULTY OF ELECTRICAL AND ELECTRONIC ENGINEERING

UNIVERSITI TUN HUSSEIN ONN MALAYSIA

BEJ40401 ELECTRONICS ENGINEERING LABORATORY IV

About Students:
Name Matric No. Section:
1. Aina Athirah binti Johari AE180034 Instructor’s Name:
2. Mohd Nawawi bin Ayup Jehmi @ Ayub CE180112 Dr. Chessda Uttraphan A/l Eh
3. Nick Cassidy Anak Merunei CE180169 Khan
4. Nurul Izyan Ainaa binti Jumari AE180084

About Experiment:
Title Submission date
Lab 5: Analog-to-Digital and Digital-to-Analog Conversions in ARM 1 - 1 - 2022
Cortex-M3 Microcontroller (LPC1768)

FOR INSTRUCTOR ONLY

Domain Item Subtotal Total


Pre-Lab /05
C
Questions /15
/20
Lab Activities /15
Lab Assignments /20
P
Observations /10
/50
Conclusion /05
Demonstrations (Understanding) /10
A Ethics (Originality & Lab Submission) /10 /30
Peer Assessment /10

TOTAL MARK Instructor’s Comment Submission Stamp

/100

BEJ40401 Semester 1 2021/22


Peer Assessment (to be filled in by the group leader)
Group leader full name : Nick Cassidy Anak Merunei
Group member 1 full name : Aina Athirah binti Johari
Group member 2 full name : Mohd Nawawi bin Ayup Jehmi @ Ayub
Group member 3 full name : Nurul Izyan Ainaa binti Jumari

- This peer assessment should be filled in by the group leader only.


- The group leader should evaluate yourself and also your group members.
- Tick (/) on the row (scale) that best describes yourself and your group members.

CRITERIA 1: Alternate roles Scale Leader Member 1 Member 2 Member 3


Clear ability to alternate roles as a group leader and a group member demonstrated in practice. 5 / / / /
Able to alternate roles as a group leader and a group member demonstrated in practice. 4
Satisfactory ability to alternate roles as a group leader and a group member demonstrated in practice. 3
Less ability to alternate roles as a group leader and a group member demonstrated in practice. 2
Very little ability to alternate roles as a group leader and a group member demonstrated in practice. 1
CRITERIA 2: Teamwork Scale Leader Member 1 Member 2 Member 3
Excellent ability to cooperate with group members in preparing the lab report/demo. 5 / / / /
Good ability to cooperate with group members in preparing the lab report/demo. 4
Satisfactory ability to cooperate with group members in preparing the lab report/demo. 3
Less ability to cooperate with group members in preparing the lab report/demo. 2
Very little cooperation with group members in preparing the lab report/demo. 1
Total mark = 10 10/10 10/10 10/10 10/10

1
Grading Rubric for Written Report (to be filled in by the instructor)

Scale
Criteria
5 4 3 2 1 Marks
Lab Activities (C) It Varies, depending on the activity assigned
Observations (C) It Varies, depending on the question assigned
Conclusion (P) Able to write a conclusion Able to write a conclusion Able to write a conclusion Able to write a conclusion Not able to write a
with excellent clarity, clearly and understandably. clearly but require minor with limited clarity and conclusion. /5
understandability, and improvements. require further
focus. improvements.
Demonstration (A) Very clear evidence of Able to demonstrate Able to demonstrate Able to demonstrate Demonstration without
knowledge and knowledge and knowledge and knowledge and understanding the
understanding understanding in practice understanding in practice understanding in practice but principle; cannot relate
and require minor require improvements.
demonstrated in practice. well. the concept to the scale * 2 = / 10
improvements.
demonstration.
Ethics (A) Solution ideas are written Solution ideas are written Little solution ideas are Some of the solution ideas Most of the solution
using their original using their original adopted from others, written are copied from others, ideas are copied from
language, written with clear language, written with with understandability. without fully understand the others, without fully
knowledge, knowledge and concept. understand the concept. /5
understandability, and understandability.
focus.

The report is submitted The report is submitted a The report is submitted 2 The report is submitted 3 The report is submitted
/ 10
before or on the dateline. day after the dateline. days after the dateline. days after the dateline. more than 3 days after /5
the dateline.

2
Table of Contents

Peer Assessment (to be filled in by the group leader) 1

Grading Rubric for Written Report (to be filled in by the instructor) 2

Table of Contents 3

Pre-Lab Answers 4

Answers to Lab Activities 5


Lab Activity 1 5
Lab Activity 2 10

Assignment 1 13

Assignment 2 18

Questions 20

Conclusion 21

3
Pre-Lab Answers

1. The LPC1768 has how many ADC channels and what is the size of the ADC (in bits)?

Answers:

LPC1768 has 8 channel and the size is 12-bit for Analog Digital Converter (ADC)

2. For an ADC with 10-bit resolution, convert the following analog voltage to its equivalent digital
value if the reference voltage is 3.3V.
(a) 400mV (b) 2.5V (c) 3.0V

Answers:

The digital output of an ADC is given by :-

𝑉𝑖
𝐷= 𝑉𝑟 𝑥 2𝑛

D Digital Output value

Vi Input Voltage

Vr Reference Voltage

n The Size of The ADC(bit)

so

a) 400mV

400𝑚
𝐷= 3.3
𝑥 210 = 124
= b0001111100
b) 2.5V

2.5
𝐷= 3.3 𝑥 210 = 776
= b1100001000
c) 3.0V

3
𝐷= 3.3 𝑥 210 = 931
= b1110100011

4
Answers to Lab Activities
Lab Activity 1
Setup the ADC in the LPC1768 microcontroller

Step Instructions Snapshot/Answer

1. The ADC is disabled on


reset (power on) to minimize
power consumption of the
microcontroller. Therefore,
to use the ADC, it needs to
be enabled first by setting
the 12th bit of the PCONP
register as follow:

LPC_SC → PCONP |=
(1<<12);

2. There is another power


control for ADC in the ADCR
register as by default, ADC
is in Power-down mode, and
this is controlled by the PDN
(bit 21) of the ADCR
Register. To make ADC
operational, we must set the
PDN bit as follow:

LPC_ADC → ADCR |=
(1<<21);

3. By using the ADCR register,


we can also select the ADC
Channel and set the Clock
Divider for ADC using SEL
[7:0] and CLKDIV [15:8] bits.

LPC_ADC → ADCR |=
(1<<0); //Select AD0.0
channel

LPC_ADC → ADCR |=
(1<<8); //Divide by 1

4. Next, you need to select the


ADC input pin for the
LPC1768, i.e., P0.23.

LPC_PINCON → PINSEL1
|= (1<<14)

5
5. Now, we can start the
conversion immediately by
setting START [26:24] bits in
ADCR as 001 i.e., the 24th
bit is set to 1.

LPC_ADC → ADCR |=
(1<<24);

6. Then, we wait for conversion


to finish by observing the
DONE bit (bit 31st) in the
ADDR0 register by

while ((LPC_ADC → ADDR0


& (1<<31)) == 0);

7. After completion, the result


is stored in the ADDR0
register in its RESULT [15:4]
bits. We can extract the
result by shifting the ADDR0
bits by 4 places and
masking the 12 bits.

int result = ((LPC_ADC →


ADDR0 >> 4) & 0xFFF);

6
8. Build the program in Listing
5.1 and debug the program.
In the debug session, open
the ADC debug window by
selecting “Peripherals > A/D
Converter”.

9. Change the analog input RESULT 1 : VALUE 1V


value in AIN0 (value
between 0 to 3.3V) and
observe the conversion
result in the A/D Channel 0
Data Register.

Using Manual Calculation:-

7
1
𝐷= 3.3 𝑥 212 =1241 @ 04D9 Hex

RESULT 2 : VALUE 2V

Using Manual Calculation:-


2
𝐷= 3.3 𝑥 212 =2482 @ 09B2 Hex

10. Modify the program to use Program modification:-


channel 2 (AD0.2) of the
ADC. Build and run the LPC_ADC -> ADCR = (1<<0); to LPC_ADC -> ADCR = (1<<2);
debug session to observe
the results. LPC_PINCON -> PINSEL1 |= (1<<14); to LPC_PINCON -> PINSEL1
|= (1<<18) ;

All ADDR0 to ADDR2

Output in A/D converter is observed at A/D channel data, ADDR2 and


RESULT. Analog input used is AIN2. The example output:-

8
AIN2 = 3.0000 with ADDR2 = 0x0000E8B0 and RESULT2 = 0x0E8B

Prove by manual calculation:-


3
𝐷= 𝑥 212 =3723.64@E8B Hex
3.3

9
Lab Activity 2
Setup the DAC in the LPC1768 microcontroller

Step Instruction Snapshot/Answer

1. The DAC is always


connected to the VDDA,
hence, no need to power it
on. Register access is
determined by PINSEL and
PINMODE settings. To use
AOUT pin (P0.26), set bit 21
of PINSEL1 register as Bit used for P0.26 for PINSEL1 based in the LPC1768 manual:-
follow:

LPC_PINCON → PINSEL1
|= (1<<21);

2. Write the desired digital


value that will be converted
to the analog value into the
DACR register

LPC_DAC → DACR =
(100<<6); //write digital
value 100 to DACR.

3. Build the program in Listing Program in Listing 5.2:-


5.2 and debug the program.
In the debug session, open
the ADC debug window by
selecting “Peripherals > D/A
Converter”.

10
D/A Converter window:-

4. Observe the values in the Digital value = 500:-


DACR register. Value in DACR register = 0x00007D00

The VALUE under D/A control shows the value of 500 in hexadecimal,
0x01F4 and its analog output, AOUT=1.6113. Proving by manual
calculation,
𝐷
𝑉𝑜 = 𝑛 𝑉𝑟
2
500
𝑉𝑜 = 10 (3.3) = 1.6113 𝑉
2
Digital value = 700:-

11
Value in DACR register = 0x0000AF00

The VALUE under D/A control shows the value of 700 in hexadecimal,
0x02BC and its analog output, AOUT=2.2559. Proving by manual
calculation,
𝐷
𝑉𝑜 = 𝑛 𝑉𝑟
2
700
𝑉𝑜 = 10 (3.3) = 2.2559 𝑉
2

12
Assignment 1

Figure 5.2 shows a simple temperature monitoring system by using the LM35 analog temperature
sensor. Write the program to turn on the “hot” LED when the temperature exceed 35C, turn on the
“cold” LED when the temperature is below 20C and if the temperature is within 20C to 35C, turn on
the “OK” LED. You need to use the LM35 datasheet to determine the output values of the LM35
relative to the temperature.

Answer:

In this case, we assume the value of temperature equal to the value of voltage,
1mv = 1 °C, so
35 °C = 0.35 V
20 °C = 0.2 V

Condition:-
1) if the input value condition is greater than 0.35V in analog or in digital equal to
434, the output of P2.1 will active which is ’hot’ LED will Turn On.
2) If the input value condition is lower than 0.2V in analog or in digital equal to 248,
the output of P2.2 will active which is ‘cold’ LED will Turn On.
3) if the input value condition is between 0.2V and 0.35V, the output of P2.0 will
active which is ‘ok’ LED will Turn On.

C Programming Code

13
#include<lpc17xx.h>
void delay(void);
int main(void)
{
LPC_GPIO2->FIODIR0 = 0x07; // Configure Port2, bit 0,1,2 as output
LPC_SC -> PCONP |= (1<<12); //Enable the ADC Peripheral
LPC_ADC -> ADCR = (1<<1); //Select AD0.1 channel
LPC_ADC -> ADCR |= (1<<21); //Power-on the ADC
LPC_ADC -> ADCR |= (1<<8); //Devide PCLK frequency by 2
LPC_PINCON -> PINSEL1 |= (1<<16) ; //select AD0.1 for P0.24

double result = 0;
while(1)
{
LPC_ADC -> ADCR |= (1<<24); //Start the conversion
while((LPC_ADC -> ADDR1 & (1u<<31)) == 0)
{} //Wait for conversion to finish
result = ((LPC_ADC -> ADDR1 >> 4) & 0xFFF);
//Shift right by 4 and 12 bit Mask to extract result
delay();

if(result > 434) // Equal to Analog > 0.35 V = 35 °C


{
LPC_GPIO2->FIOCLR0 |= (7<<0); // Clear bit 0,1,2 in Port 2
LPC_GPIO2->FIOSET0 |= (1<<1); // Turn On the "hot" LED at P2.1
delay();
}
else if (result <248) // Equal to Analog < 0.2 V = 20 °C
{
LPC_GPIO2->FIOCLR0 |= (7<<0); // Clear bit 0,1,2 in Port 2
LPC_GPIO2->FIOSET0 |= (1<<2); // Turn On the "cold" LED at P2.2
delay();
}
else {
LPC_GPIO2->FIOCLR0 |= (7<<0); // Clear bit 0,1,2 in Port 2
LPC_GPIO2->FIOSET0 |= (1<<0); // Turn On the "ok" LED at P2.0
delay();
}
}
}
void delay(void) //delay function
{
unsigned int count,i=0;
for(count=0; count < 0x1FFFF; count++)
{
i++;
}
}

Result

Condition 1:

14
Condition 2:

15
Condition 3:

16
17
Assignment 2

Write a program to create a sawtooth waveform as shown in Figure 5.4. To view the waveform on a
Logic Analyzer, go to “View > Analysis Windows > Logic Analyzer”. In the Logic Analyzer window,
click “Setup”, then click “New (Insert)” tab. Add signal name as “Aout” (which is the Aout pin).

Answer:

As showns in the Figure 5.4, the step of Sawtooth equal to 20 step while 3V as upper limit and 0V
as lower limit.
Vaout for each steps equal to 0.15V where 3V divide 20 total steps = 0.15.
0.15V will be incremental value, 0.15V need to convert to digital value since in DACR will enter the
value of digital, so 0.15V = 47
3V as upper limit also need to convert to digital value = 931

C Programming Code

#include <lpc17xx.h>

void delay(void);
int main(void)
{
LPC_PINCON -> PINSEL1 |= (1<<21); //Set pin P0.26 as AOUT
unsigned int i;
while(1)
{
for (i=0;i<931;i=i+47){ // 931 = 3V and 47 = 0.15
LPC_DAC -> DACR = (i<<6);
delay();
}
}
}
void delay(void) //delay function
{
unsigned int count,k=0;
for(count=0; count < 0xFFFF; count++)
{
k++;
}
}

18
Result

19
Questions

1. An ideal 8-bit ADC has an input range of 5.12 V. What is its resolution, and what is its greatest
quantization error?

Answer:
5.12
𝑅𝑒𝑠𝑜𝑙𝑢𝑡𝑖𝑜𝑛 = = 20 𝑚𝑉
28
Greatest quantization error = 10 𝑚𝑉

2. Draw a program flowchart which describes a program that continuously reads an analog
temperature sensor output once per second and displays the temperature in degrees Celsius
on a three-digit seven-segment display.

Answer:

20
Conclusion
For ADC:
Analog signal is transformed into digital representation by measuring the input voltage and produces
binary output number, with resolution and at a rate determined by ADC. This conversion can be
calculate manually by,
𝑉𝑖
𝐷= 𝑥 2𝑛
𝑉𝑟
where D = digital value
𝑉𝑖 = input voltage (analog)
𝑉𝑟 = voltage reference (in this lab = 3.3 V)
n = ADC resolution bit (for LPC1768, n = 12)

In ADC peripheral (Keil MDK Vision), the input voltage can be vary (0 to 3.3 V) at the Analog Input
and the result can be observed in A/D Channel Data. In this lab, only one channel must be made
active during conversion and only one conversion can be done at one time.

For DAC:
Binary input value turned into analog output. Formula used is,
𝐷
𝑉𝑜 = 𝑉
2𝑛 𝑟
where 𝑉𝑖 = input voltage (analog)
D = digital value
𝑉𝑟 = voltage reference (in this lab = 3.3 V)
n = DAC bit (for LPC1768, n = 10)

In Keil MDK Vision, the digital input can be vary at the coding file and the result can be observed at
Analog Output in DAC peripheral. The DACR used also shown with VALUE, that shows binary value
that want to be converted.

In this lab, the LPC1700 Series reference Manual and the datasheet for LPC1768 is used. For ADC, it
is important to know which ADC channel is used with its suitable ADC input pin like PINSEL1. Same
goes for DAC.

21

You might also like