Hello, if you have any need, please feel free to consult us, this is my wechat: wx91due
CSSE2010 / CSSE7201 Assignment 2
Objective
- C programming
- C programming for the AVR
You are required to modify a program in order to implement additional features. The program is a basic template of an Elevator Emulator (a description is given on page 3).
The AVR ATmega324A microcontroller runs the program and receives input from a number of sources and outputs a display to an LED display board, with additional information being outputto a serial terminal and – to be implemented as part of this assignment – a seven segment display and other LEDs.
The version of the Elevator Emulator supplied to you has basic functionality only – it will present a start screen upon launch, respond to button presses or a terminal input ‘s’ to start, then display the emulator. A list of features and their implementation details are provided in “Program Features”. The different features have different levels of difficulty and will be worth different numbers of marks.
Don’t Panic!
Academic Merit, Plagiarism, Collusion and Other Misconduct
Grading Note
Program Description
- Elevator-Emulator.c – this is the main file that contains the event loop and examples of how time-based events are implemented. Here also, you will find the implementation of the elevator and the floors, as well as code that handles the movement of the elevator. You should read and understand this file.
- display.h/display.c – this file contains the implementation for displaying the current state of the board. This file contains useful functions for changing the state of the LED matrix.
- buttons.h/buttons.c – this contains the code which deals with the IO board push buttons. It sets up pin change interrupts on those pins and records rising edges (buttons being pushed).
- ledmatrix.h/ledmatrix.c – this contains functions which give easier access to the services provided by the LED matrix. It makes use of the SPI routines implemented in spi.c.
- pixel-colour.h – this file contains definitions of some useful colours.
- serialio.h/serialio.c – this file is responsible for handling serial input and output using interrupts. It also maps the C standard IO routines (e.g. printf() and fgetc()) to use the serial interface so you are able to use printf() etc for debugging purposes if you wish. You must include serialio.h in the relevant file for the functions to work. You should not need to look in serialio.c, but you may be interested in how it works and the buffer sizes used for input and output (and what happens when the buffers fill up).
- spi.h/spi.c – this file encapsulates all SPI communication that is used to communicate with the LED Matrix.
- terminalio.h/terminalio.c – this encapsulates the sending of various escape sequences which enable some control over terminal appearance and text placement – you can callthese functions (declared in terminalio.h) instead of remembering various escape sequences. Additional information about terminal IO will be provided on the course Blackboard site.
- timer0.h/timer0.c – sets up a timer that is used to generate an interrupt every millisecond and update a global time value.
Elevator Emulator Description
Figure 1: Initial layout of elevator emulator (note that pixel positions are referenced from the bottom left)
Travellers appear on each floor and the elevator moves to their floor, picks them up and takes them to their destination floor. The elevator moves up and down and, for the sake of algorithmic simplicity, is only capable of moving one traveller at a time. Each traveller can be one of four colours, with each different colour corresponding to a different destination floor.
In the following example (Figure 2) a light red passenger appears on floor 1. Light red indicates the traveller’s destination is floor 0. The elevator moves to their floor, picks them up and then moves down to the destination. Note that there is a fixed amount of time (defined in code) between each of the frames shown.
Figure 2: Example, moving a traveller from floor 1 to floor 0
Initial Operation
Wiring Advice
Program Features
You may modify any of the code provided and use any of the code provided by course material, e.g. Blackboard, Ed Lessons, Learning Labs, etc. For some of the easier features, the description below tells you which code to modify or there may be comments in the code which help you.
Getting Started
Start Screen (Level 1 – 4 marks)
|
Hint: Printing to the putty terminal is handled with either printf(“”); or printf_P(PSTR(“”));, look for these lines on the code to change what is being sent to the terminal. (Note, the difference between these two commands is where the string is stored in memory. Normally strings are stored in SRAM, PSTR() stores the string in program memory which is important for systems (like the Atmega) which have a limited amount of SRAM). |
Set Destination with Buttons (Level 1 – 8 marks)
|
Hint:
When B0 and B1 are pressed an internal variable, called destination is changed. The loop in the
tart_elevator_controller() function then handles moving the elevator at a constant rate to the desired location.
The code for setting the destination of the elevator is in handle_inputs(). Have a look at the comments there to get you started. |
Set Destination with Terminal Input (Level 1 – 8 marks)
|
Hint:
On the start screen, the emulator can be started by pressing ‘s’ or ‘S’, looking at the function start_screen() should give you an idea of how to read serial input from the terminal.
Also be careful when writing your code. ‘1’ is not the sameas the integer 1, in this case it is a character. |
Terminal Display #1 (Level 1 – 6 marks)
Traveller Placements (Level 1 – 8 marks)
Figure 3: Example of traveller on FLOOR_2
Moving Travellers #1 (Level 1 – 8 marks)
Currently, you do not need to worry about the behaviour of the elevator when placing a traveller on the ground floor. See “Moving Travellers #2” for further details.
It is worth noting here that this functionality is different to a ‘real-life’ elevator. For the sake of simplicity of this assignment, the elevator emulator here is not capable of carrying multiple passengers. Only one traveller is moved at a time.
The speed of the elevator should be controllable with switch S2. If S2 is 0, a slow speed is enabled. If S2 is 1, the speed of the elevator is increased. It is up to you to choose suitable fast and slow speeds. Both speeds should be reasonable, but distinguishable. Approximately 100-300 ms between each time the elevator moves one LEDs distance would be considered reasonable. The provided functionality has a delay of 200 ms each time the elevator moves one LEDs length.
SSD Direction Indicator (Level 1 – 6 marks)
Figure 4: SSD Diagram (https://theorycircuit.com/arduino-projects/7-segment-arduino-interface/)
Move Travellers #2 (Level 2 – 8 marks)
Use the following colours to indicate where a traveller is going: (colour definitions in pixel_colour.h)
- Travelling to FLOOR_0 à COLOUR_LIGHT_RED
- Travelling to FLOOR_1 à COLOUR_LIGHT_GREEN
- Travelling to FLOOR_2 à COLOUR_LIGHT_YELLOW
- Travelling to FLOOR_3 à COLOUR_LIGHT_ORANGE
The elevator will go to the floor of the traveller and pick them up. Modify your code such that the elevator then goes to the correct destination floor associated with their colour. I.e. we are no longer taking all the travellers to the ground floor. Note that when the elevator is finished moving the traveller, it stays where it is until another traveller is ready to be moved.
At this stage, you must also add logic to your code that stops the user from placing a traveller on a floor which is also their destination floor. For example, if a traveller is placed on floor 3 and their destination is also floor 3 (their colour would be light yellow), your code should detect this and ignore that traveller (they should not be shown on the screen, and when “Queue Travellers” is implemented, they should not be added to the queue).
SSD Current Floor (Level 2 – 8 marks)
|
Hint:
SSD multiplexing using the CC pin was covered in the Labs. You are encouraged to revisit the content from these labs to help you for this feature.
|
Terminal Display #2 (Level 2 – 4 marks)
Sound Effects (Level 2 – 8 marks)
- A 3 kHz tone that plays for 50 ms every time a traveller is placed on a floor.
- A 500 Hz tone that plays for 100 ms every time a traveller is picked up or dropped off by the elevator.
Note, it is not expected that the tones be the exact frequency or duration defined here. A small amount of error in the frequency or duration is acceptable. We do not expect you to measure the output of your piezo to ensure it is the exact correct frequency or duration. If you want to verify the frequency of your buzzer, use this link (https://www.szynalski.com/tone-generator/) to hear what a square wave of that frequency sounds like.
It is possible that two sounds overlap (e.g. a traveller is picked up <50ms after it is placed by a button). How you handle this is up to you and will not be tested during marking. You may choose to override the tone that is currently playing or not play a tone at all if one is already playing.
|
Hint:
It will be difficult to implement these sounds without the use of a timer. It is recommended that to produce the desired frequencies, you refer to the Labs where PWM was covered. |
IOBoard LED Door Animation (Level 3 – 6 marks)
Figure 5: LED animation, lasting a total of 600ms
Traveller Queue (Level 3 – 6 marks)
It is worth noting once again that this elevator does not work the same way as a ‘real-life’ elevator. This elevator is not meant to be the most efficient, even though sometimes it would make more sense to not move travellers in the order in which they appear. For the sake of algorithmic simplicity, in this emulator however, the elevator will move one traveller at a time, in the order that they appear.
Table 1: Example of a queue (order of button presses from left to right)
|
B0 Pressed |
B1 Pressed |
B0 Pressed |
B3 Pressed |
B1 Pressed |
B2 Pressed |
||||||
|
S0: 1 |
S1: 1
|
S0: 1
|
S1: 1
|
S0: 0
|
S1: 1
|
S0: 0
|
S1: 1
|
S0: 1
|
S1: 0
|
S0: 0
|
S1: 0 |
|
Traveller added
From: FLOOR_0
To: FLOOR_3
|
Traveller added
From: FLOOR_1
To: FLOOR_3
|
Traveller added
From: FLOOR_0
To: FLOOR_1
|
Traveller added
From: FLOOR_3
To: FLOOR_1
|
Traveller added
From: FLOOR_1
To: FLOOR_2
|
Traveller added
From: FLOOR_2
To: FLOOR_0
|
||||||
Joystick – Service Mode (Level 3 – 6 marks)
The elevator should not move above the top position or below the bottom position even when the joystick is pushing it beyond its limits.
Be aware that different joysticks may have different min/max/resting output voltages and you should allow for this in your implementation – your code will be marked with a different joystick to the one you test with. You should also consider that the centre of each joystick is not consistent between joysticks. Consider implementing a “dead space” so that the elevator does not move when the joystick is not being pressed.
Assessment of Program Improvements
Features are shown grouped in their levels of approximate difficulty (level 1, level 2, and level 3).
Submission Details
- All of the C source files (.c and .h) necessary to build the assignment (including any that were provided to you – even if you haven’t changed them); and
- A PDF feature summary form (see below).
Do not submit .rar or other archive formats – the single file you submit must be a zip format file. All files must be at the top level within the zip file – do not use folders/directories or other zip/rar files inside the zip file.
If you make more than one submission, each submission must be complete – the single zip file must contain the feature summary form, the hex file and all source files needed to build your work. We will only mark your last submission and we will consider your submission time (for late penalty purposes) to be the time of submission of your last submission.
The feature summary forms are on the last pages of this document. A separate electronically fillable PDF form will be provided to you also. This form can be used to specify which features you have implemented and how to connect the ATmega324A to peripherals so that your work can be marked. If you have not specified that you have implemented a particular feature, we will not test for it. Furthermore, not including your relevant pin connections for a particular peripheral will incur a deduction of 2 marks per peripheral not specified. Failure to submit the feature summary with your files may mean some of your features are missed during marking (and we will NOT remark your submission). You can electronically complete this form or you can print, complete and scan the form. Whichever method you choose, you must submit a PDF file with your other files.
Incomplete or Invalid Code
If your submission does not compile and/or link in Microchip Studio for other reasons, then themarker will make reasonable attempts to get your code to compile and link by fixing a small number of simple syntax errors and/or commenting out code which does not compile. A penalty of between 10% and 50% of your mark will apply depending on the number of corrections required. If it is not possible for the marker to get your submission to compile and/or link by these methods then you will receive 0 for the assignment (and will have to resubmit if you wish to have a chance of passing the course). A minimum 10% penalty will apply, even if only one character needs to be fixed.
Compilation Warnings
Your code must compile and run using the default Microchip Studio and PuTTY setup on the lab computers. It is your responsibility to ensure that your code works as such. Programs such as PlatformIO and other serial terminal tools may behave differently to the software required in this course. Similarly, your serial connection must work through the IO Board, and not through the Pololu programmer, or other serial to USB devices.