ECE3223 Assignment 1 to 6 solutions

$120.00

Original Work ?

Download Details:

  • Name: Assignments-yhz1iz.zip
  • Type: zip
  • Size: 9.29 MB

Category: You will Instantly receive a download link upon Payment||Click Original Work Button for Custom work

Description

5/5 - (1 vote)

ECE3223 Assignment 1 – Working with LEDs and switches

Connect your mbed to the LEDs, switches, and resistors as shown in the schematic below:
Note that there are both active-high as well as active-low switches and LEDs. This will give you
practice with all of the cases.
Initially, the 4 blue LEDs built into the mbed itself should be off. Each time Switch 2 is pressed,
one of the blue LEDs that is off should be turned on. Each time Switch 1 is pressed, one of the
blue LEDs that is on should be turned off. In either case, if there are no blue LEDs in the
appropriate state (off for Switch 2 or on for Switch 1) then nothing should change.
The red LED should be on if and only if all of the blue LEDs are off. The green LED should be
on if and only if all of the blue LEDs are on.
You may assume that no more than one switch is pressed at a time. The program should be
usable on a human time scale (either look for a press/release cycle, or ensure that if a switch is
held down it does not repeat the associated action faster than once per 500 ms). Be sure to
compensate for spurious edges due to switch bounce. The program should be written to use the
DigitalIn and DigitalOut classes from mbed OS 2 (state with the “Blinky LED Hello World”
template).
Upload your final “main.cpp” file to the Assignment 1 dropbox on Canvas by the end of
February 16th. Do not upload the bin file that you have saved to the mbed. Instead, use the
export option which will allow you to download main.cpp from the mbed web site to your
computer so that you can then upload it the Canvas. See “How to export main.cpp from the mbed
web site” on Canvas for details.
VOUT
p21
p22
220 Ω
green
LED
220 Ω
red
LED
p20
p19
GND
switch 1 switch 2
mbed

ECE3223 Assignment #2 – Toy Emergency Vehicle Effects Generator

In this assignment you will use the DigitalIn and PwmOut interfaces on the mbed
microcontroller board to implement sound effects and blinking LEDs for a toy emergency
vehicle.
Connect two pushbutton switches, one between the mbed’s p20 and VOUT and another between
p19 and GND. Connect a red LED in series with a 220 ohm resistor between the mbed’s p23
and VOUT (the LED’s anode should be oriented towards VOUT). Connect the piezo transducer (it
looks like a small black cylinder with a hole at the top to emit sound) between the mbed’s p24
and GND.
The mbed should start in an idle mode in which all of the LEDs are off and the piezo transducer
is silent. If either switch is pressed, the mbed begins one of two different effects, one effect for
each switch. When no effects are active, the mbed should return to the idle mode.
If the switch connected to p20 is pressed, the mbed should generate a two tone siren effect and
repeat the effect until the switch is released. During this effect the piezo transducer should
generate a 960 Hz tone for 0.7 seconds followed by a 1140 Hz tone for 0.7 seconds. Synchronized
with this sound effect, the red LED and the built-in blue LED1 should alternately flashing
on and off. When the piezo is generating 1140 Hz, the red LED should be off and the blue LED
on. When the piezo is generating 960 Hz, the red LED should be on and the blue LED off.
If the switch connected to p19 is pressed, the mbed should generate a warbling siren effect and
repeat the effect until the switch is released. During this effect the piezo transducer should
generate ascending frequencies from 800 Hz to 1200 Hz over the span of 0.4 seconds and then
descending frequencies from 1200 Hz to 800 Hz, also over the span of 0.4 seconds.
Synchronized with this sound effect, red LED should smoothly transition from fully off when the
piezo is generating 800 Hz, to fully on when the piezo is generating 1200 Hz. For both the
piezo and the LED, the changes in frequency and brightness should occur in small enough steps
that it appears to a human to be a continuous transition rather than discrete steps.
To simplify the programming, you need only check for a switch release once per cycle of each
effect rather than continuously. You may also assume that only one switch will be pressed at a
time.
Submit your “main.cpp” to the appropriate dropbox on Canvas by the end of Februrary 25th.

ECE3223 Assignment #3 – Temperature Monitor

In this assignment, you will use the InterruptIn, AnalogIn, and BusOut interfaces on the mbed
microcontroller board to implement a simple temperature monitor.
The MCP9701 is the temperature sensor; its pinout is shown to the right. Connect the
MCP9701’s +Vs pin to the mbed’s VOUT pin, its Vout pin to the mbed’s p18 pin, and
its GND pin to the mbed’s GND pin. Do not confuse the MCP9701’s Vout pin with the
mbed’s VOUT pin. The voltage on the MCP9701’s Vout pin is related to the
temperature by the following equation (V in volts and T in degrees Celsius):
V = 0.400 + 0.0195T
Connect a pushbutton switch between the mbed’s GND and p15. Connect a second pushbutton switch
between the mbed’s VOUT and p26. Connect the 7-segment LED display to the mbed as shown in
Figure 3.10 (1st ed.) or Figure 3.12 (2nd ed.) in the textbook, but insert 220 ohm resistors in series with
each LED segment to reduce the current drawn.
Write a program for the mbed that will periodically read and display the current temperature from the
MCP9701, either in Celsius or Fahrenheit depending on the selected mode. Your program should use
the mean average voltage from the temperature sensor (computed over at least 1000 samples) so that
the displayed value does not fluctuate due to noise when the temperature is stable.
The temperatures should be displayed to the nearest degree of whichever unit was last selected. Since
the display can only display one digit, you must display the temperature one digit at a time. Display
each digit for 0.5 – 1 seconds, then blank the display for 0.1 seconds (this way the user can distinguish
a digit shown once from two digits with the same value shown consecutively). After displaying the
temperature, the program should display either a “C” if the temperature was in Celsius or an “F” if the
temperature was in Fahrenheit. Note that the temperature might be less than 0, in which case you will
need to display the leading negative sign (if you want to test this without a freezer, disconnect p18 from
the MCP9701 and connect p18 instead to the mbed’s GND; this simulates a temperature of around
−20.5 C or -4.9 F).
The two switches select the temperature mode. Pressing the switch connected to p26 should select
Celsius mode. Pressing the switch connected to p15 selects Fahrenheit mode. Use InterruptIn to trigger
interrupts when these switches are pressed so that the mode can be changed at any time. Although the
mode can change at any time, be sure to completely display the temperature in consistent units (for
example, don’t display the first digit from the Celsius temperature followed by the second digit from
the Fahrenheit temperature). When your program starts, it can default to whichever mode you prefer.
Hints: For debugging purposes, it might be useful to use the Serial object to display intermediate results
on your computer, although this is not a requirement for the assignment. Sections 6.2 and 6.4 of the
textbook may also be useful. Also, since the voltages being measured from the temperature sensor are
very small, even slight resistive voltage drops can skew the results; you should minimize this effect by
sampling the temperature only when the LED display is blank.
Submit your “main.cpp” to the appropriate dropbox on Canvas by the end of March 11th.

ECE3223 Assignment #4 – SPI reaction time game

In this assignment, you will use the DigitalOut, SPI, and Timer objects on the mbed microcontroller
board to implement a simple game that challenges your reaction time.
Build the circuit shown below:
In this circuit, the mbed operates as an SPI controller and the 74HC595 and 74HC165 chips operate
as SPI peripheral devices. The 74HC595 uses SPI mode 0 and an active low chip select on p14. The
74HC165 uses SPI mode 2 and an active high chip select on p15.
The 74HC595 expects an 8-bit message from the SPI controller and uses this message to control
the 7-segment display. Bit 7 of the message controls segment A of the display, bit 6 of the message
controls segment B of the display, and so on. Bit 0 of the message controls the decimal point on
the display. The 74HC595 does not send any data to the SPI controller. If more than 8 bits are
transferred, only the last 8 bits will be used. The display is only updated at the end of the
message.
The 74HC165 sends an 8-bit message to the SPI controller, reporting the state of the 4 switches.
Bit 0 reports the state of switch A, bit 1 reports the state of switch B, and so on. If more than 8
bits are transferred, all of the remaining bits will be 0. The 74HC165 ignores any data sent by the
SPI controller.
The game itself consists of an indefinite number of rounds, with each round slightly more
difficult than the last, with the challenge to the human player to last as many rounds as possible
before eventually making a mistake. For each round, the mbed should randomly select a letter A,
B, C, or D and display this letter on the 7-segment display. After the letter is displayed, the
human has a limited amount of time to press the switch corresponding to this letter. If an
incorrect switch was pressed, or the no switch was pressed withing the time limit, the game is
over and the 7-segment display should show “L” for lose. If the correct switch was pressed, a
new round should begin with a shorter time limit.
When the game starts, the time limit is 1 second. For each subsequent round, the time limit
should be 80% of the previous time limit.
The C function rand() will return a pseudo-random integer. It actually returns the next number in
a very long sequence, so it’s actually only random in that it’s hard for a human to predict.
However, the mbed always starts in a well-defined state, so you will always see the same
sequence every time you start your program if you don’t do anything else. If you want to
increase the randomness, you can start a timer at the beginning of the game and use the elapsed
time at the start of the current round to “seed” the random number generator using the srand()
function like this: srand(timer.read_us()). Note that this just moves the random number generator
to a new point in the sequence; you still use the rand() function to get the random numbers.
Submit your “main.cpp” to the appropriate dropbox on Canvas by the end of April 8th.

ECE3223 Assignment #5 – Lighting System with I2C Memory

Construct the circuit shown below:
Your program should allow the user to adjust the brightness of LED1 and LED2 using the four
switches. Pressing “L1up” should increase the brightness of LED1, pressing “L1down” should decrease
the brightness of LED1. Likewise, pressing “L2up” should increase the brightness of LED2, pressing
“L2down” should decrease the brightness of LED2. The brightness of the LEDs should be adjusted by
changing the duty cycle of the LEDs from 0% to 100% in steps of 20% per press.
The I2C EEPROM (24LC01 or 24AA01) should be used to store the selected brightness level of both
LEDs so that the last selected brightness will always be restored as the initial default whenever the
program starts. If the contents of the EEPROM are not valid (for example, the EEPROM is blank or has
been somehow corrupted), both LEDs should default to 100% brightness. Note that although the
EEPROM can be rewritten over 1 million times, this can been exceeded if constantly written to for a
few hours; to avoid premature failure, only update the EEPROM when the brightness level is changed.
Submit your “main.cpp” to the appropriate dropbox on Canvas by the end of April 22nd.
VOUT
p23
p24
p10
p9
GND
L1up
mbed
L1down
p21
p22
L2up
L2down
SDA
SCL
WP
VCC
VSS
A0
A1
A2
24×01
2.2 k
2.2 k
1
2
3
4 5
6
7
8

ECE3223 Assignment 6 – Virtual Tug-o-War Game using Direct Register Access

Connect the pushbutton switches and
LEDs to the mbed module as shown in
the schematic to the right.
The player for the red team will use the
switch connected to p14 and the player
for the green team will use the switch
connected to p27. Each player will
attempt to continuously press and release
their switch as fast as possible. The
virtual rope begins the game centered on
the playfield. Whenever a player’s switch changes state (from off to on or on to off) the
virtual rope should move one unit closer to that player’s side of the playfield. If the virtual
rope has been pulled close enough to the end of the playfield, the player on that end of
the playfield wins.
The virtual rope position can be in one of 7 positions as indicated by the external and
built-in LEDs (the LEDs that are on are indicated with the starbursts):
Red team has won
Rope position at the start of the game
Green team has won
Once the virtual rope has reached one of the two winning positions, the game is over and
the program should stop (go into an infinite loop). If the players want to start a new
game, they should press the mbed’s reset button.
Write the program to implement this game using direct access to the microcontroller’s I/O
registers instead of using the mbed’s library (no #include “mbed.h”, DigitalIn, DigitalOut,
BusOut, InterruptIn, etc.). For simplicity, ignore the potential problem of switch bounce.
Submit your “main.cpp” to the appropriate dropbox on Canvas by the end of May 3rd.

p23
p24
p27
p17
p16
p14
GND Vout
Red 220 220 Green
mbed