Professional Documents
Culture Documents
School of Engineering
MAIN EXAMINATIONS: MAY 2019
SUBJECT COURSE and CODE: Digital Systems: ENEL3DSH1
PAPER: 1
Instructions:
Answer in ink, diagrams may be drawn in pencil. This question paper contains a total of 15 pages
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
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.
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%
2
Examinations: May 2019 Digital Systems: ENEL3DSH1 - Solution Page 3 of 15
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.
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.
Mark breakdown:
MCU setup section [10]
Main loop [4]
Delay subroutine [6]
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
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]
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]
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]
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
PB.3 d d
Sensor 2 e
PD.3 PB.4 e
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