集成电路技术分享

 找回密码
 我要注册

QQ登录

只需一步,快速开始

搜索
查看: 4335|回复: 6

verilog数字跑表

[复制链接]
usd 发表于 2010-6-28 00:30:28 | 显示全部楼层 |阅读模式
module stopwatch(
      clk_50M,
      rst,          //复位
      mode,        //控制键:启动、暂停、暂停后继续计时
      cnt_msel_low,    //毫秒的低位输出
      cnt_msel_hig,    //毫秒的高位输出
      cnt_s_low,      //秒的地位输出
      cnt_s_hig       //秒的高位输出
     );
   
input clk_50M,
  rst,
  mode;
  
output [3:0] 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 [2:0] 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 [15:0] 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 [3:0] cnt_msel_low;
output [3:0] cnt_msel_hig;
output [3:0] cnt_s_low;   
output [3:0] cnt_s_hig;

reg [3:0] cnt_msel;
reg [3:0] cnt_msel_low;
reg [3:0] cnt_msel_hig;
reg [3:0] cnt_s_low;
reg [3:0] 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 下一条

QQ|小黑屋|手机版|Archiver|集成电路技术分享 ( 京ICP备20003123号-1 )

GMT+8, 2024-4-20 21:14 , Processed in 0.068413 second(s), 22 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表