Documente Academic
Documente Profesional
Documente Cultură
Fall 2015
Homework 12
Due Tuesday, 11/24 at 11:59pm
Section: _______
Name: ________________________________
Reading
Practical Electronics for Inventors Chapter 12, 12.9 12.9.2: Three-State Buffers & Lathes
Practical Electronics for Inventors Chapter 12, 12.1 12.2: Simple logic interfacing
Practical Electronics for Inventors Chapter 12, 12.10.5 12.10.6: DACs & ADCs
Practical Electronics for Inventors Chapter 16, 16.1 16.5: Audio Electronics
Read the Arduino reference on the delay() function paying attention to the Caveat
http://playground.arduino.cc/Code/AvoidDelay
Always list collaborators and cite external references used in compliance with the course Collaboration
and Academic Integrity Policy
ES52
Homework 12
Fall 2015
(22 points)
You are desiging a digital combination lock using a Finite State Machine (FSM). The hardware block
diagram looks like this:
The lock has two input buttons LEFT and RIGHT and two outputs which go high to light two indicator
LEDs. One LED indicates when the lock is ready for input, the other indicates when the lock is UNLOCKED.
The lock itself is a FSM consisting of flip-flops and the appropriate combinatorial logic to create the
next state and the output signal from the present state and the inputs. The FSM is clocked by a 4Hz
clock generator. The pushbuttons are normally open and short the contacts when pressed. You may
assume the pushbuttons have no mechanical bounce.
To use the lock:
Any time neither button is pressed the lock should be ready to accept a combination.
When ready to accept a combination, the READY LED should be on.
To unlock the lock, enter the combination by pressing the buttons as follows:
o Press both the LEFT and RIGHT button simultaneously to start combination entry
o Release the RIGHT button while continuing to hold the LEFT button down
o Press the RIGHT button again so both buttons are down
o Release the LEFT button while continuing to hold the RIGHT button down
o Press the LEFT button again so both buttons are down
o The lock is now unlocked1
When the lock is unlocked, the UNLOCKED LED should be lit. The lock should stay UNLOCKED as
long as both buttons are pressed. If either or both buttons are released, the lock should return
to READY.
While the combination is being entered the READY LED should be off
If you enter a wrong sequence the lock should return to the ready state
After a reset, the lock should be ready to accept a combination.
Ok, so its not the most secure combination in the world. Our problem is that if we make it more secure your
problem becomes much harder. So, be careful what you wish for.
Rev B
2 of 9
ES52
Homework 12
Fall 2015
Hint: Be careful. It is likely that several FSM clock cycles will occur for each button entry in the
combination. Do not assume that there is only one FSM clock per combination sequence.
a) (12 points) You plan to implement the lock using a hardware Finite State Machine (FSM). Draw
a directed graph for this hardware. Be sure and show the inputs and outputs to your state
diagram and label each state to describe its function. Mark your reset state.
b) (8 points) Draw the Present State/Next State table for the Combination Lock FSM. Include
columns for the output signals. Indicate the reset state.
c) (2 points) How many flip-flops will you need to implement your Finite State Machine?
Rev B
3 of 9
ES52
Homework 12
Fall 2015
(12 points)
Each of the following code examples have at least one show-stopping bug.
The bugs may be syntax errors or functional errors in the code. Assume that all
functions that aren't explicitly shown work as described. For each example, find and discuss
the bug. Hint: pay attention to the number of points for each question.
a) (5 points)
//
//
//
//
Rev B
4 of 9
ES52
Homework 12
Fall 2015
b) (3 points)
// This program checks to see if another day
// has elapsed since it was first started and
// prints a motivational message it if has.
const int milliseconds_in_a_day = 1000*60*60*24;
int time_last_printed = 0;
void setup (){
Serial.begin (9600);
}
void loop (){
if( millis () > (time_last_printed + milliseconds_in_a_day)){
Serial.println ("Today is the first day of the rest of your
life...");
}
time_last_printed = millis();
}
Rev B
5 of 9
ES52
Homework 12
Fall 2015
c) (4 points)
Rev B
6 of 9
ES52
Homework 12
Fall 2015
(20 points)
Your significant other is a crazy cat lady/man. S/he has nine cats that wander in and out
of the house all the time. S/he is very excited that you are taking ES52 because now you
can build a device that keeps track of how many cats are outside at any given time.
Your house has two cat doors, one that only opens inward and one that only opens out.
Each cat door has an electronic switch that shorts to ground when the door opens.2
When a cat goes through one of the doors, the normally open (n.o.) switch closes for
about 50mSec. (You may assume there is no bounce on the switch; i.e., there is only
one transition from closed to open and back to closed again when a cat goes out the
door.)
You design an Arduino Pro Micro powered cat counter which will allow the door
switches to interrupt the Arduino.3 The circuit can display a single value between 0 to
9 on a Numitron seven-segment display to indicate how many cats are currently
outside. When you reset the cat counter the display shows 0, so you always reset it
when you are sure that all the cats are in the house. Here is the completed schematic
for the cat counter:
Lucky for you none of the other cats in the neighborhood like the brand of cat food your S.O. serves so the only
cats that go in and out of the cat doors are hers/his.
3
The Arduino Pro Micro is essentially the same as the Arduino Micro except is has somewhat fewer I/O pins
available. Since you use so few I/O pins in this circuit, the differences are unimportant. The Pro Micro does require
and external reset switch, which you have included in your design.
Rev B
7 of 9
ES52
Rev B
Homework 12
Fall 2015
8 of 9
ES52
Homework 12
Fall 2015
As a reminder, here are the pins on the Arduino Pro Micro that can be used to interrupt the
microcontroller:
Arduino Interrupt #
0
1
2
3
4
Notes
Asynchronous on Edge Trigger4
Asynchronous on Edge Trigger
Asynchronous on Edge Trigger
Asynchronous on Edge Trigger
Synchronous
(a) (20 points) Attached is skeleton Arduino code for you to complete to create your interrupt
driven cat counter. You will need to complete the function to display a number from 0 to 9
on the Numitron:
void updateDisplay(int digit_to_display)
Asynchronous interrupts can wake the uController from sleep modes other than Idle mode.
You may download the skeleton code from Canvas if you prefer but please make it easy for us to tell what you
have changed/added.
5
Rev B
9 of 9
/*************************************
Partially Complete Cat Counter Code
Skeleton for Homework 12 Question 2
int
int
int
int
SSD_A
SSD_B
SSD_C
SSD_D
=
=
=
=
2;
3;
4;
5;
void setup() {
-1-
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
**************************************************
void updateDisplay(int digit_to_display)
Function to display a digit between "0" and "9"
on the Numitron.
Arguments: digit_to_display = 0 to 9
The 74HC247 is connected to the uController as
follows:
D2 -> A ('LS247 bit 0 input)
D3 -> B ('LS247 bit 1 input)
D4 -> C ('LS247 bit 2 input
D5 -> D ('LS247 bit 3 input)
You may assume that you can update the 74LS247
inputs quickly enough that the Numitron will
not display intermediate values.
**************************************************
}
//
//
//
//
//
//
//
****************************************************
The following two Interrupt Service routines are
called when a cat leaves and enters the house
respectively. They should do the minimum necessary
to let the foreground FSM know that a cat has
exited or entered.
****************************************************
void catOutISR() {
}
-2-
void catInISR() {
void loop()
{
-3-