Академический Документы
Профессиональный Документы
Культура Документы
COE133L/C1
Alarm Clock
Submitted By:
Instructor
Introduction
Hardware Description Language (HDL) is used to model, describe, and simulate the structure and
behavior of electronic circuits. There are two major types of hardware description language: VHDL, and
Verilog. The latter is used in this project. There are types of description in HDL. They are the dataflow,
structural, and behavioral. In Verilog, behavioral models contain procedural statements that control the
simulation and manipulate variables of the data types previously described. These statements are
contained within procedures. Each procedure has an activity flow associated with it. On the other hand,
structural modeling describes the interconnection between the components of a hardware module and the
design of the hardware by connecting various modules and gates, such as and, and or. Lastly, dataflow
modelling in Verilog allows a circuit to be designed in terms of the data flow between registers and how a
design processes data rather than instantiation of individual gates.
The project is limited to the creation of a digital alarm clock using Verilog HDL. The program has an
alarm function, which, when connected to a buzzer, will turn it on. On the other hand, when not
connected, it will yield a value of 1.
Program Code
module mux2b16(s,minm1,hrm1,minm2,hrm2,min_out,hr_out);
input [7:0]minm1,hrm1,minm2,hrm2;
input s;
endmodule
begin
if(reset==1)
begin
hour_out<= 8'h0;
end
else
begin
sec_out <= sec_in;
hour_out<=hour_in;
end
end
endmodule
input reset;
input [3:0]bcd_in;
begin
if(reset==1)
disp_out = 7'b0000001;
else
case(bcd_in)
endcase
end
endmodule
begin
if(reset == 1)
begin
count<=8'h0;
tc <= 1'b0;
end
else
begin
if(count == 8'h59)
begin
tc <= 1'b1;
end
else
begin
tc <= 1'b0;
if(count[3:0] == 4'd10)
begin
end
end
end
end
endmodule
begin
if(reset == 1)
begin
count<=8'h0;
tc <= 1'b0;
end
else
begin
if(count == 8'h23)
begin
tc <= 1'b1;
end
else
begin
tc <= 1'b0;
if(count[3:0] == 4'd10)
begin
end
end
end
end
endmodule
module alarmunit(en,clk,almin,alhr,min,hr,assert);
begin
if(en==0)
assert<=1'b0;
assert <= 1;
else
assert <=0;
end
endmodule
input reset,clkin;
reg [25:0]cnt;
begin
if(reset==1)
begin
cnt = 26'd0;
clkout = 1'b1;
end
else
if(cnt == 26'd2500)
begin
clkout = ~clkout;
cnt = 26'd0;
end
end
endmodule
input reset,clk;
input [3:0]num;
input [1:0]mode;
reg [7:0]min,hr;
reg [2:0]currstate,nextstate;
parameter IDLE=3'd0,GOT1=3'd1,GOT2=3'd2,GOT3=3'd3,GOT4=3'd4;
parameter DISP=2'd0,SETT=2'd1,SETA=2'd2,DISA=2'd3;
begin
if(reset)
begin
enablealarm=1;
enabledisplay=1;
currstate<=IDLE;
nextstate<=IDLE;
settime<=0;
setalarm<=0;
min_out<=8'h0;
hr_out<=8'h0;
end
else
currstate<=nextstate;
end
always@(posedge clk)
begin
case(mode)
DISP:
begin
enabledisplay<=1;
nextstate<=IDLE;
settime<=0;
setalarm<=0;
end
//---------------------------
SETT:
begin
case(nextstate)
IDLE:
begin
enabledisplay<=0;
nextstate<=GOT1;
settime<=0;
setalarm<=0;
end
GOT1:
begin
enabledisplay<=0;
hr[7:4]<=num[3:0];
nextstate<=GOT2;
end
GOT2:
begin
enabledisplay<=0;
hr[3:0]<=num[3:0];
nextstate<=GOT3;
end
GOT3:
begin
enabledisplay<=0;
min[7:4]<=num[3:0];
nextstate<=GOT4;
end
GOT4:
begin
min[3:0]=num[3:0];
settime<=1;
min_out<=min;
hr_out <=hr;
nextstate<=IDLE;
enabledisplay<=1;
end
endcase
end
//-----------------------------------
SETA:
begin
case(nextstate)
IDLE:
begin
enabledisplay<=0;
nextstate<=GOT1;
settime<=0;
setalarm<=0;
end
GOT1:
begin
enabledisplay<=0;
hr[7:4]<=num[3:0];
nextstate<=GOT2;
end
GOT2:
begin
enabledisplay<=0;
hr[3:0]<=num[3:0];
nextstate<=GOT3;
end
GOT3:
begin
enabledisplay<=0;
min[7:4]<=num[3:0];
nextstate<=GOT4;
end
GOT4:
begin
enabledisplay<=1;
min[3:0]=num[3:0];
setalarm<=1;
min_out<=min;
hr_out <=hr;
nextstate<=IDLE;
end
endcase
end
//---------------------------------------
DISA:
begin
enablealarm<=0;
nextstate<=IDLE;
end
endcase
end
endmodule
module testbench;
wire [7:0] seca, mina, hra,minm1,hrm1,minm2,hrm2,sec, min, hr; //a stands for asynchronous output
wire [1:0]mode;
wire [3:0]num;
wire [7:0]minset,hrset;
wire alert;
reg [7:0]alarmmin1,alarmhr1;
// alarm function
initial
begin
system_clk=1'b1;
reset = 1'b1;
#1
reset = 1'b0;
alarmmin1=8'h01;
alarmhr1 =8'h00;
end
always
endmodule