0% found this document useful (0 votes)
8 views10 pages

Lab Report 8 MP

The document outlines Lab-08 for EEE-342 Microprocessor Systems and Interfacing, focusing on external and internal interrupts in AVR microcontrollers. It includes objectives, pre-lab concepts, in-lab tasks involving coding and simulation, and post-lab analysis on switch debouncing methods. The lab aims to familiarize students with configuring interrupts and analyzing their functionality through practical tasks and critical analysis.

Uploaded by

Obaid
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)
8 views10 pages

Lab Report 8 MP

The document outlines Lab-08 for EEE-342 Microprocessor Systems and Interfacing, focusing on external and internal interrupts in AVR microcontrollers. It includes objectives, pre-lab concepts, in-lab tasks involving coding and simulation, and post-lab analysis on switch debouncing methods. The lab aims to familiarize students with configuring interrupts and analyzing their functionality through practical tasks and critical analysis.

Uploaded by

Obaid
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/ 10

EEE-342 MICROPROCESSOR SYSTEMS AND

INTERFACING
Lab-08

M.OBAID TAHIR
NAME M.MUBASHIR AWAN
M.UMAR SHAHID

REGISTRATION NUMBER FA22-BEE-193


FA22-BEE-167
FA22-BEE-183

CLASS/SECTION BEE-5A

INSTRUCTOR DR.SHARUGH AGHA

Lab Assessment

Post Lab Total


In-Lab
Data
Data Analysis Writing Style
Presentation
External and Internal Interrupts in AVR Microcontrollers
Objectives
 To learn the concepts related to interrupts in AVR microcontroller
 To configure and use the external interrupt or user input tasks
 To configure and use the internal interrupts

Software Tools
 MicrochipStudio or AVR Studio
 Proteus
 AVRDUDESS

Hardware Tools:

Pre Lab:
What is Interrupt?
An interrupt refers to a notification, communicated to the controller, by a hardware device or
software, on receipt of which controller momentarily stops and responds to the interrupt.
Whenever an interrupt occurs the controller completes the execution of the current instruction
and starts the execution of an Interrupt Service Routine (ISR) or Interrupt Handler. ISR is a piece
of code that tells the processor or controller what to do when the interrupt occurs. After the
execution of ISR, controller returns back to the instruction it has jumped from (before the
interrupt was received). The interrupts can be either internal interrupts or external interrupts. IN-
LAB Tasks Task 1: Generate binary counting with the help of LED’s interfaced by MCU and
controlled by 2 Switches. One for enabling the circuit and the other is to reset it. Switch pressing
is an external event, that’s why we use external interrupts. Write the C code for Interrupts and
simulate in Proteus.

External Interrupts:
The External Interrupts are triggered by the INT pins or any of the PCINT pins. The Pin Change
Interrupt Request 2 (PCI2) will trigger if any enabled PCINT[23:16] pin toggles. The Pin
Change Interrupt Request 1 (PCI1) will trigger if any enabled PCINT[14:8] pin toggles. The Pin
Change Interrupt Request 0 (PCI0) will trigger if any enabled PCINT[7:0] pin toggles. The
interrupts. Pin change interrupts on PCINT are detected asynchronously.
The External Interrupts can be triggered by a falling or rising edge or a low level. This is set up
as indicated in the specification for the External Interrupt Control Register A (EICRA). Internal
Interrupts: ATmega328p has 20 internal interrupts. These internal interrupts are generated by the
internal peripherals of Microcontroller like Timer, ADC etc. The internal interrupts are used for
efficient operation of the internal peripherals. They can be enabled through the registers of these
peripheral
IN-LAB Task 1:

Generate binary counting with the help of LED’s interfaced by MCU and controlled by 2
Switches. One for enabling the circuit and the other is to reset it. Switch pressing is an
external event, that’s why we use external interrupts. Write the C code for Interrupts and
simulate in Proteus.
a) Code:

Simulation:
b) Hardware: Implement In Lab task 1 on hardware.
In Lab Task 2:
Assume that INT1 pin is connected to a switch that is normally low. Write a program that
toggles PORTC 20 times with some delay whenever INT1 pin goes high
Code:

Simulation:
In Lab Task 3:
Record a signal using ADC. Use ADC in free running mode. Add 8-bit DAC at Port D and
convert back the signal in analog and display result on oscilloscope for comparison
Code:
Simulation:
POST-LAB Tasks 1:
What is switch debouncing? Explain software and hardware methods for switch
debouncing.

When a mechanical switch is flipped/pressed, the metal contacts inside may not open or close
cleanly. In the microseconds before the switch achieves a good solid connection, the switch's
contacts may "bounce" against each other, turning the switch on and off in rapid succession.
Even though the bounce only lasts milliseconds, a microprocessor is fast enough to tell the
difference, and it will think that the switch was pressed twice when it was actually only pressed
once. We can remedy this problem by debouncing the switch. The hardware and software
methods for debouncing are given below

1) Hardware Debouncing:
Hardware debouncing technique uses an S-R latch to avoid bounces in the circuit along
with the pull up resistors. S-R circuit is most effective of all debouncing approaches. The
figure below is a simple debouncing circuit which is often used

The circuit uses two cross coupled NAND gates which form an S-R latch, A SPDT (Single Pole
Double Throw) switch, two pull up resistors. The resistor generates a logic ‘one’ for the gates,
Switch pulls one of the inputs to ground.
If the switch is in position as shown in figure the output of the upper gate is ‘1’ irrespective of
the input of the other gate and the one created by the bottom pull up resistor which drives the
lower NAND gate to zero which in return races back to the other gate. If the switch moves back
and forth between the contacts and is suspended for a while in neither region between the
terminals, the latch maintains its state because ‘0’ from the bottom NAND gate is fed back. The
switch may move between the contacts but the latch’s output ensures it never bangs back and
thus switch is bounce free. Switch debouncing can also be done by specialized IC’s. There are
only a few of them (such as MAX6816, MAX6817, MAX6818) and are rarely used.
2) Software Debouncing:
There are two methods for software debouncing.
 Using counters
 Using shift registers
The algorithms for these methods are given below:

Counter Method:
1. Initially set up a count value to zero
2. Using a timer set up a sampling event with a period (say 1 ms)
3. On the sample event:
4. If switch signal high, then
5. Set count=0
6.Set internal switch state released
7. else
8. Increment count to a max of 10
9. end if
10. if count =10 then
11. Set internal switch state to pressed
12. end if

Shift Register Method


Similar to that of counter method. Only difference is that it uses shift register. The algorithm
assumes unsigned 8 bit reg value usually found in microcontrollers
1. Initially set up a shift register variable to 0xFF
2. Using a timer set up a sampling event with a period (say 1 ms)
3. On the sample event:
4. Shift the variable towards MSB
5. Set LSB to current switch value
6. if shift register value =0 then
7. Set internal switch state to pressed
8. else
9. Set internal switch state to released
10. end if
CRITICAL ANALYSIS:
This lab was intended to familiarize students with internal and external interrupts of AVR
microcontroller and how to configure the said interrupts. For this purpose, a total of 3 lab tasks
were designed, a brief description of which is given as follows:

1. Task 1: In this task, a simple had counter had to be created using external interrupts
INT0 and INT1. The interrupts were first globally enabled by setting the seventh bit of
the status register (SREG). There were two push buttons attached to both of the interrupts
and they were set such that whenever INT0 was pressed, the counter value increased and
whenever INT1 was pressed, the counter was reset. The Interrupt sense control bits
(ISCxx) for both INT0 and INT1 were configured such that the falling edge of these
interrupts generated an interrupt request. The rest of code was already given in the lab
manual.

2. Task 2: In this task, output toggling had to be done twenty times once the push button
connected to INT1 was pressed. For this purpose, the interrupt service routine (ISR) for
INT1 was set to only include a for-loop which would run twenty times and toggle the
values at PORTB for each iteration of the loop. As the toggling had to be done once the
push button was pressed, thus, the ISCxx bits were configured for the rising edge mode.

3. Task 3: This task involved use of the knowledge that was gained back in Lab 07. A
signal had to be recorded and converted using an Analog to Digital converter (ADC).
Then it had to be converted back using a Digital to Analog converter (DAC) at the
output. The ADC was configured for free running mode. The rest of the task involved
techniques used in tasks 1 and 2. The only thing that was done for the first time in this lab
was the manipulation of certain bits of ADCRSA register in order to achieve the desired
configuration. After comparison of the input and output on an oscilloscope in simulation, the
output was found to have had lost some amount of data.

You might also like