You are on page 1of 27

CONFIDENTIAL

UNIVERSITI TEKNOLOGI MALAYSIA


SEMESTER I EXAMINATION
SESSION 2012/2013

SUBJECT CODE

SEE 3223

SUBJECT

MICROPROCESSORS

LECTURERS

EN. KAMAL KHALIL

EN ZULFAKAR ASPAR

DR. IZZELDIN IBRAHIM ABDELAZIZ

DR. YEONG CHE FAI

DR. AHMAD `ATHIF BIN MOHD FAUDZI

ZURAIMI BIN YAHYA

COURSES

SEE, SEL, SEW, SET, SWB and SKEM

SECTIONS

01, 02, 03, 04, 05 and 06

TIME

2 HOURS 30 MINUTES

DATE

___________________________________________________________________________
INSTRUCTIONS:

ANSWER TWO (2) QUESTIONS ONLY FROM PART A AND


TWO (2) QUESTIONS ONLY FROM PART B

___________________________________________________________________________
THIS PAPER CONSISTS OF 27 PAGES ONLY INCLUDING FRONT PAGE

SEE 3223
2

PART A:

ANSWER TWO QUESTIONS ONLY FROM THIS PART

QUESTION 1
1.

Write three differentiating features between a general purpose computing system and
an embedded system based on the following properties.
(6 marks)
Properties

General Computing System

Embedded System

Application
Size
Cost

2.

Sketch a block diagram with complete labeling of the basic structure of a computer
system.
(4 marks)

3.

How many general purpose registers does the AVR processor have?

(1 marks)

4.

What is the difference between the AND and the TST instruction?

(1 marks)

5.

What triggers a Timer/Counter 1 Overflow Interrupt?

(1 marks)

6.

When an interrupt is triggered, what register is placed on the stack?

(2 marks)

7.

What bit(s) within SREG are never modified by a CP or TST instruction?


(2 marks)

8.

Why is the Random Access Memory (RAM) called volatile memory?

9.

If an address bus for a given computer has 16 lines, what is the maximum amount of
memory it can access?
(1 marks)

10.

What is the difference between a subroutine and an interrupt, based on the following
properties?
(6 marks)
Properties
Method of
occurrance/invokes
Data that are saved
to stack
Terminating
Instruction

Subroutine

(1 mark)

Interrupt

SEE 3223
3

QUESTION 2

1.

Explain the differences between C and V flag. Give the situation when each of these
flags may be used.
(4 marks)

2.

Find the contents of R22 after each of the following is executed sequentially
a)

LDI
SWAP
CLC
ROR
ROR

R22, 0x56
R22
R22
R22
(4 marks)

b)

CLC
LDI
SWAP
ROL
ASR

R22, 0x4D
R22
R22
R22
(4 marks)

3.

What is the final value of R16 after execution of the following instructions? The
instructions are executed sequentially.
Instruction
LDI

R16

R16, 52

ANDI R16, $F0


LSR

R16

COM

R16

NEG

R16
(5 marks)

4.

Write a program in Assembly language that will interchange the nibble shown below.
Use only instruction involving indirect with post increment addressing mode.
(8 marks)
Address
$200
$201
$202
$203
$204
$205
$206

4
6
8
A
B
C
D

5
7
9
1
2
3
4

Address
$200
$201
$202
$203
$204
$205
$206

5
7
9
1
2
3
4

4
6
8
A
B
C
D

SEE 3223
4

QUESTION 3
a) There are two types of method to wait for an external event (I/O request) by a
microcontroller: by polling or by interrupt request.
Situation
a. Assuming the possibility that more than one event can
happen at the same time, name the method you will use if
you want to set a priority such the highest will be serviced,
and the rest will be ignored.
b. Name the method which requires the controller uses CPU
time while waiting for an event.
c. Name the method which requires address of the routine
service the event to be initialized in the systems vector table.
d. Name the method which has the possibility to fail to detect
an event because the period of the event pulse is too short to
be recognised.

Suitable Method

(4 marks)
b) Name the label of 2 external interrupts on the pinout of the ATMega32 chip and their
respective vector Address defined on the vector.
(4 marks)
c) Name 2 internal interrupts available on the ATMega32 microcontroller.
d) Based on the assembly code below, answer the following questions.
.INCLUDE "M32DEF.INC"
.ORG 0
JMP
MAIN
.ORG 0x02
JMP
EX0ISR
MAIN: LDI
R20,HIGH(RAMEND)
OUT
SPH,R20
LDI
R20,LOW(RAMEND)
OUT
SPL,R20
SBI
DDRC,3
SBI
PORTD,2
LDI
R20,$40
OUT
GICR,R20
SEI
LDI
R30, 3
LDI
R31, 4
ADD
R30, R31
HERE:
JMP
HERE
EX0ISR:
IN R21,PORTC
LDI
R22,0x08
EOR
R21,R22
OUT
PORTC,R21
RETI

(2 marks)

SEE 3223
5

i.

State the assembly codes which declare the content of interrupt vector address
for INT0?
(2 marks)

ii.

State the assembly codes in the program which will initialised the
ATMEGA32 External Interrupt Request 0, when pin INT0 is logic 0?
(3 Marks)

iii.

What is the purpose of the instruction RETI and how is it different from RET?
(4 marks)

iv.

Modify the code above to INT1 interrupt is triggered on a falling edge at the
INT1 pin and include an interrupt service routine for INT1 interrupt which
must be labelled as EX1. The interrupt service routine will just complement
the data at port B. Show where the relevant code is added in the program.
(6 marks)

SEE 3223
6

PART B:

ANSWER TWO QUESTIONS ONLY FROM THIS PART

QUESTION 4
There is an embedded system using microcontroller AVR ATmega32 shown in Figure Q4 (a).
The program shown in Figure Q4 (b) will cause LED0 to blink from a square wave pulse of
20s period using Timer Normal mode. (Assume XTAL pin frequency (System Clock) is 4 MHz)

Figure Q4 (a)

.INCLUDE "M32DEF.INC"
LDI
R16,0x08
SBI
DDRB,3
LDI
R17,0
OUT PORTB,R17
BEGIN: LDI
R20, $38
OUT TCNT0,R20
Section 1
LDI
R20,0x01
OUT TCCR0,R20
AGAIN: IN
R20,TIFR
Section 2
SBRS R20,TOV0
RJMP AGAIN
LDI
R20,0x0
OUT TCCR0,R20
Section 3
LDI
R20,0x01
OUT TIFR,R20
EOR
R17,R16 Figure Q4(b)
OUT PORTB,R17
RJMP BEGIN

Figure Q4 (b)

SEE 3223
7

a)

b)

Referring on the codes for Section 1, Section 2 and Section 3 indicated in the program,
identify which section:
(a) Stop the timer and reset the TOV0 flag
(b) Load the starting count of timer 0 and set timer operation mode.
(c) Implement a delay of 50s in order to get the LED blink at a period of every
100s.
(3 marks)
Identify the instruction(s) used in the program that determines Timer 0 is set to Normal
mode operation and running at 4 MHz frequency.
(2 marks)

c)

In the program which registers is initialized such that TOV0 flag in TIMER0 will be set
after a 50s delay and give starting count that will determine the delay.
(2 marks)

d)

What will be the count in TIMER0 when TOV0 flag is set?

(2 marks)

e)

Which set of instructions in the program clear the TOV0 flag?

(2 marks)

f)

Show the calculation that generates the 50s delay.

(5 marks)

g)

The embedded system is added with extra LEDs to the total of 4 LEDs connecting to
PORTB.0 to PORTB.3.
i.

Sketch the circuit.

(3 marks)

ii.

Write a full program to blink the 4 LEDs in the sequence as shown in Table 4,
using Timer Normal mode. (Note: use the program in Figure Q4 (b) as reference).
(6 marks)
Table 4
PORTB.3
OFF
ON

PORTB.2
ON
OFF

PORTB.1
OFF
ON

PORTB.0
ON
OFF

SEE 3223
8

QUESTION 5
A simple robot arm is shown in Figure Q5(a). The Robot Arm has three moving parts which
are the Horizontal Shaft, Vertical Shaft and Gripper. These Horizontal Shaft, Vertical Shaft
and Gripper are controlled by motors drivers as shown in Table Q5(a). Each of these motor
drivers will determine the direction of movement of the respective Horizontal Shaft, Vertical
Shaft and Gripper as specified in Table Q5(a) which will determine the 2-dimension (vertical
and horizontal) position where the Gripper position is. Only one of the two shafts will be
moved at one time. The Gripper can be positioned at four different edge (BACK, PICK,
FRONT AND PLACE) as shown in Figure Q5(a) and described in Table Q5(b). Sensors X1,
X2, X3 and X4 in shown Figure Q5(a) and described in Table Q5(b) will signal if the Gripper
has reached the respective specified positions which are relative to the position of Horizontal
Shaft and Vertical Shaft.
Table Q5(c) defines the configurations of ATmega32 Input/Output port with respect to the
sensors and drivers. The inputs to ATmega32 port monitor the status of the respective sensor
which determines the position of the Gripper. The output from ATmega32 port controls the
respective drivers for motors which determine the direction of movement of the Horizontal
Shaft, Vertical Shaft or Gripper. All sensors and drivers are seen as digital devices by the
ATmega32 microcontroller.
Y3
Y4

X2

X1

X3

Y1
Y2

X4

Horizontal Arm
Vertical Arm
BACK

FRONT

Y5

PLACE

PICK

Platter

Platter

Figure Q5(a): The Pick and Place Robot Arm


To activate a motor driver, a logic 1 is output to respective bit specified in Table Q5(c).
Only one motor drivers can be activated at one time. An ON Status of the sensor stated in
Table Q5(b), is a logic 1 input to the respective bits specified in Table Q5(c).
The will be three type of process (PickProcess, PlaceProcess, HomeProcess) which is
described in Table Q5(d) that shows the motion of the Horizontal Shaft, Vertical Shaft or
Gripper in order to implement the respective process.

SEE 3223
9

Table Q5(a)
Moving Part
Name
Horizontal
Shaft
Vertical Shaft
Gripper

Direction
of
Movement
Forward
Back
Up
Down
Grip
Release

Arrow # shown in
Figure Q5(a)
4
8
1
3
2
6

Motor Driver Setting


to control of direction
of movement
Y1 activated
Y2 activated
Y3 activated
Y4 activated
Y5 activated
Y5 deactivated

Table Q5(b): Grippers Position (refer to Figure Q5 (a)


Positions
Name

Possible Direction of
Motion to reach the
respective position

Location of shaft

Sensor status (which


identify the
respective position)

BACK

Horizontal Shaft moved


backward from front-edge
or Vertical Shaft moved
upward from bottom-edge

Vertical Shaft at
top-edge and
Horizontal Shaft at
back-edge

Back-edge sensor X1
is ON, Top-edge
sensor X3 is ON

PICK

Vertical Shaft moved


downwards from top-edge
and Horizontal Shaft static
at back-edge position

Vertical Shaft at
bottom-edge and
Horizontal Shaft at
back-edge

Back-edge sensor X1
is ON, Bottom-edge
sensor X4 is ON

FRONT

Horizontal Shaft moved


forward from back-edge
position or Vertical Shaft
moved upward from
bottom-edge position

Vertical Shaft at
top-edge and
Horizontal Shaft at
front-edge

Front-edge sensor X2
is ON, Top-edge
sensor X3 is ON

PLACE

Vertical Shaft moved


downward from top-edge
position

Vertical Shaft at
bottom-edge and
Horizontal Shaft at
front-edge

Front-edge sensor X2
is ON, Bottom-edge
sensor X4 is ON

Table Q5(c): The input-output table of the Atmega32


No.
1
2
3
4
5

Sensor
X1
X2
X3
X4
X5

Detection
Back-edge
Front-edge
Top-edge
Bottom-edge
Gripper grip

Input to
Port A Pin 1
Port A Pin 2
Port A Pin 3
Port A Pin 4
Port A Pin 5

No.
1
2
3
4
5

Driver
Y1
Y2
Y3
Y4
Y5

Output from
Port B.1
Port B.2
Port B.3
Port B.4
Port B.5

SEE 3223
10

Table Q5(d): Motion of Shaft/Gripper according to Process Name


Process Name
PickProcess

PlaceProcess

HomeProcess

Motion of Shaft/Gripper (refer Table Q5(b) and Q5(c))


i.

Assuming at Horizontal Shaft is at BACK position, then

ii.

Vertical Shaft will move to PICK position and

iii.

At PICK position Gripper grips workpiece.

i.

Assuming Gripper is at PICK position and is gripping


workpiece, then

ii.

Vertical Shaft will move to BACK postion,

iii.

At BACK position Horizontal Shaft will move to FRONT


position

iv.

At FRONT position Vertical Shaft will move to PLACE


position

v.

At PLACE position Gripper release workpiece.

i.

Gripper release object, then

ii.

Vertical Shaft move to FRONT position, and

iii.

finally Horizontal Shaft move to BACK position.

Based on the specifications and descriptions given above:


a)

Draw the flow chart for the Pick process subroutine. (You may refer to Flowchart
Q5(b) which implements the Place process, as a guide)
(6 marks)

SEE 3223
11

b)

Based on the following flowchart, write the subroutine of the ATmega32 assembly
program that performs the Place process given Table Q5(d).
Place

Initialize Port A and Port B accordingly

Y3=ON (up direction activated)


At bottom-edge
No
X3=OFF
?

At top-edge

Yes

Y3=OFF (up direction deactivated)


Y1 = ON (Forward direction activated)
No
X1=OFF?

At front-edge

Yes

Y4 = ON (Downward direction activated)


No
X4=OFF
?

At bottom-edge

Yes

Y4=OFF (Downward direction deactivated)


Y5=OFF (Release Object)

Return

Flowchart Q5(b)
(8 marks)
c)

Assuming an emergency button is connected to Port B pin 2 (refer Figure Q6(a)),


write a program that performs the Home process which will be an interrupt routine
whenever the emergency input is activated. The Home process will cause the
Robot Arm to release object, move gripper to top-edge and and then to the back-edge
position. Show the initialisation of the interrupt vector table in the program.
(11 marks)

SEE 3223
12

QUESTION 6
Given the following components:
i.
ii.
iii.
iv.
v.
vi.
vii.
viii.
ix.
x.
xi.
xii.

1 unit of an ATmega32 microcontroller whose labelling is given in Figure Q6 (a).


1 units of a common anode 7-segment display whose labelling is given in Figure
Q6 (b).
5 units 100nF capacitor
3 units 10H inductor
10 units of 330 resistors.
8 units of 10k resistors.
1 units of 10k potentiometer.
1 units of 100 potentiometer.
Jumper wires
1 unit toggle switch
1 unit push button switch
1 unit toggle switch

Specifications:
i.
ii.
iii.
iv.
v.
vi.
vii.

The Vcc voltage is 5 Volts.


Use Single ended analog input.
Prescale the ADC clock speed to the lowest frequency possible.
The ADC Data Register will be right adjusted.
The Seven Segment Display code is given in Figure Q6(c).
The ADC conversion value is given in Figure Q6 (d).
The ADC clock frequency is to be set at 125 kHz. The Calibrated RC Oscillator
is1 MHz.

SEE 3223
13

a) Using any of the component available given above (not necessarily all), design a
ATmega32 system by drawing the complete wiring diagram an ATmega32 system with
the 7-segment connected to port B of the ATmega32, which will read an analog from
0.00V to a full scale voltage of 5.00 Volts from the ADC1 of the ATmega32. (You may
use labels to show/replace wiring connections). Use a suitable potentiometer to generate
the voltage range of 0 Volt to 5 Volts. Diagram should include:
i)

the circuit for RESET.

(2 marks)

ii)

the circuit that implement the full scale voltage of 5.00 Volts.

(3 marks)

iii)

the circuit for the Seven Segment display.

(3 marks)

iv)

the potentiometer circuit generate the voltage range of 0 Volt to 5 Volts.


(2 marks)

b) Write the complete program which will display at the seven segment display according to
table Q6. Use polling method to read the ADC.
Table Q6
Analog voltage
0-0.99
1-1.99
2.2.99
3-3.99
4-4.99
5

Seven Segment Display


0
1
2
3
4
5

In the program, show:


i)

the code that initialised the stack.

(2 marks)

ii)

the code that initialised the port for Seven Segment Display output. (2 marks)

iii)

the code that initialised the port for ADC input.

(2 marks)

iv)

the code that read the analog voltage by polling method.

(4 marks)

v)

the code that give the display on the seven segment display according to table
Q6.
(5marks)

SEE 3223
14

Figure Q6 (a)

Fiqure Q6 (b)

Seven
segment
code
(gfedcba)
03F

0.00

006

204.60

CD

05B

409.20

199

04F

613.80

266

066

818.40

332

06D

1023.00

3FF

Digit

Figure Q6 (c)

Voltage
(Volts)

Decimal Value of
a 10-bit
conversion

Approximate
Hex Value
0

Figure Q7 (c)

SEE 3223
15

APPENDIX
Reset & Interrupt Vector Table

SEE 3223
16

SEE 3223
17

SEE 3223
18
AVR Assembler Directive

Segment

Header

Code

EEPROM

Directive
.DEVICE

Defines the type of the target processor and the applicable set of instructions (illegal instructions for
that type trigger an error message, syntax: .DEVICE AT90S8515)

.DEF

Defines a synonym for a register (e.g. .DEF MyReg = R16)

.EQU

Defines a symbol and sets its value (later changes of this value remain possible, syntax: .EQU test =
1234567, internal storage of the value is 4-byte- Integer)

.SET

Fixes the value of a symbole (later redefinition is not possible)

.INCLUDE

Includes a file and assembles its content, just like its content would be part of the calling file (typical
e.g. including the header file: .INCLUDE "C:\avrtools\appnotes\8515def.inc")

.CSEG

Start of the code segment (all that follows is assembled to the code segment and will go to the
program space)

.DB

Inserts one or more constant bytes in the code segment (could be numbers from 0..255, an ASCIIcharacter like 'c', a string like 'abcde' or a combination like 1,2,3,'abc'. The number of inserted bytes
must be even, otherwise an additional zero byte will be inserted by the assembler.)

.DW

Insert a binary word in the code segment (e.g. produces a table within the code)

.LISTMAC

Macros will be listed in the .LST-file. (Default is that macros are not listed)

.MACRO

Beginning of a macro (no code will be produced, call of the macro later produces code, syntax:
.MACRO macroname parameters, calling by: macroname parameters)

.ENDMACRO

End of the macro

.ESEG

Assemble to the EEPROM-segment (the code produced will go to the EEPROM section, the code
produces an .EEP-file)

.DB

Inserts one or more constant bytes in the EEPROM segment (could be numbers from 0..255, an
ASCII-character like 'c', a string like 'abcde' or a combination like 1,2,3,'abc'.)

.DW

Inserts a binary word to the EEPROM segment (the lower byte goes to the next adress, the higher
byte follows on the incremented address)

.DSEG

Assemble to the data segment (here only BYTE directives and labels are valid, during assembly only
the labels are used)

.BYTE

Reserves one or more bytes space in the data segment (only used to produce correct labels, does not
insert any values!)

.ORG

Defines the address within the respective segment, where the assembler assembles to (e.g. .ORG
0x0000)

.LIST

Switches the listing to the .LST-file on (the assembled code will be listet in a readable text file .LST)

.NOLIST

Switches the output to the .LST-file off, suppresses listing.

.INCLUDE

Inserts the content of another source code file, as if its content would be part of the source file
(typical e.g. including the header file: .INCLUDE "C:\avrtools\appnotes\8515def.inc")

.EXIT

End of the assembler-source code (stops the assembling process)

SRAM

Everywhere

Description

SEE 3223
19

SEE 3223
20

SEE 3223
21

SEE 3223
22

SEE 3223
23

SEE 3223
24

AVR Timers: TIMER0


TCCR0

SEE 3223
25

SEE 3223
26

SEE 3223
27

Sample Program running on a 1 Mhz clock frequency ATmega32, that read continuously a single ended input
from ADC0, which is set with an ADC frequency of 7.8125k Hz and with a full scale voltage of 2.56 volt.

You might also like