Вы находитесь на странице: 1из 11

MICROCOMPUTERS CMPE2003 Solutions

Department of Electrical and Computer Engineering Semester 2, 2016

NAME: STUDENT ID:

Answer all questions. Make sure you write your name and student ID number on both
the cover page and also above.
State your assumptions and show all relevant workings to answer ALL questions. Give
indication of correct answer if you provide answers which can be ambiguous. DO NOT use
red colour on your exam as it interferes with the marking process.

Question 1. (Total: 40 marks)


Difficulty: Easy Level

(a) What is General/Global Interrupt Enabler (GIE) on an MSP430 and provide an example
of two calls (in C or assembly) used in CCS to enable and disable GIE respectively?
(10 marks)

The GIE is a bit in the status register (SR) or register R2 within the register file, which
when set is able to enable maskable interrupt sources
can be activated/deactivated via some of the following calls
o SR |= BIT3; // Enable interrupts i.e. GIE = 1
o SR &= ~BIT3; // Disable interrupts i.e. GIE = 0
o __eint(); // Intrinsic function call i.e. GIE = 1
o __dint(); // Intrinsic function call i.e. GIE = 0
o __enable_interrupt(); // Intrinsic function call i.e. GIE = 1
o __disable_interrupt(); // Intrinsic function call i.e. GIE = 0
o __bis_SR_register(GIE); // Intrinsic function call i.e. GIE = 1
o __bic_SR_register(GIE); // Intrinsic function call i.e. GIE = 0
o EINT ; Assembly: Emulated instruction i.e. GIE = 1
o DINT ; Assembly: Emulated instruction i.e. GIE = 0
o BIS #8,SR ; Assembly: Enable interrupts i.e. GIE = 1
o BIC #8,SR ; Assembly: Disable interrupts i.e. GIE = 0
o BIS #8,R2 ; Assembly: Enable interrupts i.e. GIE = 1
o BIC #8,R2 ; Assembly: Disable interrupts i.e. GIE = 0
o Any other equivalent implementation

(b) Draw the flowchart for a main program that uses polling (busy wait) and a flowchart of a
periodic polling and provide explanation comparing the differences between the two. The
space provided is sufficient for your answer but there is additional space provided at the
end of the exam paper if required.
(30 marks)

Curtin University is a trademark of Curtin University of Technology.


CRICOS Provider Code 00301J (WA), 02637B (NSW)

Page 1 of 6
MICROCOMPUTERS CMPE2003 Solutions
Department of Electrical and Computer Engineering Semester 2, 2016

In the busy wait polling method on the left flowchart, the main program polls the I/O
devices continuously whereas
In periodic polling, a timer interrupt sets up I/O devices polling on a regular basis.
Periodic polling is used in applications where I/O hardware cannot generate interrupts
directly and to relegate I/O functions to the background process.

Curtin University is a trademark of Curtin University of Technology.


CRICOS Provider Code 00301J (WA), 02637B (NSW)

Page 2 of 6
MICROCOMPUTERS CMPE2003 Solutions
Department of Electrical and Computer Engineering Semester 2, 2016

We can also have the following acceptable flowchart diagrams as covered in the tutorials.

Curtin University is a trademark of Curtin University of Technology.


CRICOS Provider Code 00301J (WA), 02637B (NSW)

Page 3 of 6
MICROCOMPUTERS CMPE2003 Solutions
Department of Electrical and Computer Engineering Semester 2, 2016

Question 2. (Total: 60 marks)


Difficulty: Intermediate Level

(a) An empty loop takes 2 s to execute on an MCU consuming 20 clock cycles. Some user
code is added into the empty loop whereby the total loop execution time consumes 140
clock cycles. Two XOR lines of code from the added user code are placed at the start and
end of the code within the loop to perform an MCU pin toggling for oscilloscope
measurement measuring 11.5 s. Estimate the effective-execution-time (excluding the two
XOR lines) in s for the added code into the for loop, if an XOR line of code takes x
clock cycles to execute?
(20 marks)

Determine the time per clock cycle


2 s s
0.1 .
20 cycles cycle
Added code takes
140 20 x 120 x cycles including one XOR line of code operation.
Determine a line of XOR code execution
11.5 s s
0.1
120 - x cycles cycle
x 5 cycles.
Added code effective-execution-time takes
140 20 2 x 140 20 2 5 110 cycles
s
110 cycles 0.1 11 s.
cycle

(b) What are the contents of register R5 after executing the last line of assembly code shown
below? Complete Table 2 provided for the destination contents by making use of Table 1.
(25 marks i.e 5 marks per correct entry)
mov.w #0xC2F0,R4 ; A memory location with write access to memory
; block starting at 0xC200 for MSP-EXP430FR5739
mov.w #0x1155,0(R4)
mov.w #0xFFEE,R5
bic.b &0xC2F0,R5
bis.b #0x1144,R5

Curtin University is a trademark of Curtin University of Technology.


CRICOS Provider Code 00301J (WA), 02637B (NSW)

Page 4 of 6
MICROCOMPUTERS CMPE2003 Solutions
Department of Electrical and Computer Engineering Semester 2, 2016

Use the information below as guide for the assembly code given above.

Instruction Operation
bic src, dst (src)' & dst dst

bis src, dst src | dst dst

mov src, dst src dst

Addressing Mode Syntax Description

# Immediate data

& Absolute address

Rn Register contents are operand

X(Rn) (Rn+X) points to the operand

Table 1 Description of Instruction and Addressing Mode Syntax


mov.w #0xC2F0,R4 ; A memory location with write access to memory
; block starting 0xC200 for MSP-EXP430FR5739
mov.w #0x1155,0(R4) ; Store 0x1155 -> M(0xC2F0)
mov.w #0xFFEE,R5 ; Store 0xFFEE -> R5
bic.b &0xC2F0,R5 ; (M(0xC2F0))' & R5 -> R5 (.b upper byte is zero)
bis.b #0x1144,R5 ; 0x1144 | R5 -> R5 (.b upper byte is zero)

Instruction Destination Result in Hexadecimal

mov.w #0xC2F0,R4 R4 0xC2F0

mov.w #0x1155,0(R4) 0(R4) Memory 0x1155

mov.w #0xFFEE,R5 R5 0xFFEE

bic.b &0xC2F0,R5 R5 0x00AA

bis.b #0x1144,R5 R5 0x00EE

Table 2 Complete Result in Hexadecimal column

Curtin University is a trademark of Curtin University of Technology.


CRICOS Provider Code 00301J (WA), 02637B (NSW)

Page 5 of 6
MICROCOMPUTERS CMPE2003 Solutions
Department of Electrical and Computer Engineering Semester 2, 2016

(c) Before an interrupt occurs in an MSP430, the content of Program Counter (PC) is 0x8000
and Stack Pointer (SP) is 0xC400. Complete Figure 1 below when an interrupt occurs (the
Interrupt Service Routine points to 0xFFFA).
(15 marks i.e 5 marks per correct entry)

PC Memory SP
FFFA 8000 C3FE

Figure 1 Fill in the blanks


The SP address defaulted to decrement by 2 bytes for byte/word push. When an interrupt is
initiated, items are pushed onto the stack i.e. decremented because of last in first out (LIFO)
scheme used by MSP430. Figure 1 indicates the return address 0x8000 in Memory (stack)
already so SP holds the decremented Memory address 0xC3FE.

Curtin University is a trademark of Curtin University of Technology.


CRICOS Provider Code 00301J (WA), 02637B (NSW)

Page 6 of 6
The program counter holds the address of the next
instruction to be executed.sp-points to the last stack location used.
Driver: void LEDsInit(void)
enum bool LEDsPut(value)
void switchesInit(void)
enum bool switchesPut(uc_8 &value)

basic tecnic: simulation, toggling, inserting a programme.

The timer overflow flag is set when the 16bit timer counter
overflows. If the system clock is 25MHz and
a three bit prescaler is implemented as a binary
!17
power division operation. If the prescaler is %011
what is the time from one overflow to the next?
answer:
We divide the system clock by 8 so it is 3.125MHz or
0.32microsecs.
For a 16bit counter the count is 65536 for overflow
so the answer is
65536 * 0.32 microsecs = 20971.52 microsecs or
20.97152 millisecs.

When an ISR is finishing and another is pending


what happens to the context saved on the stack?
Que 2 answer:
For the S12 if another interrupt is pending then the
contents of the stack are left unchanged and the
starting address of the new interrupt loaded into the

The terms endian and endianness refer to the convention used to


interpret the bytes making up a data word when those bytes are stored
in computer memory.
Stubs are functional skeletons used to allow compilation of a system
and execution but providing minimal if any actual functionality.

1. A for loop in C has two parts to its execution. There is an overhead


representing the time taken to setup and terminate the loop operations and there
is a per loop time component.

Consider an empty for loop that executes once and its total execution is 5 clock
cycles. Now consider some portion code added into the empty loop. In an
execution setup, the non-empty loop executes 10 times consuming 205 clock
cycles. What is the time in clock cycles for the execution of the added code
portion only? State any assumptions made.

From the execution setup, where x is the overhead and y is the per non-empty
loop, 10 y + x = 205.

Assume the overhead for empty loop is the same as that for the non-empty loop
that is x = 5,
y=
2. (b) Toggling a pin and observing the external effect on an oscilloscope is quite an
effective timing method. The operation of toggling takes 7 microseconds and it is
done both before and after the code execution to be timed. The oscilloscope
measures an execution time of 95 microseconds from the start to end toggles.
How long (effective time in microseconds) does the actual code take to execute
and why?

Although the operation to toggle the pin occurs at the beginning and end of the
execution the effective extra time in the measurement corresponds to one toggle
time. So the actual code time is 95 - 7 = 88 microseconds.

4. A timer subsystem uses a 16-bit timer counter. An input capture is used to obtain
two successive rising edges of a waveform and the timer counter unsigned integer
variable values captured are:

first = 0xC002; second = 0x3362;


What is the period of the waveform in timer counter clock cycles?

What single line of C code using these variables would correctly obtain the period
value and why?

Second minus first is 0x3362 - 0xC002 = 0x7360 (or decimal 29536) C code:
period = second - first;

The important thing here is that effectively we have modular arithmetic so the
overflow does not matter provided the result is within one complete period of the
16-bit timer counter.

5. (e) What is the use of the volatile reserved word in C? In particular why is it
important in embedded systems?

Volatile tells the compiler that the variable can be changed outside of the normal
execution sequence (e.g. by an interrupt or an external input) so whenever it is
needed during execution it must be read from the source variable.

A finite state machine represents the relationship between input signals, internal
operations and derived output signals. It is often represented in C by a combination of
switch statements. Many embedded systems are reactive to the environment and return
outputs to affect the environment and so can easily be defined in terms of state
machines. Software tools exist to convert state diagrams directly to code without human
intervention.

A header file is a file with extension .h which contains C function declarations and macro
definitions to be shared between several source files. There are two types of header
files: the files that the programmer writes and the files that comes with your compiler.

Вам также может понравиться