Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: THEend8_
EMBEDDED PROCESSORS 2 (ENG2029)
The numbers in square brackets in the right-hand margin indicate the marks allotted to the
part of the question against which the mark is shown. These marks are for guidance only.
Attempt all questions
An electronic calculator may be used provided that it does not have a facility for either
textual storage or display, or for graphical display.
Continued overleaf
Page 2 of 6
Q1 The code in Figure Q1 is run on a Cortex M0+ microcontroller.
#include "mbed.h"
unsigned int delay(volatile unsigned int loop)
{ while (loop)
{
loop--;
}
return loop;
}
int main() {
DigitalOut gpo(PTD6);
while (true) {
gpo = 1;
delay(4800);
gpo = 0;
delay(9600);
}
}
Figure Q1.
(a) What function does the line DigitalOut gpo(PTD6) perform and why?
[3]
(b) Does this program cause the microcontroller to output any signal? If so, on
which pin does it occur? Sketch this waveform. [3]
(c) The output signal is observed to have a period of 900μs. If the clock
frequency of this Cortex M0+ processor is taken to be 48MHz, estimate the
number of clock cycles which are occupied by one pass through the loop
inside the function delay. [3]
(d) Given your answer to part c is an estimate, what other timings would it be
necessary to know in order to make a more accurate calculation? [2]
(e) What changes in the program would be necessary if the period of the
waveform was to be reduced to 300 μs? The ratio of the time spent high to the
time spent low should be maintained as it was in the original program. [3]
(f) Write the additional code necessary if the original program is to be altered so
that a second waveform is also produced. The specification is as follows: [6]
- Both waveforms should have a period 900 μs.
- The waveforms should appear on bits 6 and 7 of port D.
- The second waveform should be high for double the time that the
first waveform is high.
Continued overleaf
Page 3 of 6
Q2 (a) A simple Arithmetic and Logic Unit (ALU) has two registers, A
(Accumulator) and B. Draw a diagram to show how data busses can be
connected between A, B and the ALU output so that the result of an arithmetic
or logical operation can be stored in the accumulator register. [4]
(b) By using your simple diagram further show how data can be transferred
between the registers and memory. [4]
(c) Figure Q2 below is the schematic for a 4-bit ALU (but does not show the
registers). Complete the following table for this 4-bit ALU, where x’s
represent don’t care states, and ?’s are to be determined. Explain your result
in each case.
Figure Q2: A and B are 4-bit inputs. Z is a 4-bit output.
K L M N O P Q A B Z
0 0 1 0 1 0 0 0101 0010 ????
1 1 1 0 1 0 0 0101 0010 ????
? ? ? ? ? ? ? xxxx 1110 1111
x x x x X 0 1 0101 1011 ????
Continued overleaf
Page 4 of 6
Q3 (a) Define the terms ‘synchronous serial’ and ‘asynchronous serial’ and give an
example of each type which might be found in an embedded processor. [3]
(b) An SPI (Serial Peripheral Interface) and a UART (asynchronous serial)
module both transmit the byte 39h. Draw the expected waveforms for the SPI
link and for the output of the UART. [2]
(c) Draw the expected output signals when the SPI link is idle and when the
UART is not transmitting anything. [2]
(d) 100 bytes of data is to be transmitted via both an SPI and an asynchronous
serial link. If the Baud rate is 1kb/s determine how long this transmission will
take for each method. Do you have enough information to properly calculate
the time in both cases? [4]
(e) The MOSI data line from an SPI transmitter is mistakenly connected to an RX
pin of a UART. The SPI transmitter sends three bytes. The waveform in
Figure Q3 was observed on the MOSI, SS and SCLK lines. Determine:
(i) What was the baud rate in use? [2]
(ii) What was the data transmitted? [3]
(iii) What was the data received? You can assume RX UART was set to
the same baud rate as SPI [4]
Figure Q3. Each division on the time axis is 100μs.
Q4 (a) Timers and counters are important resources in any microcontroller.
(i) Why do typical microcontrollers have flexible timer modules and
functions? [4]
(ii) Describe the difference between the timer and the ticker in the Mbed
system. Give instances of the use of each. [8]
(b) The following code, Figure Q4, is executed on a Freescale Freedom Board.
#include "mbed.h"
Ticker TimerInt;
volatile int i,j;
DigitalOut gpo(PTD6);
void flip() {
i++;
gpo=i & 1;
}
int main() {
TimerInt.attach_us(&flip, 1000);
// spin in a main loop.
i=0;
while (true) {
}
}
Figure Q4
(i) Sketch the output which would be observed at pin D6. [4]
(ii) You are now required to modify this code so that two output
waveforms are produced. A new second output at 1/8th the frequency
of the waveform on D6 has to be sent to A0. Indicate how the program
of figure Q4 can be modified to achieve this (You do not have to write
perfect C code). [4]
End of question paper
Page 6 of 6
Q5 (a) How many bytes are used to store an IEEE standard variable of type ‘float’
in memory? [2]
(b) In the IEEE standard format for storing single precision floating point
numbers:
(i) What is the number of bits used to store each of the sign, exponent and
fraction? [2]
(ii) What is the range of allowable values for the exponent? [2]
(iii) What is the formula used to describe the sign, exponent and fractional
parts? [4]
(c) Determine:
(i) The IEEE representation of the floating point number 37.0 [5]
(ii) The floating point number which is represented in memory by: [5]