关键词 > ECS642U/P

ECS642U/P Embedded Systems 2018

发布时间:2023-01-04

Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

Main Examination Period 2018

ECS642U/P    Embedded Systems

Question 1

a) Give brief answers to the following questions:

i)    An embedded system serves a single purpose: the program cannot be changed. It has more limited interfaces (often no screen or keyboard).

ii)   A reactive system responds (or reacts) to changes in its environment.

iii)  An MCU peripheral is an interface circuit between the CPU and the pins of on the MCU: examples include ADC, GPIO, DAC, timers etc

iv)  It is hard to see what is happening inside an embedded system: for example, there is no screen. When timing is critical, any attempt to observe can change it.

v)   The principle of memory mapped I/O is that output is done by writing to a memory locations and input by reading from memory. Certain locations in memory are       ‘mapped’ to external connections.

vi)  Pins can be multiplexed: that is, shared between different peripherals.

b)

i)    This is controlled using the Data Direction Register (PDDR): each bit in this register controls whether a GPIO pin is an input or output.

ii)   Both the PDOR and the PSOR can be used to set an output: the bit in the PDOR corresponds to the output value 1 – high, 0 – low. However, the CPU only support 32-bit reads and writes so to set 1 bit only, the PDOR must be read, OR-ed with a mask and then written. The PSOR can do the same in a single write of a 32-bit     word: where the bits are ‘1’ the PDOR is updated, where ‘0’ no change is made.

iii)  Two methods are available: polling, which is repeatedly reading the value in the PDIR to see if the value has changed or having the change trigger an interrupt.

c) Give brief answers to the following questions about interrupts.

i)    An GPIO input can be configured to generate an interrupt; a PIT (timer) can generate a periodic interrupt.

ii)   The code is written in a function (with no arguments). To connect the code to the interrupt, the function must be given a set name.

iii)   Code running in an interrupt runs asynchronously with the cyclic system, as the    interrupt can occur at any point in the cycle. Communication is by shared memory so care must be taken not to cause race conditions.

Question 2

a)

i)    An ADC is used to convert a continuously varying voltage to a digital value: examples of sensors that require an ADC are temperature, pressure, …

ii)   The resolution relates to the number of bits in the results of the ADC: a 4-bit ADC can distinguish only 16 different values, so the smallest difference between values is 1/16 of the full range. A typical resolution is in the range 8 to 16 bits.

iii)   Two techniques are a) polling a bit set by the ADC set when conversion is complete

b) configuring the ADC to generate an interrupt when the conversion is complete.

b)

i)    A DAC generates a voltage (output) whose value is given by a binary value (input).

ii)   PWM generates a variable voltage by rapidly switching a value that is either on or   off (binary). The effective voltage is given by the ratio of the on time to the off time.  The switching is done at a frequency chosen so that the application responds to the average voltage.

c)

i)    The counter value CVAL register is decremented on every clock cycle. When it      reaches zero, an interrupt is generated and the CVAL is reloaded from the LDVAL.

ii)   The LDVAL is given by 24 MHz / 12 KHz = 2000

d)

i)    A sleep mode suspends the operation of the CPU while leaving some of the       peripherals working. The CPU can be woken but a peripheral (such as a timer).  Different modes (sleep, deep sleep) varying in the retention of state and the time taken to wake.

ii)   Do not clock peripherals that are not being used. Reduce the MCU clock frequency.

Question 3

a) .

i)    The program code and assembly code can be viewed. i) Breakpoints can be set: when the program stops registers and variables can be seen. ii) Global variables can be ‘watched’ – lives updates can be seen iii) the state of peripheral registers can be inspected.

Others: serial output over UART/USB; Micro trace buffer (MTB).

ii)   The development board has a (Open SDA) debug unit, supporting the (CMSIS- DAP) debug protocol used by the IDE. The debug unit interfaces to the MCU     (using a serial wire) debug port. The MCU has a breakpoint and watch point unit (and a MTB).

b) .

i)    An oscilloscope is used: the button is used to trigger the oscilloscope and the GPIO also displayed.

ii)   The interrupt handling takes at least 16 cycles, saving the current state including PC and some registers b) the ISR must run and the GPIO be updated.

iii)   Less than 5 microseconds (depending on the clock speed, which is up to 50 MHz)

c) .

i)    A thread is a separate stream of execution through the program. Each thread has its own program counter (PC) value.

ii)   Any functions (such as a wait’) that causes a delay cannot be used in the ISR as the ISR must complete without delay.

iii)  The first thread could send a signal. The second thread could wait for a signal.

iv)  The execution of threads in interleaved. A race condition may occur.

d)

The tasks priorities are determined by the period: the shorter the period the higher the priority.

RM scheduling is the best fixed priority schedule scheme assuming periodic tasks that do not interact (and have known execution times).

There is an upper bound on the utilisation (the bound depends on the number of tasks); below this bound we can be sure that RM will schedule a set of tasks (the test is            sufficient).

Question 4

a)

Suitable peripherals are:

Movement M: ADC

Switches S1, S2: GPIO

Bleeper B: TPM (using PWM)

Suitable pins are:

M: PTE20 has ADC

S1, S2: PTA1, PTA2 for GPIO

B: PTE21 – channel 1 of TPM 0

b)

The states are:

Off: the system is off

Active; the system is active: low volume bleep

Armed: system is armed: no bleep

Sounding: an alarm has been detected; loud bleep

A diagram showing states and transitions

 

c)

The following tasks are proposed:

•    One (of more) tasks to poll S1, S2, M. The same or separate tasks could be used.

•   A task to implement the state machine and sound the bleeper

No ISRs are suggested.