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

Main Examination Period 2017

ECS642U/P    Embedded Systems

Question 1

a) Give brief answers to the following questions:

i)   What is an embedded’ (computer) system?

An embedded computer system is one that is inside another system, so that the computer system becomes a component.

ii)  Give two examples of real-world embedded systems.

An engine control system in a car. A control unit in a traffic light system.

iii) What is the difference between a processor (CPU) and a micro-controller (MCU)?

An MCU contains a CPU but also I/O peripherals; many MCUs also contain memory and no external connection to the memory bus.

iv) Give two example of a peripherals found in a typical MCU.

GPIO, ADC, DAC, PIT … .

v)  What is pin multiplexingand why is it used?

Pin multiplexing means sharing pins between different functions i.e. different peripherals. Sharing reduces the total pin count, reducing cost (of the circuit).

vi) What is a sleep modeand why is it useful?

In sleep mode, the processor stops executing (though some state is retained). This is useful as the peripherals can continue to work, waking the processor when it is needed, reducing power             consumption.

b) A micro-controller contains a 32-bit General Purpose I/O (GPIO) port. The port is to be used to control an LED and to react to a button, using polling. Outline the steps needed to configure the port for this use. You are not required to use the exact names of           registers or to write code.

•    Clock distribution to the port

•    The pins must be set to GPIO in the PIN multiplexing (PORT) register

•    Data direction is used to set one pin is output (LED) and the other as input (button)

•    A pull-up register may be needed for the input pin (unless one is configured externally.

c) A push button is attached to a micro-controller GPIO pin, configured so that an interrupt occurs when the button is pressed and an Interrupt Service Routine (ISR) is called.

i)   What change (or changes) in the voltage on the GPIO pin can be configured to cause the interrupt to occur?

The interrupt is usually configured to occur on the falling edge; rising edge is also an option.

ii)  How is the ISR connected to an interrupt on a specific GPIO pin a) by the programmer and b) when the program runs?

The programmer must give the ISR the correct name. When the program runs, the address of the ISR is found in the vector table (in NVIC peripheral). Note that the interrupt is for a port, so code is need to check which pin caused it.

iii) Outline what happens in the CPU when the interrupt occurs.

The program counter and some registers are saved on the stack (further info: there are two stacks) so that the running program can be resumed when the interrupt completes. The ISR address is then loaded to the program counter. (Conventions to do this registers usage were not covered.)

Question 2

a)  An embedded system uses an analogue to digital converter (ADC):

i)   Explain the purpose of an ADC. Give two example of physical quantities that could be measured using an ADC.

Temperature, pressure, humidity, … .

ii)  A voltage in the range 0 to 3.3v is measured using an ADC with a resolution of 12- bits. What is the average quantisation error in this scenario?

There are 2^12 different values: the max quantisation error is 3.3/2^12 (or 0.5 * 3.3/2^12) and the average is half this. ( The factor of 0.5 depends on how the ADC works; either answer fine).

iii)  Explain the difference between a single-ended (i.e. normal) ADC conversion and a differential conversion, including how the quantisation error (assuming the same    parameters as part ii) above) is affected.

The error doubles as the result is a signed integer, representing a voltage between -3.3v and 3.3v.

b)  One design of an ADC is a successive approximation ADC.

i)   Outline the operation of this type of ADC.

The ADC uses a DAC and a comparator. At each approximation step, the next most significant bit is set in the current approximation; this is used to generate a voltage (using the DAC) and             compared with the voltage to be measured. The result determines whether the bit is correct:         generated voltage greater -> bit cleared; lower -> bit set. The number of approximation steps is    equal to the resolution of the ADC.

ii)  Explain the factors that influence the time taken to complete a conversion.

The main factor is the resolution, as each extra bit requires another approximation cycle (3 marks). Each cycle must include sufficient time for the voltage being measured to be sampled: this time     can be adjusted and you need more time if the source has higher impedance. (1 mark) The ADC   can also do averaging (1 mark alternative).

c)  A value measured by an ADC is used to control a motor. It is proposed to use Pulse Width Modulation (PWM) to vary the speed of the motor.

i)   Outline the principles of PWM and why it is suitable for this application.

Diagram useful.

An analogue value is created by varying the duty-cycle of a on / off output. The duty cycle is the ratio between the on time and the off time. The modulation frequency is the frequency of the on / off signal and must be higher than the maximum frequency of the analogue signal that we are    creating.

A motor does not act quickly to changing voltage so is suitable to be controlled in this way (CS students taking this module may not know what an inductor is).

ii)  A PWM peripheral (such as the KL25Z’s TPM) is driven by a clock of frequency f   and has a modulo value MOD and a channel value CnV. Explain the relationship   between these values and a) the modulation frequency and b) the effective voltage driving the motor.

a)  The modulation frequency is given by MOD cycles (actually MOD+1) of the frequency f. Modulation freq = f / MOD

b)  (Depending on the type of modulation selected) the pulse is high for CnV counts of the clock (CnV <= MOD). So duty cycle = CnV / MOD, which gives the effective volts as a proportion of the max.

d)  A particular use of the ADC requires a very high sample rate. When each conversion is requested separately by the CPU, it is unable to reach the required rate.

i)   Explain how Direct Memory Access (DMA) might allow a higher sample rate to be achieved, but also noting the limits that cannot be overcome in this way.

Using DMA, values sampled by the ADC are written directly to memory without invention of the processor. This reduces the CPU workload but does not reduce the time for each sample.

ii)  Outline how the DMA can be triggered and how the CPU is informed when data has been sampled.

DMA can be triggered using software or a timer (PIT) or another peripheral. A flag is set for completion or an interrupt generated.

Question 3

a)  What are the main features of development board, such as the FRDM KL25Z, that distinguish it from a MCU?

The development board includes a debug unit, some devices (LED, accelerometer), power connector and headers. ]TV!s l!s} !s no} pa}!n!}!va - en(}V!n6 sVow!n6 nnpaJs}enp!n6 !s o才.[

b)  An embedded system is being developed in C, using a development board and an IDE.

i)   Explain the steps that enable a program written in C to run on the target processor? Note any assumptions you make about the setup of the development environment.

The program is compiled using a cross compiler for the target processor. It is linked to form an    image. The image is downloaded to the memory on the target processor, via the debug interface.

ii)  A bug is suspected in the program. Suggest two techniques that could be used inspect the operation of the program, noting any limitations.

A (small number of) variables can be monitored (“watched”) – the values are updated to the IDE in real-time. The data rate is limited and the variable must be statically allocated (global, roughly).     Break points can be inserted into the program to stop execution at a chosen location. The value of any variable (or register) can be inspected when program is stopped.

c)  In a some application, the developer needs to know:

i)   how quickly a processor can react to an event (such a voltage rise), and

Could use an oscilloscope, displaying the event and a signal from the processor; there is an overhead as the processor takes some time to assert the signal.

ii)  how long the processor spends executing part of the code.

Outline how these values could be measured.

Could also use an oscilloscope by toggling a signal on a pin and the start / end of the code block.  [Alternative answer: use a timer: start/stop or just read it at beginning / end of code block and store value for inspection in the debugger.]

d)  A system has 4 tasks; it is proposed to schedule the tasks to run in a cyclic system. The periods and the estimated Worst Case Execution Times (WCET) of tasks are:

Tes

daJ!op )ms(

MO3T )ms(

A

20

2

B

5

1

C

10

3

D

5

1

i)   Calculate the utilisation of the computer for each tasks and explain the relevance of the total utilisation for determining if the workload can be scheduled.

2 + 4 + 6 + 4 = 16 / 20 The total utilisation must be less than on otherwise the processor is overloaded. (Even so, schedule may not exist).

ii)  Explain the concepts of major and minor cycles in a cyclic schedule, giving the values for this workload.

Minor 5, major 20

Major cycle: period after which the schedule repeats. LCM of task periods.

Minor cycle: major cycle made up of an integral number of minor cycles; in each one of more tasks is run. GCD of task periods.

iii)  Give a schedule for the tasks, or explain why they cannot be scheduled.

1.   BDCCC

2.   BDAAX

3.   BDCCC

4.   BDXXX

Question 4

A proposed system has the following requirements:

A system has a button, two analogue sensors (S1 and S2) and an LED. The button    switches between the two sensors. The LED is lit when the reading from the currently selected sensor exceeds 50% of the full range.

Answer the following questions relating to these requirements.

a)  The system is being implemented using a FRDM KL25Z development board. Select suitable pins to connect the sensors, button and LED to the KL25Z board (see         information in the Appendix); briefly justify you choices.

S1, S2: PTE20, PTE21 – useable for ADC, connected to a header

Button: PTD4 – connected to a header, (interrupt for port D)

LED: PTA1 – almost anything could do

b) The button is to be polled using a cyclic system.

i)   Explain the difference between the position of the button and the button press event.

The button position corresponds to the state (value) of the input (0 – button down). A press vent occurs when the button is pressed, detected by the value going from 1 to 0. (A transition)

ii)  What is button bounce, how is it caused and why might it be a problem?

The button contacts may close and open as the button is pressed – mechanical bouncing. It is a problem as several transitions occur and could be interpreted as more than on press event.

iii) Outline code to sense when the button is pressed, taking account of possible bounce.

State Up, Down, Bounce

Switch state

case up: if position is down, then event occurs and state is down

case down: if position is up then state is bounce, start timer

case bounce:

if timer expired state is up

if position is down then state is down (NO NEW EVENT)

c)  A State Transition Model (STM) diagram has been prepared (see Figure 1) that is intended to specify how the system responds to the button.

 

Figure 1: State Transition Model

i)   Explain the elements of the Figure 1 diagram.

S1-low, S1-high are states

Solid circle is initial state

Line are transitions, labelled with: a) [condition] and b) / action

ii)  Explain whether the model shown in Figure 1 covers all of the given requirements for the response to the button; if it does not, describe which requirements are   omitted.

The STM does not show the button causing the change between two sensors. It only shows the LED going on and off depending on the current sensor value.

iii) Assuming that the press of the button can be modelled by an event buttonPress’, redraw the diagram adding elements to model the omitted requirements.

Version 1:

 

Page 10

Version 2 (horizontal transitions not labelled)

 

d) The sensors are to be read 1000 times a second.

i)   Outline how the Programmable Interrupt Timer (PIT) can be used to control this timing precisely.

The PIT can be used to create an interrupt every 1ms and the sensor is read in the ISR.

ii)  The PIT has a clock frequency of 24 MHz. Calculate the count down value that should be used to ensure the sensors read at the specified frequency.

count = 1ms x 24MHz = 10^-3 x 24 x 10^6 = 24,000