0% found this document useful (0 votes)
96 views

Demo!: Goal

The document describes the design and implementation of an electronic combination lock using an FPGA. It involves: 1. Creating a state transition diagram for the lock finite state machine with 6 states representing the combination "01011". 2. Writing Verilog modules to implement the FSM and synchronize button inputs. 3. Using MAX+plusII for synthesis, simulation, and programming the FPGA. 4. Wiring up buttons and a 7-segment display to test the lock functionality.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
96 views

Demo!: Goal

The document describes the design and implementation of an electronic combination lock using an FPGA. It involves: 1. Creating a state transition diagram for the lock finite state machine with 6 states representing the combination "01011". 2. Writing Verilog modules to implement the FSM and synchronize button inputs. 3. Using MAX+plusII for synthesis, simulation, and programming the FPGA. 4. Wiring up buttons and a 7-segment display to test the lock functionality.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

Demo!

GOAL:
Build an electronic combination lock with a reset
button, two number buttons (0 and 1), and an
unlock output. The combination should be 01011.
0
1
RESET

UNLOCK

STEPS:
1.Create state transition diagram for lock FSM
2.Write Verilog module(s) that implement FSM
3.Use MAX+plusII (synthesis, simulation)
4.Program FGPA, wire up buttons, give it a whirl!
6.111 Fall 2004

Lecture 7, Slide 1

Step 1: State transition diagram


RESET
1

1
0

RESET
Unlock = 0

0
Unlock = 0

01
Unlock = 0
0

0
01011
Unlock = 1

0101
Unlock = 0

010
Unlock = 0

6.111 Fall 2004

66 states
states
33 bits
bits

Lecture 7, Slide 2

Step 2: Write Verilog


module lock(clk,reset_in,b0_in,b1_in,out);
input clk,reset,b0_in,b1_in;
output out;
// synchronize push buttons, convert to pulses
// implement state transition diagram
reg [2:0] state;
always @ (posedge clk)
begin
state <= ???;
end
// generate output
assign out = ???;
// debugging?
endmodule

6.111 Fall 2004

Lecture 7, Slide 3

Step 2A: synch buttons


// button -- push button synchronizer and level-to-pulse converter
// OUT goes high for one cycle of CLK whenever IN makes a
// low-to-high transition.
module button(clk,in,out);
out
input clk;
input in;
r1
r2
r3
in
D Q
D Q
D Q
output out;
clk
reg r1,r2,r3;
always @ (posedge clk)
synchronizer
state
begin
r1 <= in;
// first reg in synchronizer
r2 <= r1;
// second reg in synchronizer, output is in sync!
r3 <= r2;
// remembers previous state of button
end
// rising edge = old value is 0, new value is 1
assign out = ~r3 & r2;
endmodule
6.111 Fall 2004

Lecture 7, Slide 4

Step 2B: state transition diagram


// state assignments
parameter S_RESET = 0;
parameter S_0 = 1;
parameter S_01 = 2;
parameter S_010 = 3;
parameter S_0101 = 4;
parameter S_01011 = 5;
// implement state transition diagram
reg [2:0] state;
always @ (posedge clk)
begin
if (reset) state <= S_RESET;
else case (state)
S_RESET: state <= b0 ? S_0
: b1 ? S_RESET : state;
S_0:
state <= b0 ? S_0
: b1 ? S_01
: state;
S_01:
state <= b0 ? S_010 : b1 ? S_RESET : state;
S_010:
state <= b0 ? S_0
: b1 ? S_0101 : state;
S_0101: state <= b0 ? S_010 : b1 ? S_01011 : state;
S_01011: state <= b0 ? S_0
: b1 ? S_RESET : state;
default: state <= S_RESET; // handle unused states
endcase
end
6.111 Fall 2004

Lecture 7, Slide 5

Step 2C: generate output


// its a Moore machine!

Output only depends on current state

assign out = (state == S_01011);

Step 2D: debugging?


// hmmm.

What would be useful to know?

Current state?

led_decoder l(state,segments);

6.111 Fall 2004

Lecture 7, Slide 6

Step 2E: led_decoder


// led_decoder -- decode 4-bit input into 7-segment enables
module led_decoder(in,segments);
input [3:0] in;
output [6:0] segments;
wire a,b,c,d,e,f,g;
// the seven segments
// top segment
assign a = (in==0) || (in==2) || (in==3) || (in==5) || (in==6) || (in==7) || (in==8) ||
(in==9) || (in==10) || (in==14) ||(in==15);
// upper right segment
assign b = (in==0) || (in==1) || (in==2) || (in==3) || (in==4) || (in==7) || (in==8) ||
(in==9) || (in==10) || (in==13);
// lower right segment
assign c = (in==0) || (in==1) || (in==3) || (in==4) || (in==5) || (in==6) || (in==7) ||
(in==8) || (in==9) || (in==10) || (in==11) || (in==13);
// bottom segment
assign d = (in==0) || (in==2) || (in==3) || (in==5) || (in==6) || (in==8) || (in==11) ||
(in==12) || (in==13) || (in==14);
// bottom left segment
assign e = (in==0) || (in==2) || (in==6) || (in==8) || (in==10) || (in==11) || (in==12) ||
(in==13) || (in==14) || (in==15);
// upper left segment
assign f = (in==0) || (in==4) || (in==5) || (in==6) || (in==8) || (in==9) || (in==10) ||
(in==11) || (in==14) || (in==15);
// middle segment
assign g = (in==2) || (in==3) || (in==4) || (in==5) || (in==6) || (in==8) || (in==9) ||
(in==10) || (in==11) || (in==12) || (in==13) || (in==14) || (in==15);
// bundle results into a single 7-bit vector
assign segments = {g,f,e,d,c,b,a};
endmodule
6.111 Fall 2004

Lecture 7, Slide 7

Step 2: final Verilog implementation


module lock(clk,reset_in,b0_in,b1_in,out,segments);
input clk,reset_in,b0_in,b1_in;
output out;
output [6:0] segments;
wire reset,b0,b1;
button b_reset(clk,reset_in,reset);
button b_0(clk,b0_in,b0);
button b_1(clk,b1_in,b1);
// state assignments
parameter S_RESET = 0; parameter S_0 = 1; parameter S_01 = 2;
parameter S_010 = 3; parameter S_0101 = 4; parameter S_01011 = 5;
// implement state transition diagram
reg [2:0] state;
always @ (posedge clk) begin
if (reset) state <= S_RESET;
else case (state)
S_RESET: state <= b0 ? S_0 : b1 ? S_RESET : state;
S_0: state <= b0 ? S_0 : b1 ? S_01 : state;
S_01: state <= b0 ? S_010 : b1 ? S_RESET : state;
S_010: state <= b0 ? S_0 : b1 ? S_0101 : state;
S_0101: state <= b0 ? S_010 : b1 ? S_01011 : state;
S_01011: state <= b0 ? S_0 : b1 ? S_RESET : state;
default: state <= S_RESET; // handle unused states
endcase
end

6.111 Fall 2004

assign out = (state == S_01011);


led_decoder l(state,segments); // debugging!
endmodule

Lecture 7, Slide 8

Step 3A: set top level file

6.111 Fall 2004

Lecture 7, Slide 9

Step 3B: compile/synthesize/map

6.111 Fall 2004

select next error

locate error in source

Lecture 7, Slide 10

Step 3C: start waveform editor

6.111 Fall 2004

Lecture 7, Slide 11

Step 3D: add I/O nodes

6.111 Fall 2004

Lecture 7, Slide 12

Step 3E: set simulation end time

6.111 Fall 2004

Lecture 7, Slide 13

Step 3F: set input values, save

6.111 Fall 2004

Lecture 7, Slide 14

Step 3G: run simulation

6.111 Fall 2004

Lecture 7, Slide 15

Step 3H: examine simulation results

6.111 Fall 2004

Lecture 7, Slide 16

Step 4A: AssignDevice

6.111 Fall 2004

EPF10K10LC84 or EPF10K70RC240

EPC2LC20

Lecture 7, Slide 17

Step 4B: AssignPins

6.111 Fall 2004

Lecture 7, Slide 18

Step 4C: recompile

6.111 Fall 2004

Lecture 7, Slide 19

Step 4D: MAX+plusIIProgrammer


Set up JTAG chain

6.111 Fall 2004

Lecture 7, Slide 20

Step 4E: select programming file

6.111 Fall 2004

Lecture 7, Slide 21

Step 4F: Add to list

We program the EPC2 serial flash memory whose


contents is loaded into the Flex10K FPGA on power-up.
6.111 Fall 2004

Lecture 7, Slide 22

Step 4G: Attach ByteBlasterII cable


ByteBlasterII cable

EPC2LC20 serial flash RAM


Flex10K10LC84 FPGA

Header with AD bus


connections to FPGA pins

Connections to buttons
6.111 Fall 2004

1.8432Mhz XTAL wired to /AD0 which


connects to CLK input (pin 1) of FPGAs

FPGA I/Os wired to


7-segment display

Lecture 7, Slide 23

Step 4H: program device, cycle power

6.111 Fall 2004

Lecture 7, Slide 24

You might also like