Student Name: ______

Student Number: ______

THE UNIVERSITY OF NEW SOUTH WALES

July 2005

COMP3221

MICROPROCESSORS AND EMBEDDED SYSTEMS

1)  Time Allowed: 3 Hours

2)  Total Number of Questions: 4 Questions (multiple Parts in each Question)

3)  Answer All Questions

4)  Open book

5)  No electronic calculators are permitted.

PRINT YOUR STUDENT NUMBER AND NAME ON TOP RIGHT HAND CORNER OF THIS PAPER.

ALL ANSWERS SHOULD BE WRITTEN IN THE SPACES PROVIDED ON THIS PAPER.

ALL ANSWERS MUST BE WRITTEN IN INK. PENCILS MAY BE USED ONLY FOR DRAWING, SKETCHING OR GRAPHICAL WORK.

Question

/

Max Marks

/

Marks Obtained

1 / 20
2 / 20
3 / 30
4 / 30
TOTAL / 100

Number of Pages: 20 Pages including this page

Microprocessors and Embedded Systems COMP 3221/9221

1. Basics Concepts (10 × 2 = 20 marks)

PART 1 Describe the differences between microcontrollers and microprocessors.


PART 2 Describe the memory models of the ISA of AVR microcontrollers.

PART 3 Give examples of four different addressing modes in AVR.

Microprocessors and Embedded Systems COMP 3221/9221

PART 4 Discuss the advantages and disadvantages of using macros versus functions.

PART 5 Discuss the advantages and disadvantages of using interrupts versus polling.

PART 6 What is the switch bounce problem? Describe a software debouncing approach.


Microprocessors and Embedded Systems COMP 3221/9221

PART 7 In serial data transmission, what are the start bit and stop bit used for?

PART 8 Describe how a watchdog timer can be used to detect a software crash.

PART 9 Explain how the daisy chain bus arbitration scheme works.

Microprocessors and Embedded Systems COMP 3221/9221

PART 10 What AVR instruction can be used to reduce the power consumption of a AVR microcontroller? Why?

2. Miscellaneous Questions (20 marks)

PART 1 Consider a 64-bit microprocessor. Its Program Status Register has an oVerflow flag V that indicates if an overflow has occurred. If an overflow has occurred, the V flag is set to one; otherwise it is set to zero. The subtraction instruction has the following syntax:

sub Rd, Rr

It does the following operations: Subtract Rr from Rd and store the result in Rd, where both Rd and Rr are 64-bit general registers. As in any microprocessor, all numbers are stored in two’s complement.

Give a Boolean formula for computing the V flag for sub. (3 marks)

Microprocessors and Embedded Systems COMP 3221/9221

PART 2 A 16-bit A/D converter is to digitize a five-volt, full scale signal. What is the resolution? (2 marks)

PART 3 A 16-bit A/D converter is to digitize a five-volt, full-scale signal. What is the accuracy with which the A/D converter can digitize the following signals?

1 V, 2.5 V, 5 V (3 marks)

PART 4 Consider the following AVR assembly code.

.set x=pc

ldi r20, low(x)

ldi r21, high(x)

ldi r30, low(pc)

ldi r31, high(pc)

.set x=pc

ldi r20, low(pc)

ldi r21, high(pc)

Assume the address of the instruction “ldi r20, low(x)” is 0x0600. After the above sequence of code is executed, what are the hexadecimal values in r20, r21, r30, and r31, respectively? (3 marks)

Microprocessors and Embedded Systems COMP 3221/9221

For PART 5 and PART 6

Consider two single precision floating point numbers x and y in IEEE 754 format, where x=0xC0EF0000 and y=0xC1AB0000.

PART 5 What is the hexadecimal value of x+y in IEEE 754 format? (3 marks)

PART 6 What is the decimal value of x+y? (2 marks)

For PART 6 and PART 7

A C program consists of six functions. Their call relations are shown as follows (the arguments and irrelevant C statements are omitted).

Microprocessors and Embedded Systems COMP 3221/9221

int main(void)

{

func1(…);

func2(…);

func3(…);

}

int func1(…)

{

func1(…);

}

int func3(…)

{

func3(…);

}

int func2(…)

{

func4(…);

func5(…);

}

Microprocessors and Embedded Systems COMP 3221/9221

Both func1() and func3() are recursive functions. func1() calls itself 12 times for the actual parameters given in main(). func3() calls itself 10 times for the actual parameters given in main(). Neither func4() nor func5() calls any function. The sizes of all stack frames are shown as follows.

main(): 200 bytes.

func1(): 100 bytes.

func2(): 400 bytes.

func3(): 300 bytes

func4(): 600 bytes

func5(): 300 bytes

Assume that no interrupt occurs during the execution of this program.

PART 6 Draw the call tree of this program. (2 marks)

Microprocessors and Embedded Systems COMP 3221/9221

PART 7 How much stack space is needed to execute this program correctly in the worst case? (2 marks)

3. AVR Assembly Programming (10 ´ 3 = 30 marks)

All programs must be well commented.

PART 1 Write an AVR assembly program to compute the sum of all array elements in a one-dimensional integer array A. Your program must satisfy the following requirements.

1)  Array A has 10 elements and each element is a 2-byte signed integer.

2)  The initial value of A[i] (i=0, 1, …, 9) is stored in the flash memory. You may choose any integer value for each element.

3)  Array A is stored contiguously in the SRAM.

4)  Your program must define and use at lease one MACRO.

5)  The sum is stored in registers r26:r25.

Your program may ignore the overflow.

Microprocessors and Embedded Systems COMP 3221/9221

Microprocessors and Embedded Systems COMP 3221/9221

PART 2 Write an AVR assembly program to implement the following C program.

int sum (int n);

int main(void)

{

int n=30;

sum(n);

return 0;

}

int sum(int n)

{

if (n<=0) return 0;

else return (sum(n-1)+n*n);

}

All local variables and parameters must be stored in the stack space. You need to choose a proper size for n and describe the stack frame structures using a diagram.

Microprocessors and Embedded Systems COMP 3221/9221

Microprocessors and Embedded Systems COMP 3221/9221

PART 3 Consider an embedded system using an AVR Mega64 microcontroller. The embedded system needs a software clock to keep the number of days since it started to operate. The software clock is implemented by using Timer/Counter 0 Overflow Interrupt. Assume that

1)  Timer/Counter 0 Overflow Interrupt has been set to occur every 100 microseconds in the main program.

2)  All 32 general registers are used in the main program.

Write an interrupt service routine ISR0 for Timer/Counter 0 Overflow Interrupt to keep the number of days since the embedded system started to operate.

Note that your ISR0 should NOT affect any registers used the main program.

Microprocessors and Embedded Systems COMP 3221/9221

Microprocessors and Embedded Systems COMP 3221/9221

4.  Interrupts and I/O (30 marks)

For PARTs 1, 2, and 3:

Assume for a processor with a 500 MHz clock it takes 200 clock cycles for a polling operation (calling polling routine, accessing the device, and returning). The overhead for an interrupt operation is 300 clock cycles. Hard disk transfers data in 256-byte chunks and can transfer at 16 M bytes/second rate.

PART 1 If the processor uses software polling, what percentage of the processor time is tied up in polling the hard disk to achieve a data transfer rate of 16M bytes/second? (4 marks)

PART 2 If the processor uses interrupt technique and the interrupt rate is equal to the software polling rate, what percentage of the processor time is tied up in servicing interrupt by the hard disk during the data transfer? (4 marks)

PART 3 If the processor’s clock frequency increases to 1 GHz and the processor uses interrupt technique and the hard disk is only active 10% of the time, what percentage of the processor time is tied up in servicing the interrupt by the hard disk?

(4 marks)

Microprocessors and Embedded Systems COMP 3221/9221

For PARTs 4 and 5:

Consider an embedded system using an AVR mega64 microcontroller. There are 20 interrupting sources, Int0, Int1, …, Int19. Assume that the size of the stack space needed by each interrupt service routine is 50 bytes. If no interrupt occurs, the correct execution of the program needs 1K bytes of stack space in the worst case.

PART 4 If interrupts may occur at any time and each interrupt service routine does not enable the Global Interrupt Flag I in the Program Status Register, how much stack space is needed by the program in the worst case? (4 marks)

Microprocessors and Embedded Systems COMP 3221/9221

PART 5 Assume that an interrupting device generates a new interrupt request only if its last interrupt request has been processed i.e. its interrupt service routine has been finished. Assume that interrupts may occur at any time and ONLY the interrupt service routines of Int0, Int1, Int2 and Int3 enable the Global Interrupt Flag I in the Program Status Register at the beginning of their interrupt service routines, how much stack space is needed in the worst case? (4 marks)

.

For PART 6 and PART 7

Consider designing an electronic toy. It uses a 3*3 keypad to get the input from the user and requires that 26 capital letters be input via 9 keys. If a straightforward key scanning approach like the one in our Lab 4 is used, only 9 symbols can be input to the toy, which does not satisfy the requirement.

PART 6 Design an encoding scheme such that 26 capital letters can be represented via 9 keys and the user does not need to remember the encoding scheme when typing letters. (4 marks)

Microprocessors and Embedded Systems COMP 3221/9221

PART 7 Describe a key scanning procedure which implements your encoding scheme using a diagram or an algorithm. If using an algorithm to describe the key scanning procedure, you can use any computer language and English. (6 marks)

Microprocessors and Embedded Systems COMP 3221/9221

10