Sunteți pe pagina 1din 14

Department of Assignment

Engineering and Specification


Mathematics

Session:
Module: Embedded Systems Design - 55-501340
Module Leader: Alan Holloway
Assignment number/title: 1
Academic contact for guidance: a.f.holloway@shu.ac.uk
Maximum word count or number of pages: Equivalent to 2000 words
Percentage contribution to overall module mark: 50%

Deadline for submission:

Method and Location for Submission: Blackboard Submission

Deadline for return of feedback:

Module learning outcomes to be assessed:

 Demonstrate an understanding of typical embedded microprocessor systems in


terms of the microprocessor architecture, memory, parallel and serial I/O
facilities, interrupts, timer/counters and their cost.

 Design, implement and test systems, written in a high level programming


language such as 'C' using appropriate programmable interface devices from an
initial specification through to validation.

 Design, implement and test systems, written in a high level programming


language such as 'C' using appropriate programmable interface devices from an
initial specification through to validation.

References/recommended reading:

The Designer's Guide to the Cortex-M Processor Family: A Tutorial Approach


T. Martin
Publisher: Newnes (13 May 2013)
ISBN-10: 0080982964
ISBN-13: 978-0080982960

The Indispensable Guide to C with Engineering Applications


P. Davies
Publisher: Addison Wesley; 1 edition (27 Feb. 1995)
ISBN-10: 0201624389
ISBN-13: 978-0201624380

Embedded Systems Design Part A Sem 1 (2020 -2021) 1


Please ensure that all sources of information used are referenced. For guidance see
http://libguides.shu.ac.uk/referencing
All assessments are subject to SHU's collusion and plaigiarism regulations. Please refer to:
https://students.shu.ac.uk/shuspacecontent/assessment/plagiarism

Embedded Systems Design Part A Sem 1 (2020 -2021) 2


Embedded Systems design Module Guide (Section A only)

Note the module is split into two sections (A & B). The weighting for assessment purposes is divided equally
each section contributing 50%.

Assessment (Section A only!)

Section A of this module is assessed through 100% coursework and you will be required to submit a portfolio of work
undertaken. Normally there will be a series of lab exercises, a set of homework/self-study questions (non assessed)
and a major assignment. The major assignment will be a demanding problem typically requiring the development of a
complete microprocessor/microcontroller system for a specific application. The major assignment will be assessed in
part by a formal written report.

Portfolio Weighting Comments


Contents Section(A)
Lab Exercises 10% The programming exercises are to be demonstrated in week
commencing the (See Blackboard) during your normal
laboratory class.
Main Demonstrated in week commencing the (See Blackboard)
90%
Assignment

Embedded Systems Design Part A Sem 1 (2020 -2021) 3


Embedded Systems Design

GPIO Exercises for the STM32Fxx development boards

All programs should be developed and tested using the u-Vision development system and debugger. It is essential
you become very familiar with these software tools.

Useful notes:
 Use the sample Blinky project file as a starting point. You can re-use the same project for all these
exercises by replacing the 'C' files. Remove the previous 'C' file and add the new 'C' file. Removing a file
from a project does not delete the file!
 Layout your program neatly – look at the layout in the example programs and read the C style guide for
further guidance.
 Beware of 0 and O! The number zero is 0 and the letter 'oh' is ‘O’.
 Learn how to use the simulator effectively. It will save you a lot of time in the long run! Use the facility to
view the peripheral devices of the microcontroller when you test your programs.

Save the original Blinky 'c' source with a new name (something sensible such as Q1.c make sure you have used
the .c file extension). Remove the old 'c' source file by right clinking on the file and select remove from the project
(figure 1a). Next add your newly saved file to the project by right clicking on the Source Files folder, select Add Files
to Group 'Source Files'…. (figure 1b). Navigate to the location of file and select Add. Your new 'c' source file should
now be added to the Source Files folder in the project. Repeat this for all the following questions so each exercise has
an individual 'c' source file.

Figure 1a Figure 1b

Q1 Write a program to produce a 3 bit binary count on 3 of the development board LED's.

000, 001, 010, 011 …….. 111

See the schematic for the development board to establish which port pins are connected to the required LED's.
Remember you will need to initialise each port pin as an output with suitable characteristics and enable the clock
each I/O pin (see Blinky example for reference).

Q2 Write a program that performs the following:

Embedded Systems Design Part A Sem 1 (2020 -2021) 4


- Configures one of the pins connected to a suitable push button as a digital input and a pin connected an LED as a
digital output. (See development board schematics for suitable port pins).

- Continuously polls (checks the status) of the input pin connected to the push button and if pressed illuminates the
LED.

Q3 This exercise is to count logic pulses on a single input bit using a polling technique.

The program should initialise a variable to zero and continuously poll (check the status) of the input pin. For every
press of the pushbutton the program should increment the variable and output the variable to the Debug (printf)
Viewer.

Q4 (STM32F4-Discovery Board Only ) Connect 2 external switches to suitable port pins on the development board
and configure the pins as inputs in your program. Your program should poll the input pins and reading their status
and illuminate one of 3 LED's depending on the input combination as defined by the truth table below.

SWITCH 1 SWITCH 2 LED OUTPUT


0 0 All Off
0 1 LED1
1 0 LED2
1 1 LED3

Additional Notes:

For use of the Debug (printf) Viewer see introductory handouts.

Data sheets, User Guides & other information


See the module Blackboard site for links to the uVision software and relevant datasheets
Use the on-line help in u-Vision.

Embedded Systems Design Part A Sem 1 (2020 -2021) 5


Embedded Systems Design

General Notes!

 Use the sample example ADC project file as a starting point. You can re-use the same project for all these
exercises by replacing the 'C' files. Remove the previous 'C' file and add the new 'C' file. Removing a file
from a project does not delete the file!
 Layout your program neatly – look at the layout in the example programs and read the C style guide for
further guidance.
 You will be required to demonstrate the example lab questions you have completed as part of the
assessment for the module, make sure you save the c source file for each question separately.

ADC Lab questions

Q1 Connect an external potentiometer between 3V and GND on the STM32F4 discovery board and feed the wiper
output (Vout) into a suitable ADC input on the microcontroller (see diagram below). The potentiometer should
generate a voltage from 0 to +3 volts to simulate a sensor signal.

+3V
+3V & GND Vout 0 - 3V - Connect to a
from Discovery suitable ADC input pin
Board (PA3)
GND

Download the example ADC program and alter the value of the potentiometer - what's happening in your program?
Confirm the correct conversion is taking place using a Digital Multi-Meter DMM.

Q2 Save the example program as a new source file and add it to your project (remember to remove the old file).
Modify the program to do the following:

Read the input voltage from the potentiometer every 50ms (approximately)

If the input voltage is < =1V switch on the Green LED


If the input voltage is > 1V & < 2 switch on the Red LED
If the input voltage is >= 2 switch on the Blue LED

Q3 Assume that the input to the ADC channel is from a temperature sensor which generates 0 to 3 volts for the
temperature range 0 ºC to 100 ºC. Modify the program to print out the temperature in degrees centigrade. Calculate the
resolution of your temperature value and print it out to an appropriate number of decimal places. Remember the ADC
is 12-bit and the ADC reference voltages are … (see datasheet)

Q4 Copy the first Binky example program and modify it so that the delay is determined by the analogue input on
ADC. This will enable the speed of the flashing LED sequence to be modified while the program is executing by
turning the potentiometer connected to ADC.

Embedded Systems Design Part A Sem 1 (2020 -2021) 6


GND

+3V
PA1

A number of the pins can be used as analogue I/O - for full details see the excel spread sheet "Kornak-(STM32-
Discovery-F4)-0001 Rev n.nn Module Pinouts & Functions.xls" and/or use the datasheet for the chip.

Below are some suggested pins where the alternate functions are primarily for the more complex peripherals (Ethernet
& USB) and which will probably not be used. These therefore make ideal ADC inputs.

STM32F4 Discovery Pin Name and


Pin F4 Pin LQFP100 Function
PB0 P1.22 35 PB0-ADC12_IN8
PB1 P1.21 36 PB1-ADC12_IN9
PC1 P1.7 16 PC1-ADC123_IN11
PC2 P1.10 17 PC2-ADC123_IN12
PC4 P1.20 33 PC4-ADC12_IN14
PC5 P1.19 34 PC5-ADC12_IN15

Embedded Systems Design Part A Sem 1 (2020 -2021) 7


Embedded Systems Design

General Notes!

 Use the sample example projects as a starting point. You can re-use the same and replace the 'C' files as
required with your own code. Note you must remove the previous 'C' file which contains the main(), you
can only have one main()in the project. Removing a file from a project does not delete the file!
 Layout your program neatly – look at the layout in the example programs and read the C style guide for
further guidance.
 You will be required to demonstrate the example lab questions you have completed as part of the
assessment for the module, make sure you save the c source file for each question separately.
 You may use the peripheral driver libraries provided by STM if you wish however you will be required to
explain the operation of the code and why you have set specific parameters.

Timer & Interrupt Lab questions - You must use a hardware timer for the following questions.

Q1 Replace the software delay function used in Blinky example with one that uses a hardware timer. You will need to
select which timer to use, select a suitable prescaler value and to calculate the value that needs to be loaded into the
timer/counter to generate a 4.0 second delay. Note: some counters can be programmed to count up or down, others are
fixed to count up. After the timer has been initialised and started, the timer overflow flag should be polled to detect
when it changes from logic 0 to logic 1 indicating the timing period has elapsed.

Q2 Add start/stop (running/inactive) functionality to Q1 (above). This must be controlled using an external push
button connected to a suitable I/O pin of the discovery board. The external push button must trigger an interrupt
which causes your program to toggle between running/inactive states.

Embedded Systems Design Part A Sem 1 (2020 -2021) 8


ESD 2020-2021 Smart meter

Embedded Systems Design Part A Sem 1(2020-2021) 9


ESD 2020-2021 Smart meter
Main Assignment - Development of an Electrical Smart Meter

Individual assignment with 90 % weighting (Section A only)

Objective - To develop an electrical smart meter which measures and logs power usage using a suitable
microcontroller development system.

The Basic System

The instantaneous power being consumed is converted through the smart meters front end sensor electronics into an
analogue signal voltage which linearly corresponds to a measured power value of 0 to 25kW. To simulate the sensor
output a potentiometer which produces an adjustable analogue voltage on the development board (or external board)
should be used and connected to the appropriate analogue input channel of the microcontroller.

Your program should read the ADC at 1 second time intervals and convert the digital value into the equivalent power
level using the information provided by the lecturer. The measured power level should be continuously displayed on
an appropriate indicator/display Serial Debug Window, LED's or LCD etc.

Note the output voltage from the potentiometer must not exceed the maximum input voltage of the ADC!
The analogue input signal should be connected to an appropriate analogue input channel of the microcontroller.
Digital (and all other) signals should also be limited to appropriate levels as to not damage the microcontroller, read
the datasheet of the microcontroller to obtain these specifications.

Producing a basic functional and well-structured program as described above with suitable documentation would
attract a mark within the 40-50% region. The marking criteria will be based on - method of implementation, code
structure and elegance, comments and documentation and your ability to explain your code at the time of
demonstration.

Additional Features (guidance only)

1. Add a max/minimum feature to your system and display the values on a suitable indicator. The values should
be reset by pressing a push button on the development board or external board.
2. Add an alarm for high usage. If the power level stays above 8.5kW for more than 10 seconds the LED's should
flash, warning of high power usage.
3. Use the buzzer/speaker connected to a suitable output to emit beeps/tones representing the alarm signal.
4. Calculate the running cost of the electricity used; you should assume that the cost is 13p per kW minute (note
minutes not hours are used to allow reasonable timescales when testing)
5. Store the sampled data into an array for analysis at a later time. The user should be able to access the stored
data by holding down a push button for more than 3 seconds. The data should then be output on the UART for
download to a PC.
6. If the data is stored in an array located RAM memory (default option when arrays are created) the logged data
will be lost when power is removed from the chip. Store the data in non volatile memory such as the internal
flash or an external EEPROM connected to the microcontroller using the I2C or SPI bus. (Ask the lecturer for
more information on the external peripherals which may be accessed through the I2C or SPI bus)
7. Add user configurable parameters such as setting the cost per minute or changing the high power warning
levels. These could be set using, HyperTerminal and the serial UART.
8. Use the Real Time Clock (RTC to timestamp the logged data)

9. Use an external LCD display to show the measured and calculated parameters
10. Add your own innovative features!

Notes : The measurement of elapsed time must make use of one of the hardware timers of the microcontroller and
must use the timer to generate periodic interrupts. By counting the interrupts the passing of time can be measured. For

Embedded Systems Design Part A Sem 1(2020-2021) 10


ESD 2020-2021 Smart meter
example if a timer was initialised to generate an interrupt every 100ms and at every interrupt a variable was
incremented, then when the variable reached 10 this would indicated that one second had passed.

Useful Information.

In order to develop a working prototype and to evaluate the possibilities the following are available:-

Microcontroller development board with various I/O devices such as LCD, LED’s, Push Buttons, potentiometer,
Buzzer etc.
Microchip I2C and SPI evaluation boards with a range of peripherals.
+ Any other suitable devices and peripherals which enhance your design.
The Keil MDK ARM compiler
The uVision Development environment and simulator
Other C libraries available are:- functions to read the ADC channels, output to the DAC, Serial I/O etc.

Assessment method

1. You must attend laboratory sessions in order that your progress can be monitored at each stage of the design. Attendance
will be monitored!
2. You will be asked to show program design and program code and where possible demonstrate partial solutions.
3. Your design should be documented and any ‘C’ code you write should be well structured and conform to a standard
layout with appropriate use of comments.
4. Note: if you do not attend laboratories and suddenly turn up at the end with a working program you will not be credited
with the work. The various stages of development must be monitored.
5. All students must submit a report and program listing with their name and student ID on both!
6. The Report - Produce a short report (typically about four sides of A4) containing an outline of the hardware components
and configuration of your system, the software design and a brief description of the operation of the smart meter. The
complete ‘C’ listing of your program should be added to the report as an appendix (exclude any software routines
provided by the lecturer).
The report must clearly show how the values for your timing have been derived. This should indicate the timer used, the
prescaler value and the timer period. The report should briefly discuss the use of interrupts in your program; the interrupt
vector used by your timer and the priority level.
7. Demonstration – The submitted program(s) must be demonstrated to the lecturer. During the demonstration you will be
questioned about the operation of your implementation. Demonstrations will typically be during the laboratory session of
the final week of semester 1. No demonstration…No marks!

Embedded Systems Design Part A Sem 1(2020-2021) 11


ESD 2020-2021 Smart meter

Student name:   Submission Date and Time  


Student number:   Marker:  
Overall Mark:

Mark
Criterion: Weighting: 1st (100 to 70%) 2.1 (69 to 60%) 2.2 (59 to 50%) 3rd (49 to 40%) Fail (39 to 0%)
:
Able to discriminate, select Use of software tools Use software tools Able to use a Unable to use the basic
Use of software
and use more advanced including advanced including some limited subset of subset of the software
development and 10%
development tools. tool features advanced tool the software tools. tools.
debugging tools
features  
    H M L H M L H M L H M L H M L  
Competent use of C Competent use of C Competent use of C Satisfactory use of Unable to use standard C
Report:
language in embedded language in embedded language in C language in language appropriately.
Program design 10%
systems and use of systems and use of embedded systems. embedded systems
and structure
compiler features compiler features  
    H M L H M L H M L H M L H M L  
Report: Professional Detailed Appropriate Adequate Little or no useful user
Program layout documentation and documentation and documentation and documentation and documentation and poor
10%
and format/layout of program. format/layout of format/layout of format/layout of program format/layout.
documentation program. program. program.  
    H M L H M L H M L H M L H M L  
Innovative use of polling Competent use of Use of polling Use of appropriate Little or no competence at
Report:
and interrupt driven polling and interrupts techniques with techniques for I/O using simple polling
Input & output
10% programming techniques. for I/O interfacing some use of interfacing techniques for I/O
programming
interrupts for I/O interfacing
methodologies.
interfacing
H M L H M L H M L H M L H M L
Program performs all Program performs all Program performs Program performs Little or no evidence of a
Working state system requirements and system requirements. most of the system minimum system working system.
and innovative 60% system extended in an requirements requirements.
features. appropriate and innovative
direction.  
    H M L H M L H M L H M L H M L  

Embedded Systems Design Part A Sem 1(2020-2021) 12


ESD 2020-2021 Smart meter

Working state and innovative features.

Basic System (40 - 50 %) - Basic sensors are simulated, ADC and basic digital IO are used to measure parameters, processing and scaling of the data is completed.
Information is displayed on a suitable indicator

Additional Features (guidance only)

1. Add a max/minimum feature to your system and display the values on a suitable indicator. The values should be reset by pressing a push button on the development
board or external board.
2. Add an alarm for high usage. If the power level stays above 8.5kW for more than 10 seconds the LED's should flash, warning of high power usage.
3. Use the buzzer/speaker connected to a suitable output to emit beeps/tones representing the alarm signal.
4. Calculate the running cost of the electricity used; you should assume that the cost is 13p per kW minute (note minutes not hours are used to allow reasonable
timescales when testing)
5. Store the sampled data into an array for analysis at a later time. The user should be able to access the stored data by holding down a push button for more than 3
seconds. The data should then be output on the UART for download to a PC.
6. If the data is stored in an array located RAM memory (default option when arrays are created) the logged data will be lost when power is removed from the chip.
Store the data in non volatile memory such as the internal flash or an external EEPROM connected to the microcontroller using the I2C or SPI bus. (Ask the lecturer
for more information on the external peripherals which may be accessed through the I2C or SPI bus)
7. Add user configurable parameters such as setting the cost per minute or changing the high power warning levels. These could be set using, HyperTerminal and the
serial UART.
8. Use the Real Time Clock (RTC to timestamp the logged data)
9. Use an external LCD display to show the measured and calculated parameters
10. Add your own innovative features

Embedded Systems Design Part A Sem 1(2020-2021) 13


ESD 2020-2021 Smart meter

Embedded Systems Design Part A Sem 1(2020-2021) 14

S-ar putea să vă placă și