usd 发表于 2010-6-28 00:30:28

verilog数字跑表

module stopwatch(
      clk_50M,
      rst,          //复位
      mode,      //控制键:启动、暂停、暂停后继续计时
      cnt_msel_low,    //毫秒的低位输出
      cnt_msel_hig,    //毫秒的高位输出
      cnt_s_low,      //秒的地位输出
      cnt_s_hig       //秒的高位输出
   );
   
input clk_50M,
rst,
mode;

output cnt_msel_low,
      cnt_msel_hig,
      cnt_s_low,
      cnt_s_hig;
      
wire clk;
wire en_cnt;
      
clk_1kgeni0(
      .clk_50M   (clk_50M),
      .rst   (rst),
      .clk   (rst)
      );   
work_blocki1(
      .clk    (clk),
      .rst    (rst),
      .en_cnt   (en_cnt),
      .cnt_msel_low (cnt_msel_low) ,
      .cnt_msel_hig (cnt_msel_hig),
      .cnt_s_low(cnt_s_low),
      .cnt_s_hig(cnt_s_hig )
      );
control i2( .clk   (clk),
   .rst   (rst ),
   .mode    (mode),
   .en_cnt    (en_cnt)
      );
endmodule               
      
//==========================================================      
module control (clk,
      rst,
      mode,
      en_cnt
      );
      
input clk;
input rst;
input mode;
output en_cnt;      

reg en_cnt;      
reg state;   
parameter stop=0;
parameter work=1;
parameter tmpstop=2;

always @(posedge clk or posedge rst)
if (rst)
begin
state<=stop;
en_cnt<=0;
end
else
begin
case(state)
stop:
begin
en_cnt<=0;
if (mode)
state<=work;
end
work:
begin
en_cnt<=1;
if(mode)
state<=tmpstop;
end
tmpstop:
begin
en_cnt<=0;
if(mode)
state<=work;
end
default:
state<=stop;
endcase   
end
endmodule
//-----------generate clk_1k-------------------------------------
module clk_1kgen (
      clk_50M,
      rst,
      clk
      );
input clk_50M;
input rst;
output clk;

reg clk;
reg cnt_clk;
      
always @(posedge clk_50M or posedge rst)
begin
if (rst)
cnt_clk<=0;
else if (cnt_clk==50000)
cnt_clk<=0;
else
cnt_clk<=cnt_clk+1;
end
always @(posedge clk_50M or posedge rst)
begin
if (rst)
clk<=0;
else if (cnt_clk==0)
clk<=0;
else if (cnt_clk==25000)
clk<=1;
end

endmodule

//============================================================
//   work block
//============================================================
module work_block(clk,
       rst,
       en_cnt,
       cnt_msel_low,
       cnt_msel_hig,
       cnt_s_low,
       cnt_s_hig
    );
input clk;
input rst;
input en_cnt;
output cnt_msel_low;
output cnt_msel_hig;
output cnt_s_low;   
output cnt_s_hig;

reg cnt_msel;
reg cnt_msel_low;
reg cnt_msel_hig;
reg cnt_s_low;
reg cnt_s_hig;

wire msel_low;
wire msel_hig;
wire s_low;
wire s_hig;

assign msel_low=(cnt_msel==9)? 1'b1:1'b0;
assign msel_hig=(cnt_msel_low==9)? msel_low:1'b0;
assign s_low=(cnt_msel_hig==9) ? msel_hig:1'b0;
assign s_hig=(cnt_s_low==9)? s_low:1'b0;

always @(posedge clk or posedge rst)
begin
   if (rst)
   cnt_msel<=0;
else if (en_cnt)
begin
   if(cnt_msel==9)
   cnt_msel<=0;
   else
   cnt_msel<=cnt_msel+1;
   end
end
//====================cnt_msel_low============================
always @(posedge clk or posedge rst)
begin
   if (rst)
   cnt_msel_low<=0;
   else if (en_cnt)
   begin
   if (msel_low)
   begin
    if (cnt_msel_low==9)
      cnt_msel_low<=0;
    else
    cnt_msel_low<=cnt_msel_low+1;
   end
   end
end
//===================cnt_msel_hig=============================   
always @(posedge clk or posedge rst)
begin
   if (rst)
   cnt_msel_hig<=0;
   else if (en_cnt)
   begin
   if (msel_hig)
   begin
    if (cnt_msel_hig==9)
      cnt_msel_hig<=0;
    else
    cnt_msel_hig<=cnt_msel_hig+1;
   end
   end
   end
//==================cnt_s_low=================================   
always @(posedge clk or posedge rst)
begin
   if (rst)
   cnt_s_low<=0;
   else if (en_cnt)
   begin
   if (s_low)
   begin
    if (cnt_s_low==9)
      cnt_s_low<=0;
    else
    cnt_s_low<=cnt_s_low+1;
   end
   end
   end
//===================cnt_s_hig=================================
always @(posedge clk or posedge rst)
begin
   if (rst)
   cnt_s_hig<=0;
   else if (en_cnt)
   begin
   if (s_hig)
   begin
    if (cnt_s_hig==5)
      cnt_s_hig<=0;
    else
    cnt_s_hig<=cnt_s_hig+1;
   end
   end
end   
endmodule

interig 发表于 2010-6-28 01:20:36

俺是用VHDL,看不太明白,走错了

usb 发表于 2010-6-28 02:48:27

有何问题呢?

interig 发表于 2010-6-28 04:35:19

哈哈<br>
有什么问题啊??<br>
说说看呢

inter 发表于 2010-6-28 05:30:33

这个帖子没什么意义,好像是在举例,又不说清楚!

大鹏 发表于 2020-8-28 15:15:12

verilog数字跑表

zxopenhl 发表于 2020-8-30 17:00:54

verilog数字跑表
页: [1]
查看完整版本: verilog数字跑表