0% found this document useful (0 votes)
218 views19 pages

About Students: Name Matric No. Section

The document contains information about an electronics engineering laboratory experiment submitted by 4 students to their instructor. It includes: 1) Student names and matric numbers who participated in the experiment. 2) The title and submission date of the experiment - "Lab 6: Interrupt, Timer and PWM in ARM Cortex-M3 Microcontroller (LPC1768)". 3) A grading rubric for the instructor to evaluate the experiment submission under various domains and criteria.

Uploaded by

sarah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
218 views19 pages

About Students: Name Matric No. Section

The document contains information about an electronics engineering laboratory experiment submitted by 4 students to their instructor. It includes: 1) Student names and matric numbers who participated in the experiment. 2) The title and submission date of the experiment - "Lab 6: Interrupt, Timer and PWM in ARM Cortex-M3 Microcontroller (LPC1768)". 3) A grading rubric for the instructor to evaluate the experiment submission under various domains and criteria.

Uploaded by

sarah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

FACULTY OF ELECTRICAL AND ELECTRONIC ENGINEERING

UNIVERSITI TUN HUSSEIN ONN MALAYSIA

BEJ40401 ELECTRONICS ENGINEERING LABORATORY IV

About Students:
Name Matric No. Section:
1. ARDY SYAZZWAN BIN JIBA CE180078 Instructor’s Name:
2. MUHAMMAD DINIE BIN MAZLAN CE180088 Ir. Ts. Dr. NORFAIZA BINTI FUAD
3. MOHD ZAID IZUDDIN BIN ZULKAPLI CE180133
4. AIMAN BIN ROSLI CE180137

About Experiment:
Title Submission date
Lab 6: Interrupt, Timer and PWM in ARM Cortex-M3 Microcontroller 18/01/2022
(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
Peer Assessment (to be filled in by the group leader)

Group leader full name : MOHD ZAID IZUDDIN BIN ZULKAPLI


Group member 1 full name : MUHAMMAD DINIE BIN MAZLAN
Group member 2 full name : AIMAN BIN ROSLI
Group member 3 full name : ARDY SYAZZWAN BIN JIBA

- 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

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


Pre-Lab (5%)

1. List the most significant actions that a CPU takes when it responds to an enabled
interrupt. (3 marks)
the processor can be interrupted for a number of reasons such as a hardware device has
signaled that it has data to process. A hardware device has completed a task. So when an
interrupt enabled, the CPU will have to stop execute the current program. The control then
passes to a special piece of code called an interrupt handler or interrupt service routine.

2. What is the maximum value, in decimal, that a 12-bit and a 24-bit counter can count up
to? (1 mark)
4096

3. The LPC1768 has how many PWM outputs? (1 mark)


Pulse Width Modulation (PWM) is modulation technique that generates Variable-width pulses
to represent the amplitude of an analog input signal. Thus, LPC1768 has 6 PWM output pin.
LAB ACTIVITY 6.0

ACTIVITY 1.
LAB ASSIGNMENT 6.1
Modify program:
LAB ASSIGNMENT 2

Activity 2

Assignment 2

#include <LPC17xx.h>

void Init_Wait(void);

void wait_us(int t);

int main(void)

Init_Wait();

LPC_GPIO1->FIODIR |=(1<<0);

while (1)
{

LPC_GPIO1->FIOSET |=(1<<0);

wait_us(1);

LPC_GPIO1->FIOCLR |= (1<<0);

wait_us(1);

void Init_Wait(void)

LPC_TIM3->CTCR = 0; //timer mode

LPC_TIM3->PR = 49; //for 1s resolution

void wait_us(int t)

LPC_TIM3->TCR = 1<<1; //reset timer counter

LPC_TIM3->TCR = 1; //enable timer counter

while (LPC_TIM3->TC < t); //wait if conter < t

}
LAB ACTIVITY 6.3

Lab Assignment 6.3:

Create PWM signals with different duty cycles on PWM1.1, PWM1.2 and PWM1.3. i.e., PWM1.1
= 20% duty cycle, PWM1.2 = 50% duty cycle, and PWM1.3 = 80% duty cycle. Observe the
outputs on the Logic Analyzer.
The Program:

#include <LPC17xx.h>
void Init_Wait(void);
void wait_ms(int t);
int main(void)
{
Init_Wait();
LPC_PINCON->PINSEL4 |= (21<<0); //Set pin function to (PWM1.1,
P2.0),(PWM1.2,P2.1),(PWM1.3, P2.2)
LPC_PWM1->PCR = (7<<9); //PWM1,PWM2,PWM3 output enabled
LPC_PWM1->PR = 24;//Prescaler 1us resolution
LPC_PWM1->MCR |= (1<<1); //Reset on PWM MR0 & TC if it matches MR0
LPC_PWM1->MR0 = 10000; //set PWM cycle to 10 ms
LPC_PWM1->MR1 = 2000; //Set 20% Duty Cycle to (PWM1.1, P2.0)
LPC_PWM1->MR2 = 5000; //Set 50% Duty Cycle to (PWM1.2, P2.1)
LPC_PWM1->MR3 = 8000; //Set 80% Duty Cycle to (PWM1.3, P2.2)
LPC_PWM1->LER = (1<<3) |(1<<2) |(1<<1) | (1<<0); //latch values in MR3,MR2,MR1 and MR0
LPC_PWM1->TCR = (1<<0) | (1<<3); //enable counters and PWM Mode
while(1)
{
}
}
void Init_Wait(void)
{
LPC_TIM0->CTCR = 0; //timer mode
LPC_TIM0->PR = 24999; //for 1ms resolution
}
void wait_ms(int t)
{
LPC_TIM0->TCR = 1<<1; //reset timer counter
LPC_TIM0->TCR = 1; //enable timer counter
while (LPC_TIM0->TC < t); //wait if conter < t
}
Lab Assignment 6.4:

(a) 0V produce 0% duty cycle

(b) 3V produce 100% duty cycle


Figure above shows the result from logic analyzer. It can be observed that when the input
voltage is 0V, the duty cycle is 0% and when the input voltage is 3V, the duty cycle is 100%.
It can also be noticed that with the increase in input voltage, the duty cycle increases.

The Program:

#include <LPC17xx.h>
void Init_Wait(void);
void wait_ms(int t);
int main(void)
{
Init_Wait();
LPC_SC -> PCONP |= (1<<12); //Enable the ADC Peripheral
LPC_ADC -> ADCR = (1<<0); //Select AD0.0 channel
LPC_ADC -> ADCR |= (1<<21); //Power-on the ADC
LPC_ADC -> ADCR |= (1<<8); //Devide PCLK frequency by 2
LPC_PINCON -> PINSEL1 |= (1<<14) ; //select AD0.0 for P0.23
LPC_PINCON->PINSEL4 |= (1<<0); //Set pin function to (PWM1.1, P2.0)
LPC_PWM1->PCR = (1<<9); //PWM1
LPC_PWM1->PR = 24;//Prescaler 1us resolution
LPC_PWM1->MCR |= (1<<1); //Reset on PWM MR0 & TC if it matches MR0
LPC_PWM1->MR0 = 10000; //set PWM cycle to 10 ms
LPC_PWM1->LER = (1<<1) | (1<<0); // MR1 and MR0
LPC_PWM1->TCR = (1<<0) | (1<<3); //enable counters and PWM Mode
int result = 0;
while(1)
{
LPC_ADC -> ADCR |= (1<<24); //Start the conversion
while((LPC_ADC -> ADDR0 & (1u<<31)) == 0)
{} //Wait for conversion to finish
result = ((LPC_ADC -> ADDR0 >> 4) & 0xFFF);
//Shift right by 4 and 12 bit Mask to extract result
if(result == 0) // 0 is Digital Value that Equal to Analog = 0V
{
LPC_PWM1->MR1 = 0; //Set 100% Duty Cycle to (PWM1.1, P2.0)
LPC_PWM1->LER = (1<<1); //latch value in MR1
}
else if (result == 3723) // 3723 is Digital Value that Equal to Analog = 3V
{
LPC_PWM1->MR1 = 10000; //Set 100% Duty Cycle to (PWM1.1, P2.0)
LPC_PWM1->LER = (1<<1); //latch value in MR1
}
else // if Analog Value Between 0V and 3V @ Optional
{
LPC_PWM1->MR1 = 5000; //Set 50% Duty Cycle to (PWM1.1, P2.0)
LPC_PWM1->LER = (1<<1); //latch value in MR1
}
}
}
void Init_Wait(void)
{
LPC_TIM0->CTCR = 0; //timer mode
LPC_TIM0->PR = 24999; //for 1ms resolution
}
Questions

6.1 By referring to the “startup_PLC17xx.s” file, give the interrupt number for Timer0 to
Timer3, and GPIO, respectively. (4 marks)

32 bit

6.2 Explain why in the interrupt handler, the interrupt must be cleared?

(4 marks)

to service the device and stop it from interrupting. Once the handler returns, the CPU
resumes what it was doing before the interrupt occurred.

6.3 Determine the value in the prescale register (PR) if the timer resolution of 5 ms is
required. (4 marks)

5kHz

6.4 Explain the function of the prescale counter (PC) and its relation to the PR. (3 marks)

Prescale register is used to define the resolution of the timer. If the {R is 0 then TC in
incremented every 1 clock cycle of the peripheral clock. The 32-bit is a counter which is
increment to the value stored in PR.
CONCLUSION

Upon completing the Lab 6, on an ARM cortex-M3 microcontoller, Lab 6 demonstrates an


interrupt, timer and PWM (LPC1768). Interrupts are used to provide a quick response to random,
unexpected events while incurring minimal overhead. While timers are an essential component of
modern microcontrollers. The LPC1768 has four Timer peripherals that are identical: Timer0,
Timer1, Timer2, and Timer3.Each of the four timers is 32-bit and has a 32-bit prescale that can be
configured. They are meant to count the cycles of a peripheral clock or an external clock signal
and, if desired, generate an interrupts (or other actions) in response to timer values that have been
set (based on four match registers). Learn how to modify a programmed by changing the interrupt,
generating a timer resolution, and so on. Generating PWM signals with a variable duty cycle and
generating PWM signals

You might also like