You are on page 1of 15

UNIVERSITY OF KWAZULU-NATAL

School of Engineering
MAIN EXAMINATIONS: MAY 2019
SUBJECT COURSE and CODE: Digital Systems: ENEL3DSH1

PAPER: 1

DURATION: Three hours TOTAL MARKS: 100

Internal Examiners: Mr B. Naidoo, Dr T. Walingo


External Examiner: Prof L Cheng

Instructions:

Answer in ink, diagrams may be drawn in pencil. This question paper contains a total of 15 pages

There are three sections:


Section A (20%) Answer on MCQ sheet – Indicate student number and seat number
Section B (40%) Answer in a separate book that is clearly marked “Section B” on the cover
Section C (40%) Answer in a separate book that is clearly marked “Section C” on the cover

Please provide clear and concise answers.


The correct and effective use of comments is encouraged.
Please plan your solution and write legibly. A neat answer indicates clear thinking.
Note: ATmega32 datasheet excerpt appended to this paper.

SECTION A – GENERAL MULTIPLE CHOICE

There are 20 MCQ questions based on the AVR family of microcontrollers. Please answer all these questions.
Each question is worth 1 mark and there is no negative marking. Please follow instructions on the MCQ answer
sheet.

1. Which one of the following instructions is normally used without the need to first setup the stack
pointer?
a) SEI b) PUSH c) POP d) RCALL e) LDD

2. The LPM instruction requires prior initialization of the following pointer


a) SP b) X c) Y d) Z e) k

3. Indicate which pointer can be used to access CSEG in the ATMEGA32?


a) SP b) X c) Y d) Z e) all of these

4. Which memory segment contains flash memory technology?


a) CSEG b) DSEG c) ESEG d) FSEG e) none of these

5. Which flag is set by the following instruction: CLR r16


a) N b) C c) Z d) V e) none are set

6. Which of the following branches will modify SP


a) RET b) RJMP c) JMP d) BRNE e) none of these

7. What is the 5-bit 2’s comp representation of -17?


a) 01111 b) the number does not exist c) 1110 1111
d) 10001 e) 1111 0001
Examinations: May 2019 Digital Systems: ENEL3DSH1 - Solution Page 2 of 15

8. Which instruction takes more than 1 clock cycle to execute?


a) LDI b) LSL c) LDS d) NOP e) OUT

9. Which of the following data movement instructions does not exist?


a) SD b) ST c) STD d) SPM e) All exist

10. Which one of the following may not be used as an argument in an assembler expression?
a) SP b) immediate values c) labels d) defined constants e)
addresses

11. Which one of the following is true about ATmega32 microcontroller pins?
a) All pins have alternate functions. b) All pins are PORT pins.
c) Pin 12 and 13 are for timers. d) You can generate a square wave on pin 28 and
29.

12. Which one will not make an ATmega32 microcontroller to reset?


b) Brown out. b) Power on.
c) Logic one on pin 9. d) Watchdog time expiry.

13. What is the rollover value of Timer1 operating in normal mode


c) The value loaded in the OCR1A b) The value loaded in OCR1B c) 0xFF
d)0xFFFF

14. When is the OCF1A flag raised?


d) Timer0 in CTC mode and the value of TCNT0 = OCR0 b) Timer1 in normal mode and the
value of TCNT1A = OCR1A c) Timer1 in CTC mode and the value of TCNT1 = OCR1A
d) Timer1 in CTC mode and the value of TCNT1A = OCR1A

15. Which one is not true about Timer0 and Timer1


e) They share TCCR0 b) They both have their own timer overflow
flags
c) They both can be used as event counters d) They both have their own timer compare
match flags
16. Which interrupt has the highest priority?
(a) SPI STC (b) INT2 (c) TIMER0 OVF (d) INT0

17. Which one is not a software interrupt


(a) USART TXC (b) INT1 (c) TIMER0 OVF (d) TIMER1 COMPB

18. Which one of the following registers is not used in serial communications for ATmega32?
(a) UDR (b) TCCR0 (c) UBRR (d) UCSRC

19. Assuming we are transmitting the ASCII letter “E” (01000101) with no parity and one stop bit. The
overhead due to framing is
(a) 37.5% (b) 25% (c) 10% (d) 20%

20. Which one is not true about the MAX232 chip


(a) chip used in serial communication (b) converts RS232 voltages to TTL levels (c) has
two sets of line drivers for transferring and receiving data (d) none of the above

2
Examinations: May 2019 Digital Systems: ENEL3DSH1 - Solution Page 3 of 15

Section B – AVR core and assembly

Please answer this section in a separate book that is titled “Section B” on the front cover.
All questions in this section are compulsory. This section is worth 40 marks.

QUESTION B1: Long Question [20]

Write an Assembly program for the ATMega32 that does the following:
1. Display a binary down-count on 8 LEDs connected to Port C
2. When the count overflows restart from zero; continue forever.

The following restrictions apply…


1. The LEDs are connected in an active high configuration
2. Use Timer 1 to implement a visualisation delay as follows...
a. Timer 1 mode: Normal
b. Timer 1 clock source: Prescaled system clock (slowest speed)
c. Use polling of the Timer 1 Overflow Flag to implement the delay
d. This delay routine must be a callable subprogram
e. The sub program is called when needed from the main loop
3. Explicitly Set or Clear bits in the appropriate I/O registers. Assume that all bit values are initially
wrong.
4. Structure your program very clearly and logically into blocks of code.
5. Comment every code block – indicating the purpose of the code

Mark breakdown:
MCU setup section [10]
Main loop [4]
Delay subroutine [6]

QUESTION B2: Short Questions [20]

B2.1) Read the code listing below and answer the questions that follow. The code contains four lines of
code that contain syntax errors. The intended logic of the code is very simple... Continuously do the
following: Read a byte from Port C, multiply by 2, write the result to Port D

Setup:
ldi r16,$00
out DDRD,r16
ldi r16,$FF
out DDRC,r16
start:
in PORTC,r16
lsr r16,1
out PORTD,r16
rjmp start

Write out the above incorrect code (without fixing the code) and add in-line comments. The comments
should explain what is wrong with that line of code (if there is an error). [4]

B2.2) What is the HEX opcode for the rcall instruction in the main loop of Question B2.1? An extract from
the rcall instruction set manual is provided below. Show working and explain the logical steps clearly. [5]

3
Examinations: May 2019 Digital Systems: ENEL3DSH1 - Solution Page 4 of 15

B2.3) Write a macro that stores a byte of immediate data to an I/O register. The macro is called LDIO and it
takes two parameters namely,
• Parameter 1: one byte of immediate data, and
• Parameter 2: the destination I/O register

Usage example: LDIO $1A,PORTB

NOTE: The macro must leave the processor in its original state. You may assume that SP has already been
setup. So the macro can use the stack without setting up SP. [8]

B2.4) What is the purpose of a watchdog timer (2 marks)? Name a typical product or application where the
WDT is used (1 mark). Please be brief. [3]

SECTION C – AVR PERIPHERAL SYSTEMS


Please answer this section in a separate book that is titled “Section C” on the front cover. This section is
worth 40 marks. If a value for a particular parameter, e.g. prescaler, is not given, choose yours and indicate
it. In all cases show your working.

QUESTION C1
[20]

For a clock frequency of 8 MHz, you are required to write a program to simultaneously sound a buzzer and
drive a motor continuously. The buzzer, connected to PORTB.1, should be driven by a 1 KHz square wave
generated by TMR1 overflow interrupt. The motor, connected to OCO pin, should be driven by a 2 KHz square
wave generated by TMR0 in the CTC mode toggling the OCO pin. Use a prescaler setting of 64 for TMR0 and
no prescaler for Timer 1.

a) For driving the motor with TMR0 in CTC mode and toggling the OCO pin.
[10]

i.) Determine the time it will take to toggle the OCO pin. [2]

ii.) Determine the value to be loaded in the OCR0 and write assembler instructions to configure the
register. [4]

iii.) Determine the value to be loaded in the TCCR0 and write assembler instructions to configure the
register. [4]

b) For driving the buzzer with TMR1 overflow interrupt.


[10]

i.) Determine the time it takes for the interrupt to occur. [1]

ii.) Determine the value to be loaded in the TCNT1H and TCNT1L. [3]

iii.) Determine the value to be loaded in the TCCR1A and TCCR1B. [4]

iv.) Determine the value to be loaded in the TIMSK. [2]

4
Examinations: May 2019 Digital Systems: ENEL3DSH1 - Solution Page 5 of 15

QUESTION C2
[20]

The hardware design for a car parking systems for the south entrance to the University of KwaZulu-Natal
Howard College campus is shown in Figure C2. The system should indicate to the controller at the gate the
number of cars in the parking. Note that detailed interfaces have not been shown. The description of the
hardware and entire system is as follows:
▪ The design uses an ATMega32.
▪ The maximum number of cars in the parking is less than one hundred.
▪ The system is equipped with two car sensors that output a logic LOW when a car passes the gate on
either side.
▪ The system has two multiplexed common cathode seven segment displays enabled by a logic zero.

a) Write an interrupt driven assembly language program to implement the system. The program should use
a function called MUXDISPLAY that displays the number of cars stored in a temporary register called
COUNT to the SSD’s. Assume that the park is initially empty and that you are equipped with a built in
function called, SPLIT, which returns the tens of a number in a temporary register called TENS and the
ones in a temporary register called ONES. Extra marks will be given for a well commented code. [14]

Hint: the table codes for the SSD’s for displaying numbers 0 to 9 are; 0X3F, 0X06, 0X5B, 0X4F, 0X66,
0X6D, 0X7D, 0X07, 0X7F, 0X6F with the MSB kept clear.

b) You are required to extend the system design to send the number of cars in the register COUNT, of
question C2 a) above, to a computer running HyperTerminal.

i.) Describe with a block diagram your hardware interface between the microcontroller and PC? [2]

ii.) Using the following asynchronous USART parameters; XTAL = 8MHz, 8 data bits, no parity, 1 stop
bit and baud rate of 1200bps. Determine the values to be loaded in the UCSRB and UCSRC registers.
[4]

Sensor 1 PB.7
E
PD.2 PB.0 a E a
Entry Sensor b
PB.1 b

8515 PB.2 c SSD1 c SSD0

PB.3 d d
Sensor 2 e
PD.3 PB.4 e

Exit Sensor PB.5 f f

PB.6 g g

Figure C2

5
Examinations: May 2019 Digital Systems: ENEL3DSH1 - Solution Page 6 of 15

6
Examinations: May 2019 Digital Systems: ENEL3DSH1 - Solution Page 7 of 15

7
Examinations: May 2019 Digital Systems: ENEL3DSH1 - Solution Page 8 of 15

8
Examinations: May 2019 Digital Systems: ENEL3DSH1 - Solution Page 9 of 15

9
Examinations: May 2019 Digital Systems: ENEL3DSH1 - Solution Page 10 of 15

*Interrupt Sense control for INT 1 is same as the table above except, ISC01→ ISC11, ISC00→ISC10

10
Examinations: May 2019 Digital Systems: ENEL3DSH1 - Solution Page 11 of 15

11
Examinations: May 2019 Digital Systems: ENEL3DSH1 - Solution Page 12 of 15

12
Examinations: May 2019 Digital Systems: ENEL3DSH1 - Solution Page 13 of 15

13
Examinations: May 2019 Digital Systems: ENEL3DSH1 - Solution Page 14 of 15

14
Examinations: May 2019 Digital Systems: ENEL3DSH1 - Solution Page 15 of 15

15

You might also like