Lab 8

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

Student Names:Zeki TEL 2013400015 İhsan Berkan BALABAN

2014400138

CMPE 443 PRINCIPLES OF EMBEDDED SYSTEMS DESIGN

LAB #008

“Multiple Interrupts”
“Power Saving”
Motivation

In this experiment, we will study multiple interrupts where one interrupt will invoke
another interrupt. Besides, we will use special instructions to observe their effects in power
saving when they are used with interrupts. So in this experiment you will learn
● programming output compare timer function to generate an interrupt.
● programming an interrupt handler to generate another interrupt.
● using an interrupt handler to handle multiple interrupt requests.
● observing power saving when special instructions are used.

1) External Interrupt 4 pts

When you pressed the push button on the LPC4088 which is shown in the figure, you can
give External Interrupt to board.

In External.h file:

- What is the pin name of the pin which is connected to Push Button? (PX_Y) __
P2_10 0.5 pts
- Write the IOCON address of the push button to
IOCON_PUSH_BUTTON_ADDRESS. 0x4002 C128 0.5 pts
- Write the address of the External Interrupt Flag register to EXT_ADDRESS
0x400F C140 0.5 pts

In External.c file:
Student Names:Zeki TEL 2013400015 İhsan Berkan BALABAN
2014400138

- Change the functionality of the push button as EINT0


- uint32_t temp=IOCON_PUSH_BUTTON;
- temp|=1;
- temp&=~(6);
- IOCON_PUSH_BUTTON=temp;
0.5 pts
- Change the External interrupt mode as Edge Sensitive
- EXT->EXTMODE|=1<<0;
0.5 pts
- Enable interrupt for EINT0_IRQn.
NVIC_EnableIRQ(EINT0_IRQn)
; 1 pt
- Whenever an interrupt occurs, it should be cleared in handler. Clear interrupt for
EINT0. EXT->EXTINT|=1<<0; 0.5
pts

2) Methods for Low Power 7 pts

In order to change the power mode of the board. You will use SCR (System Control
Register) and PCON register.

- Write the address of these registers to the SystemStructures.h file.


- PCON 0x400FC0C0 1 pt
- SCR 0xE000ED10

In PowerConsumptionTest method:

a) Sleep Mode

In this part, you should change the LAB_8 code for entering the sleep mode. Your code
should go to Sleep Mode after you pressed Joystick Left Button and turn on all the 4 LEDs.
(When you pressed the push button on the LPC4088 which is shown in the figure, the
EINT0_IRQHandler will be called and board will wake up)

- What should be the value of SCR register value for Sleep Mode?
SCR &=~(4); 0.5 pts
- What should be the value of PCON register value for Sleep Mode?
PCON&=~(3);0.5 pts
Write the necessary code in SleepMode method and call it when Joystick Left Button is
pressed.

- Find Current while LED on in the Sleep Mode. 10.0 0.5 pts
Student Names:Zeki TEL 2013400015 İhsan Berkan BALABAN
2014400138

(Hint: You can check it is in sleep mode or not by pressing joystick center button. If no led
is turned off, it means it is in sleep mode)
(Hint: Do not forget __WFI();)

b) Deep Sleep Mode

Your code should go to Deep Sleep Mode after you pressed Joystick Right Button and turn on
all the 4 LEDs.

- What should be the value of SCR register value for Deep Sleep Mode?
SCR|=1<<2; 0.5 pts
- What should be the value of PCON register value for Deep Sleep Mode?
PCON&=~(3);0.5 pts
Write the necessary code in DeepSleepMode method and call it when Joystick Right Button
is pressed.

- Find Current while LED on in the Deep Sleep Mode. 9.4 0.5 pts

c) Power Down Mode

Your code should go to Power Down Mode after you pressed Joystick Up Button and turn on
all the 4 LEDs.

- What should be the value of SCR register value for Power Down Mode?
SCR|=1<<2; 0.5 pts
- What should be the value of PCON register value for Power Down Mode?
PCON&=~(2);0.5 pts
Write the necessary code in PowerDownMode method and call it when Joystick Up Button is
pressed.

- Find Current while LED on in the Power Down Mode. 9.4 0.5 pts

d) Deep Power Down Mode


Student Names:Zeki TEL 2013400015 İhsan Berkan BALABAN
2014400138

Your code should go to Deep Power Down Mode after you pressed Joystick Up Button and
turn on all the 4 LEDs.

- What should be the value of SCR register value for Deep Power Down Mode?
SCR|=1<<2; 0.5 pts
- What should be the value of PCON register value for Deep Power Down Mode?
PCON&=~(3);0.5 pts
Write the necessary code in DeepPowerDownMode method and call it when Joystick Down
Button is pressed.

- Find Current in the Deep Power Down Mode. 7,4 0.5 pts

3) Ultrasonic Sensor with Interrupts 7 pts

In previous lab, you used polling method for sending trigger signal to Ultrasonic sensor.
However in this lab you will use Timer2 and Timer3 interrupts and also you will send trigger
signal via Timer2 interrupt.

Connect Ultrasonic Sensor same as the previous lab file.

HC - SR04 Pins LPC4088 Pins

Vcc VU

GND GND

Trig P11 (P0_9)

Echo P16 (P0_24)

In Ultrasonic_Trigger_Timer_Init (in Ultrasonic.c file) method:

Write the Correct Configuration for EMR (Toggle Output Value and Initial value is HIGH)
uint32_t temp=TIMER2->EMR;

- temp|=1<<5;
- temp|=1<<6;
- TIMER2->EMR=temp; 0.5 pts
Student Names:Zeki TEL 2013400015 İhsan Berkan BALABAN
2014400138

- Enable TIMER2_IRQn (Interrupt Request).


- NVIC_EnableIRQ(TIMER2_IRQn); 0.5 pts
- Set Priority Timer2 IRQ as 5.
NVIC_SetPriority(TIMER2_IRQn,5);
- ___________ 0.5 pts
- Clear pendings for Timer2.
- NVIC_ClearPendingIRQ(TIMER2_IRQn); ___________ 0.5 pts

In Ulrasonic_Start_Trigger (in Ultrasonic.c file) method:

- Give correct value to MR3 Register for 10 microsecond


- TIMER2->MR3=PERIPHERAL_CLOCK_FREQUENCY/1000000*10; 0.5
pts
- Enable interrupt for MR3 register, if MR3 register matches the TC.
- TIMER2->MCR|=1<<9;
0.5 pts
- Remove the reset on counters of Timer2.
- TIMER2->TCR&=~(2); 0.5 pts
- Enable Timer2 Counter and Prescale Counter for counting
- TIMER2->TCR|=1<<0; 0.5 pts

In TIMER2_IRQHandler (in Ultrasonic.c file):

- Change MR3 Register Value for Suggested Waiting


- TIMER2->MR3=PERIPHERAL_CLOCK_FREQUENCY/1000*60; 0.5 pts
- Clear pendings for Timer3.
- NVIC_ClearPendingIRQ(TIMER3_IRQn); 0.5 pts
- Enable TIMER3_IRQn (Interrupt Request).
- NVIC_EnableIRQ(TIMER3_IRQn); 0.25 pts
- Clear IR Register Flag for Corresponding Interrupt
- TIMER3->IR&=~(8); 0.25 pts

In TIMER3_IRQHandler (in Ultrasonic.c file):

- Clear pendings for Timer3.


- NVIC_ClearPendingIRQ(TIMER3_IRQn); 0.5 pts
- Disable TIMER3_IRQn (Interrupt Request).
- NVIC_DisableIRQ(TIMER3_IRQn); 0.5 pts

4) Using Ultrasonic Sensor 5 pts

In this part, you will write codes into update method for:
Student Names:Zeki TEL 2013400015 İhsan Berkan BALABAN
2014400138

- When Ultrasonic Sensor detects obstacles which are closer than 7cm, turn on all the
LEDs. ___________ 0.5 pts
- When Ultrasonic Sensor detects obstacles which are in the range of 7cm and 12cm , turn
on LED1, LED2 and LED3. ___________ 0.5 pts
- When Ultrasonic Sensor detects obstacles which are in the range of 12cm and 20cm , turn
on LED1 and LED2.
- When Ultrasonic Sensor detects obstacles which are in the range of 20cm and 30cm , turn
on LED1. ___________ 0.5 pts
- When Ultrasonic Sensor detects obstacles which are far from 30 cm, turn off all the
LEDs. ___________ 0.5 pts

5) Power Saving 2 pts

In part 2, you have used four power saving modes. Can you use all of them in the update
method of Part 4? If you think that a method can be used in part 4, then use it and write your
observations. If not, then write the reason.

Method Yes/No Yes: Observations No: Reason

Sleep Yes It works

Deep Sleep No Doesn’t work

Power Down No Doesn’t work

Deep Power Down No Doesn’t work

You might also like