You are on page 1of 9

EEL 4746 – Microcomputer I

Assignment 4
1. Explain the differences between using polling and event driven techniques for
testing the state of one of the digital input pins on a microcontroller.
ANS: Polling is known to be the method of reading or writing a single value from a data
acquisition system. The time between polled readings is scheduled by the operating system, such
as Windows. Therefore, it is not deterministic and depends on multiple factors in the system,
such as computer speed, operating systems, programming languages, and code optimization. A
background operation, also known as DMA or Interrupt driven operation, is a task that runs
under the control of the data acquisition hardware and notifies the application when it is
complete. The time between background readings is clocked by the data acquisition hardware
and is independent of Windows timing. During a background data transfer, the data acquisition
hardware interrupts the CPU and the driver handles these interrupts by transferring the data into
the application memory space. In addition, when the requested background operation is finished,
the driver posts a Windows message or event to the application that will respond to this event
and manipulate the data. While a polled operation is simple to program, it is generally advisable

m
to use event-driven operations because they are more portable, robust, and less dependent on the

er as
operating system timing.

co
eH w
o.
2. List the most significant actions that a CPU takes when it responds to an enabled
interrupt. rs e
ou urc
ANS: The hardware of the CPU does the exact same thing for each interrupt, which is what
o

allows operating systems to take control away from the current running user process. The
aC s

switching of running processes to execute code from the OS kernel is called a context switch.
vi y re

I. Using the pointer to the current process control block, the state and all register values for
the process are saved for use when the process is later restarted.
II. The CPU mode bit is switched to supervisory mode.
ed d

III. Using the pointer to the interrupt handler table and the interrupt vector, the location of the
ar stu

kernel code to execute is determined. The interrupt vector is the IRQ for hardware
interrupts (read from an interrupt controller register) and an argument to the interrupt
assembly language instruction for software interrupts.
is
Th

3. Explain the following terms with respect to interrupts:

Priority A priority interrupt is a system which decides the priority at which various devices,
which generates the interrupt signal at the same time, will be serviced by the CPU. The
sh

system has authority to decide which conditions are allowed to interrupt the CPU, while
some other interrupt is being serviced. Generally, devices with high speed transfer such
as magnetic disks are given high priority and slow devices such as keyboards are given low
priority. When two or more devices interrupt the computer simultaneously, the computer
services the device with the higher priority first.

This study source was downloaded by 100000828830581 from CourseHero.com on 07-02-2021 06:45:04 GMT -05:00

https://www.coursehero.com/file/77126665/Assignment-4docx/
EEL 4746 – Microcomputer I
Assignment 4

Latency:
Interrupt latency, also called interrupt response time, is the length of time that it takes for a
computer interrupt to be acted on after it has been generated. In most computers, a trade-off
exists among interrupt latency, throughput, and processor utilization. An interrupt is a signal
from a device attached to a computer, or from a program within the computer, that tells
the OS (operating system) to stop and decide what to do next. Minimum interrupt latency
depends mainly on the configuration of the interrupt controller, which combines interrupts
onto processor lines, and assigns priority levels to the interrupts.

Nesting: The term “nested” refers to the fact that in NVIC, a number of interrupts (up to several
hundred in some processors) can be defined, and each interrupt is assigned a priority, with “0”

m
er as
being the highest priority. In addition, the most critical interrupt can be made non-mask able,

co
meaning it cannot be disabled (masked).

eH w
o.
One function of NVIC is to ensure that higher priority interrupts are completed before lower-
rs e
priority interrupts, even if the lower-priority interrupt is triggered first. For example, if a lower-
ou urc
priority interrupt is being registered* or executed and a higher-priority interrupt occurs, the CPU
will stop the lower-priority interrupt and process the higher-priority one first.
o

4. A comparator circuit and LM35 are to be used to create an interrupt source, using the
aC s

circuit of Figure 9.5. The comparator is supplied from 5.0 V, and the temperature threshold
vi y re

is to be approximately 38oC. Suggest values for R1 and R2. Resistor values of 470, 680, 820,
1k, 1k2, 1k5 and 10k are available.
ed d

Solution: We have calculate the result and find the final result that is for the circuit of 9.5 figure
ar stu

we need to use the resistor having the values of R1= R2=680 ohm.
Figure of circuit:
is
Th
sh

This study source was downloaded by 100000828830581 from CourseHero.com on 07-02-2021 06:45:04 GMT -05:00

https://www.coursehero.com/file/77126665/Assignment-4docx/
EEL 4746 – Microcomputer I
Assignment 4
6. What is the maximum value, in decimal, that a 12-bit and a 24-bit counter can count up
to?

ANS: for 12 bit we use this formula, Max value= 2^12-1=2048 and for the 24 bit the counter
value is =2^24-1=8388608.

7. A 4.0 MHz clock signal is connected to the inputs of a 12-bit and a 16-bit counter. Each
starts counting from zero. How long does it take before each reaches its maximum value?

Solution: for the counting of 12bit


Clock-speed = 4 MHz Counter = 12bit
Time to count = 1/clock-speed=0.00025ms
max value= 2*12-1
time to require at maximum value = max-value*Time required = (2*12-1)*0.00025ms
1.02375 ms

m
er as
co
Second part:

eH w
o.
for 10 bit: Clock speed = 4Mhz Counter = 16bit
rs e
Time to count = 1/clock-speed=0.00025ms
ou urc
Max value= 2*16-1
Time to require at maximum value = max-value*Time required = (2*16-1)*0.00025ms
16.38375ms
o
aC s

8. A 10-bit counter, clocked with an input frequency of 512 kHz, runs continuously. Every
vi y re

time it overflows, it generates an interrupt. What is the frequency of that interrupt stream?
Solution: So now put the value and calculate,
Counter = 10bit and Clock= 512khz
ed d

as we know that Time to count = 1/clock-speed=0.001953125ms


ar stu

as we know that max value= 2*10-1


time to required overflow = 2^10* Time required to count 1
= (2^10-1)*0.001953125ms
=2ms
is

Now we will Calculate the Frequency= 1/2*10^-3= 0.5kHz.


Th

Programming Assignment, Please note that all the programming assignments in this
sh

courses are for the mbed board with LPC1768 microcontroller that is referred to in
the text book and is used for labs.

1. There are two push buttons connected to pins 5 and 6, the other terminal of both push buttons
is connected to Vought. Write a C program to implement the following procedure using

This study source was downloaded by 100000828830581 from CourseHero.com on 07-02-2021 06:45:04 GMT -05:00

https://www.coursehero.com/file/77126665/Assignment-4docx/
EEL 4746 – Microcomputer I
Assignment 4
interrupts:
The procedure is that LED1 flashes continuously, but when push button connected to pin 5 is
pressed, LED2 turns on for 5 seconds then they turn off. If the push button connected to pin 6 is
pressed, LED3 turns on for 10 seconds and then it turns off.
You must enable interrupts on pins 5 and 6 in a manner that when push button is pressed
interrupt is sent to microcontroller.

What happens when both push buttons are pressed at the same time?
ANS: when I have pressed same button leds are blinking as I have designed in the code first
led1 is glowing continuously , suppose I have press the button then according the button Leds are
blinking 5s and 10 then again program goes same state.

m
er as
co
eH w
o.
rs e
ou urc
o
aC s
vi y re
ed d
ar stu
is
Th
sh

This study source was downloaded by 100000828830581 from CourseHero.com on 07-02-2021 06:45:04 GMT -05:00

https://www.coursehero.com/file/77126665/Assignment-4docx/
EEL 4746 – Microcomputer I
Assignment 4
Program:

m
er as
co
eH w
o.
rs e
ou urc
o
aC s
vi y re
ed d
ar stu
is
Th

2. Write a program that implements a similar procedure without using interrupts

ANS: I have just add the Interrupt call. So code is given below.
sh

This study source was downloaded by 100000828830581 from CourseHero.com on 07-02-2021 06:45:04 GMT -05:00

https://www.coursehero.com/file/77126665/Assignment-4docx/
EEL 4746 – Microcomputer I
Assignment 4

m
er as
co
eH w
o.
rs e
ou urc
o
aC s
vi y re
ed d
ar stu
is
Th
sh

4. Write a C program to implement a reaction timer application. A reaction timer is


used to
measure the time a person takes to respond to a visual stimulus. Once reset is
pressed, after 30 second, your program must turn on LED1, then measures the time

This study source was downloaded by 100000828830581 from CourseHero.com on 07-02-2021 06:45:04 GMT -05:00

https://www.coursehero.com/file/77126665/Assignment-4docx/
EEL 4746 – Microcomputer I
Assignment 4
a person takes to press a push button in response. Display this time in millisecond on
Tera terminal. Connect the push button to pin 5.
5.

m
er as
co
eH w
o.
rs e
ou urc
o
aC s
vi y re
ed d
ar stu
is
Th
sh

6. There are two push buttons connected to pins 5 and 6, the other terminal of both
push buttons is connected to Vout. The following C program implements the
following procedure:
 Ticker identifier is used to flash LED1 every 0.2 second.

This study source was downloaded by 100000828830581 from CourseHero.com on 07-02-2021 06:45:04 GMT -05:00

https://www.coursehero.com/file/77126665/Assignment-4docx/
EEL 4746 – Microcomputer I
Assignment 4
 When push button connected to pin 5 is pressed Timeout identifier is used to blink
LED2 once 2 seconds after the button is pressed.
 When the push button connected to pin 6 is pressed, an interrupt is sent to mbed to
turn on LED3 for 5 seconds and then it turns off.

ANS: Program:

m
er as
co
eH w
o.
rs e
ou urc
o
aC s
vi y re
ed d
ar stu
is
Th
sh

Circuit:

This study source was downloaded by 100000828830581 from CourseHero.com on 07-02-2021 06:45:04 GMT -05:00

https://www.coursehero.com/file/77126665/Assignment-4docx/
EEL 4746 – Microcomputer I
Assignment 4

m
er as
co
eH w
o.
rs e
Table: Show the hard ware results like 0= low and 1= High
ou urc
LED1 status LED3 status
LED2 status
o

No button pressed 1 0 0
aC s

Button1 (pin5) 1
vi y re

pressed and then 0 0


released
Button2 (pin6)
pressed and then 0 0 1
ed d

released
ar stu

Button1
pressed/released first, 0 0 1
next Button2
is

Button2
pressed/released first, 0 0 1
Th

next Button1
sh

This study source was downloaded by 100000828830581 from CourseHero.com on 07-02-2021 06:45:04 GMT -05:00

https://www.coursehero.com/file/77126665/Assignment-4docx/
Powered by TCPDF (www.tcpdf.org)

You might also like