Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

Department of Electrical, Electronic and Computer Engineering

Trial test: Theory


Copyright reserved

Microprocessors EMK310

13 May 2020

Test information
Maximum marks: 36 Full marks: 30
90 minutes + 10 minutes for Open book (no consulting with
Duration of paper: Open / closed book:
completing e-answer sheet any other person)
Total number of pages (including this page): 12

IMPORTANT
1. The examination regulations of the University of Pretoria apply.
2. Complete all questions in the Excel spreadsheet that must be downloaded from the EMK310 test webpage.
3. Perform calculations in a separate answer book. Submit the Excel file with your answers by uploading it via the EMK310 test
webpage to the server.
4. Correct answers will be awarded the number of marks indicated for each question.
5. If you calculated answer is not given as an option, select the closest option to your answer.
6. Hints: (i) You may use any of the resources on the PC, e.g. MS Excel. (ii) The marks awarded per question is not linearly
related to the time required for completion of the question, but is scaled according to difficulty and time required to
complete the question. Two minutes per mark are allowed for easy questions and 3.5 minutes per mark for difficult
questions.
NOTES on E-grading
● Answers are graded programmatically.
● Hexadecimal values
o Correct: 0xFF or 0x2435 or 0xA
▪ The text characters a-f, A-F, x, X and Z are acceptable in the numeric field as part of hexadecimal
numbers. Uppercase X is used to indicate a “don’t care” value, while uppercase Z indicates a
high-impedance state.
o Incorrect: 345h or FFh or Ah or ‘x’FF or xA2 or E4
● Binary values
o Correct: 0b0010 or 0b00010001 or 0b0X010001 or 0b01010ZZZ
o The text characters b, X and Z are acceptable in the numeric field as part of binary numbers. Uppercase X is used to
indicate a “don’t care” value, while uppercase Z indicates a high-impedance state.
o Incorrect: ‘b’0010 (incorrect form of b) or 0001 0001 b (spaces)
● Decimal values
o Round off all values to at least two decimals unless stated otherwise. However, use the original unrounded value in
all subsequent calculations.
o Correct: 1256.58 or 3456234.40
o Incorrect: 1256,58 (comma instead of point) or 3 456 234,40 (spaces and comma).
o Incorrect: 5000+2700 or 2*pi or 4pi (formulae and expressions are not allowed in the numeric answer field).
● Where multiple choices are provided, give only the specific letter of the choice that you made.

1
General system description

Overview
A bar-owner contracted you to create a machine that could prepare mixed drinks. However, to be able to
re-open his business under the lockdown regulations, he decided to enter the milkshake industry with an
innovation that would allow consumers to order mixed-flavour milkshakes. He consequently asked you to
re-design the system as a milkshake syrup mixer and dispenser. Having the syrup dispensed in accurate
quantities could speed up the pace at which milkshakes could be prepared for delivery. A diagram of the
invention, the Miximilki X, is shown in Figure 1.

Figure 1: Diagram of the Miximilki X.

An individual syrup bottle is further shown in Figure 2 and the start panel is shown in Figure 3.

Figure 2: Diagram of an individual syrup bottle in the


Miximilki X. Figure 3: Miximilki X start panel

2
Operation of the Miximilki X
Waiting for an order
While waiting for an order, the Miximilki X does not do anything, but checks the level of liquid within each
of the bottles.

Receiving an order
The milkshake parlour accepts online orders which are transmitted via a Wi-Fi link between a Wi-Fi module
(ESP8266) and a computer that is logging the orders. The Wi-Fi module is connected to the microcontroller
and they communicate via serial communication. Once the order is received, the system should wait until
the operator starts the mixing process.

Starting the mixing process


The operator should then observe a green LED lighting up on the start panel (Figure 3), indicating that the
system has received an order. When this LED is lit, the operator may place a measuring glass on a spot
marked 10 cm away from the first syrup bottle. Once this is done, the operator should press the “START”
button to initiate the pouring process.

Positioning the measuring glass


The Miximilki X is expected to control the movement of the conveyor belt to manoeuvre the measuring
glass between the 10 cm gaps which separate the various intervals. A control strategy is to be implemented,
for the conveyor belt motors, to ensure that the syrup is not accelerated in a manner which would cause
spillage.

Syrup pouring
The open ends of the bottles are sealed with a solenoid valve. When the valve is electronically opened, a
pre-set quantity of syrup will travel through the valve until the valve is closed. Depending on which
milkshake is ordered, it is expected that the conveyor belt moves backwards and forwards to obtain the
correct quantity of syrup following the sequence that the customer placed on his/her order. Once the syrup
mix is completed, the conveyor belt should move it to the ending position (and no further), so that the
operator may collect the syrup for further preparation of the milkshake.

Measuring the quantity of fluid remaining in the bottle


To measure the quantity of syrup remaining within the bottle, fluid level sensors have been placed within
each of the bottles. The sensors vary their resistance based on the quantity of fluid which they are enclosed
in. Based on this concept, a varying analogue voltage can be created that is related to the amount of fluid
remaining in the bottle.

The analogue voltages are then connected to the input of an analogue multiplexer which selects which
channel to propagate to the outputs (based on the select bits sent from the PIC). The output voltages are
then scaled by a scaling circuit and are sampled by the ADC of the microcontroller.

You decided to use an analogue multiplexer, as opposed to multiple ADCs, to reduce the number of scaling
circuits you would need to implement.

Empty bottle early warning system


Using the voltages sampled by the ADC, the PIC then determines the degree to which the bottle is empty. If
it is found that the bottle is nearing empty, the PIC lights up the red LED which corresponds to the near

3
empty bottle. The operator then becomes aware of which bottles to swap out before the next syrup mix is
prepared.

High level block diagram


A high level block diagram of the system can be seen in Figure 3.

Figure 4: High level block diagram of the Miximilki X.

Syrups which are used in the Miximilki X


A table of the syrups used by the Miximilki X are given in Table 1.

Table 1: The milkshake flavours in each bottle

Position in array Syrup


0 Strawberry
1 Chocolate
2 Peppermint
3 Banana
4 Raspberry
5 Lime
6 Vanilla
7 Caramel

4
Working example of the first 12 milkshake mixes that the Miximilki X can
dispense
The system keeps a record of the unique flavour mixes that are ordered. For the purpose of the question
paper, the number of unique flavour mixes that can be stored is 12. Table 2 provides a working example of
such a record.

Table 2: Unique order record example for the Miximilki X

Flavour Ingredient 1 Ingredient 2 Ingredient 3


mix ID
0 Strawberry (25 ml)
1 Chocolate (25 ml)
2 Peppermint (25 ml)
3 Banana (25 ml)
4 Raspberry (25 ml)
5 Lime (25 ml)
6 Vanilla (25 ml)
7 Caramel (25 ml)
8 Strawberry (5 ml) Vanilla (10 ml) Lime (10ml)
9 Peppermint (15 ml) Chocolate (10 ml)
10 Chocolate (10 ml) Raspberry (15 ml)
11 Raspberry (15 ml) Banana (10 ml)
12 Banana (10 ml) Caramel (10 ml) Peppermint (5 ml)
Note that for the prototype Miximilki X, the syrups must be poured in the correct quantity and sequence
from ingredient 1 to ingredient 3 since the sequence in which customers choose the ingredients for their
milkshakes is not fixed.

SECTION 1
General microcontroller theory and memory [15]

Every person who orders a milkshake must register on the system to obtain a customer number between 1
and 2000. The machine records every milkshake that is ordered. A record consists of the customer number
appended by the unique mix ID from table 2 (as the least significant bits) to form one entry.

Question 1 [1]
How many bytes are required to store a single record? Give your answer as a decimal number.

Question 2 [1]
If the maximum number of shakes that can be ordered on one day is 4000 and all the records need to be
stored on an external AT24CS32 EEPROM, how many of these EEPROMS would be required? The details of
the EEPROM are given in the attached datasheet. Give your answer as a decimal number.

Question 3 [1]
How many entries can be stored in AT24CS32 EEPROMs if you could add the maximum number of these
devices to the system? Give your answer as a decimal number.

5
Question 4 [3]
You want to read the 26th entry from the 5th AT24CS32 EEPROM (assuming it is possible to connect 5
EEPROMs in the system). Give the binary value of the Device Address (use 0bkkkkkkkk format).

Question 5 [1]
You want to read the 26th entry from the 5th AT24CS32 EEPROM (assuming it is possible to connect 5
EEPROMs in the system). Give the hexadecimal value of the First Word Address (use 0xkk format).

Question 6 [1]
You want to read the 26th entry from the 5th AT24CS32 EEPROM (assuming it is possible to connect 5
EEPROMs in the system). Give the hexadecimal value of the Second Word Address (use 0xkk format).

Question 7 [2]
You use computed goto look-up tables to store the recipes for the twelve unique flavour mixes (Table 2 gives
an example for the question paper). Every line in the look-up table contains (i) the position of the syrup in
the Miximilki as the most significant nibble and (ii) the millilitre value of the ingredients divided by 5 as the
least significant nibble, in mixing order.

org 0x100

Shake00
addwf PCL
retlw 0x05 ; Position 0, 25 ml
retlw 0x00 ; No entry(Position 0, 0 ml)
retlw 0x00 ; No entry(Position 0, 0 ml)

Shake01
addwf PCL
retlw 0x15 ; Position 1, 25 ml
retlw 0x00 ; No entry(Position 0, 0 ml)
retlw 0x00 ; No entry(Position 0, 0 ml)

Shake02
...
Given the code above, at which address will the second ingredient of Shake03 be located? Give your
answer in hexadecimal (0xkk) format.

Question 8 [2]
You run out of memory and decide to reformat the computed look-up tables to make use of a single table
using table reads and writes. The table is configured as shown below.

org 0x100
Shakes: db 0x05, 0x00, 0x00 ; Shake 00
db 0x15, 0x00, 0x00 ; Shake 01
...
Given the code above, at which address will the second ingredient of Shake03 be located? Give your
answer in hexadecimal (0xkkkk) format.

Question 9 [2]
How many entries may be stored in a computed goto lookup table that starts at address 500h in the
PIC18F45K20? Give your answer as a decimal value.

6
Question 10 [1]
Is there a problem with the code below? If so, list all the lines that would cause a problem. If your answer
contains multiple letters, write the letters without commas or extra characters, e.g. abcd

1 org 0h
2 CLRF LATA
3 CLRF TRISA
4 CLRF ANSEL
6 CLRF LATB
7 CLRF TRISB
8 CLRF ANSELH
9 CLRF MyVar
10 org 00Ah
11 Table
12 addwf PCL
13 retlw 0x01
14 retlw 0x02
...
a) The code is correct.
b) Problem in line 1
c) Problem in line 2
d) Problem in line 3
e) Problem in line 4
f) Problem in line 5
g) Problem in line 6
h) Problem in line 7
i) Problem in line 8
j) Problem in line 9
k) Problem in line 10
l) Problem in line 11
m) Problem in line 12
n) Problem in line 13
o) Problem in line 14

SECTION 2
Serial communication (RS232 & I2C) [8]

Question 11 [1]
The baud rate required for the ESP8266 module is 57600. If the internal oscillator of the PIC18F45K20 is set
to 16 MHz, what decimal value should be loaded into the SPBRG register? Note: SYNC = 0, BRGH = 1, BRG16
= 0. Give your answer as a decimal number.

Question 12 [1]
If the serial communications protocol makes use of 8N1, how many bits of data are sent during the
transmission of the string “MIXIMILKIX”? Give your answer as a decimal number.

7
Question 13 [2]
If the maximum allowed length for a shake order is 24 characters, assuming 8N1, what is the minimum
allowable baud rate for the entire order to be received in at least 25 ms? Give your answer as a decimal
number.

Question 14 [2]
From the conventional RS232 timing diagram below of the transmission of 0x09 (8O1 communication
protocol, i.e. 8 data bits, parity bit using odd parity, and 1 stop bit), what is the most likely cause of a packet
transmission failure? Write only the letter in the Unit/Text field, e.g. k

a) The voltage levels are inconsistent with the RS232 standard.


b) The start bit is incorrect.
c) The stop bit is incorrect.
d) The parity bit is incorrect.
e) The signal is inverted.
f) The incorrect number of bits have been transmitted.
g) The incorrect message has been transmitted.
h) Nothing is wrong, the packet should be transmitted correctly

Question 15 [1]
In the figure below, identify which block contains an I2C "bus idle" condition. Write only the letter in the
text/unit field.

8
Question 16 [1]
In the figure above, identify which block contains an I2C "stop" condition. Write only the letter in the
text/unit field.

SECTION 3
Input / Output (sensors & ports) [8]

Question 17 [1]
The voltages from the fluid level measuring circuits (Inputs in the figure below) are relayed to the ADC
(Output in the figure below) using an 8-bit multiplexer as shown below. PORTD[2..0] (connected to S2 to S0)
is used to select the voltage to relay. Assuming that the input order of the multiplexer is the same as the
order in Table 1, what should the value on PORTD[2..0] be to determine the level of vanilla syrup? Give your
answer as a binary value (use 0bkkk format).

Question 18 [1]
The H-bridge that controls the conveyor belt motor is given in the figure below.

You will use two port pins RA0 and RA1 to control the direction of the conveyor belt and thus the direction
of the motors. When current flows into the positive terminal of the motor and out of the negative terminal
of the motor into ground, the conveyor belt moves forward. If pin RA0 needs to be set to close the switches
that will cause the conveyor belt to move forward, which switch/es (S1 to S4) should be connected to
PORTA pin RA0?

9
a. S1
b. S2
c. S3
d. S4

If your answer contains multiple letters, write the letters without commas or extra characters, e.g. abcd

Question 19 [2]
Give the addresses of the registers that should be initialised to use PORTA as described? Write your answer
in the numeric field separated by commas, e.g. 0x002,0x0F5,...

Question 20 [1]
When both PORTA,0 and PORTA,1 is set high at the same time, it could be catastrophic. Therefore we can
use some logic gates to ensure that this never happens as shown in the figure below.

Which logic gate has to be placed in the center block to ensure that the circuit will still function as required,
while ensuring that both inputs to the H-bridge would never be high at the same time? Just write the name
of the logic gate in the text/unit field e.g. AND, OR, NAND, NOR, XOR etc.

Question 21 [2]
Which statements have to be executed for the interrupt of the “START” button. Assume an external
interrupt at PORTB,0. If your answer contains multiple letters, write the letters without commas or extra
characters, e.g. abcd

a. BCF TRISB,0
b. BSF TRISB,0
c. BSF INTCON,INT0IE
d. BCF INTCON,INT0IE
e. BSF PIE2,CCP2IE
f. BSF INTCON,INT0IF
g. BCF INTCON,INT0IF
h. BCF PIE2,CCP2IE
i. BCF INTCON,GIE
j. BSF INTCON,GIE
k. BSF IPR, CCP1IP
l. BCF IPR, CCP1IP

Question 22 [1]
To drive the conveyor belt motors a pulsetrain of a 100 pulses is required. This can be accomplished by
using the following code:

10
MOVLW X
MOVWF EMK
LoopHere
DCFSNZ EMK,f
GOTO endBranch
BTG PORTA,0
CALL Delay
GOTO LoopHere
endBranch

What should the value of EMK be in order for the code to generate a pulse train of a 100 pulses? Give your
answer as a decimal value.

SECTION 4
Timing (delays, timers & oscillators) [5]

Question 23 [1]
If the conveyor is set to move at 30 mm/s, calculate the delay needed in order to move the measuring glass
between two syrup bottles. Because of the control strategy, it takes 3 seconds over the first 10 mm to
achieve full speed. Give your answer as a decimal value.

Question 24 [1]
Calculate the value of X (inner loops) that is needed to implement the full delay calculated in the previous
question if the clock frequency is set as 1 MHz, Z = 10, Y = 196 and the following code is used. Give your
answer as a decimal value.

DELAY
MOVF Z
MOVWF Delay3
Loop3
MOVF Y
MOVWF Delay2
Loop2
MOVF X
MOVWF Delay1
Loop1
DECFSZ Delay1,f
GOTO Loop1

DECFSZ Delay2,f
GOTO Loop2

DECFSZ Delay3,f
GOTO Loop3

RETURN

Question 25 [1]
It was decided that a timer is better suited to implement the delay. If Timer1 and the internal oscillator on
the PIC is used, and the oscillator is set to 250 kHz, calculate the value that must be written to
11
TMR1H:TMR1L. Assume the timer operates in 16-bit mode, with a prescale value of 8. Give your answer as
a decimal value.
(Hint: writing a value to TMR1H:TMR1L is the same as loading the period register PR2 with a specific value when using
Timer 2.)

Question 26 [2]
If Timer2 is used to implement the delay, calculate the slowest speed that the conveyor can move in mm/s
to pour the milkshake syrups. Assume that the conveyor is stopped after each timer interrupt, i.e. it moves
10 cm for each delay. Give your answer as a decimal value.
(Hint: You may decide on a most appropriate speed for the oscillator to implement this specific delay requirement. )

References

Image URLs
● https://www.microchip.com/PIC18F45K20
● https://en.wikipedia.org/wiki/ESP8266
● http://sweetclipart.com/generic-smartphone-illustration-1372
● http://www.idownloadblog.com/2016/10/07/wifi-the-strongest-link/
● https://www.circuitspecialists.com/74hc4052.html
● https://openclipart.org/detail/248021/red-led-lamp-on
● https://www.shutterstock.com/search/conveyor+belt

12

You might also like