Docsity

Tutorial 3 Embedded Microcontrollers, Exercises of Microcontrollers

Toggle sidebar
bg1
EEE20003 Tutorial - 3
Q1) The diagram below shows a house alarm using an I/O port on the MK20. The alarm is triggered by
detection of an intruder whilst the alarm is enabled through the key switch. A pressure mat or the
opening of a door may be used to detect intruders. A light indicates the triggering of the alarm.
Name
Type
Function
Light
Output
This is switched HIGH when the alarm is triggered and
remains HIGH until the alarm is disabled. The light requires
approximately 6mA current.
Pressure Mat
Input
Detects an intruder (momentary HIGH contact)
Door Sensor
Input
Detects a door being open (momentary HIGH contact).
Key Switch
Input
Used to enable/disable the alarm
(Static, HIGH => ON / LOW => OFF).
Write a C program to implement this alarm.
Q2) The diagram below shows a simple control system designed to maintain the water level in a tank between
two levels by turning on and off a pump. To reduce wear on the pump it is necessary to minimise how
often the pump is turned on and off โ€“ the running period is of secondary concern. To achieve this, the
water pump is initially turned on when the water level falls below the Too Low Sensor and then kept on
until it rises above the Too High Sensor. The pump is not turned on again until the water again falls below
the Too Low Sensor. In this way the water level is allowed to vary over the range between the sensor
levels which helps ensure that the pump motor is not cycled on and off too frequently.
MCU
C.0
C.5
C.4
C.3
MK20
C.7
High
Low
Pump
Tank
C.4
C.0
Water
Pump
pf2

Partial preview of the text

Download Tutorial 3 Embedded Microcontrollers and more Exercises Microcontrollers in PDF only on Docsity!

EEE20003 Tutorial - 3

Q1) The diagram below shows a house alarm using an I/O port on the MK20. The alarm is triggered by detection of an intruder whilst the alarm is enabled through the key switch. A pressure mat or the opening of a door may be used to detect intruders. A light indicates the triggering of the alarm.

Name Type Function Light Output This is switched HIGH when the alarm is triggered and remains HIGH until the alarm is disabled. The light requires approximately 6mA current.

Pressure Mat Input Detects an intruder (momentary HIGH contact)

Door Sensor Input Detects a door being open (momentary HIGH contact).

Key Switch Input Used to enable/disable the alarm (Static, HIGH => ON / LOW => OFF).

Write a C program to implement this alarm.

Q2) The diagram below shows a simple control system designed to maintain the water level in a tank between two levels by turning on and off a pump. To reduce wear on the pump it is necessary to minimise how often the pump is turned on and off โ€“ the running period is of secondary concern. To achieve this, the water pump is initially turned on when the water level falls below the Too Low Sensor and then kept on until it rises above the Too High Sensor. The pump is not turned on again until the water again falls below the Too Low Sensor. In this way the water level is allowed to vary over the range between the sensor levels which helps ensure that the pump motor is not cycled on and off too frequently.

MCU

C.

C.

C.

C.

MK

C.

High

Low

Pump

Tank

C.

C.

Water

Pump

EEE20003 Tutorial - 3

The sensors and pump control are connected to PORT C of a MK20. The port pins used are summarised in this table: Bit Number Function Logic Levels 0 Input from Too High Sensor

0 => water level lower than sensor 1 => water level higher than sensor 4 Input from Too Low Sensor

0 => water level lower than sensor 1 => water level higher than sensor 7 Output to Pump

0 => pump off 1 => pump on

Write a program in C to implement this control system

Q3) Write a program to emulate a thermostatically controlled heater system with the following operation.

The room temperature is monitored with a temperature sensor that provides a voltage in the range 0 โ€“ 3.3V covering the temperature from 15 to 35 Celsius in a linear fashion. The thermostat is emulated by the potentiometer provided. The room heater is to be switched on at the set temperature T with a 4 degree hysteresis i.e. switch on at (T-2) off at (T+2). Heater operation is emulated by an LED. The set temperature is initially 20 C. The system is to sample the temperature every 10 seconds. It should report measurements and actions when doing this to the console.

Challenges

  • Allow the set temperature to be modified with the Up/Down buttons. The set temperature

is reported on the console when changed.

You may use the provided hardware to test your code.

MK

R1 R2 ADC Channel

3.3V

GPIO