verilog程序.doc_第1页
verilog程序.doc_第2页
verilog程序.doc_第3页
verilog程序.doc_第4页
verilog程序.doc_第5页
已阅读5页,还剩4页未读, 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

module first_counter (clock , / Clock input of the designreset , / active high, synchronous Reset inputenable , / Active high enable signal for countercounter_out / 4 bit vector output of the counter); / End of port list/-Input Ports-input clock ;input reset ;input enable ;/-Output Ports-output 3:0 counter_out ;/-Input ports Data Type-/ By rule all the input ports should be wires wire clock ;wire reset ;wire enable ;/-Output Ports Data Type-/ Output port can be a storage element (reg) or a wirereg 3:0 counter_out ;/-Code Starts Here-/ Since this counter is a positive edge trigged one,/ We trigger the below block with respect to positive/ edge of the clock.always (posedge clock)begin : COUNTER / Block Name/ At every rising edge of clock we check if reset is active/ If active, we load the counter output with 4b0000if (reset = 1b1) begincounter_out = #1 4b0000;end/ If enable is active, then we increment the counterelse if (enable = 1b1) begincounter_out = #1 counter_out + 1;endend / End of Block COUNTERendmodule / End of Module counterTestbench of counter4include first_counter.v 2module first_counter_tb();3/ Declare inputs as regs and outputs as wires4reg clock, reset, enable;5wire 3:0 counter_out;67/ Initialize all variables8initial begin 9$display ( timet clk reset enable counter ); 10$monitor ( %gt %b % %b %b , 11$time, clock, reset, enable, counter_out); 12clock = 1; / initial value of clock13reset = 0; / initial value of reset14enable = 0; / initial value of enable15r#5eset = 1; / Assert the reset16#10 reset = 0; / De-assert the reset17#5 enable = 1; / Assert enable18#100 enable = 0; / De-assert enable19#10 $finish; / Terminate simulation20end2122/ Clock generator23always begin24#5 clock = clock; / Toggle clock every 5 ticks25end2627/ Connect DUT to test bench28first_counter U_counter (29clock,30reset,31enable,32counter_out33);3435endmodule1module arbiter ( 2clock, 3reset, 4req_0, 5req_1, 6gnt_0, 7gnt_1 8); 910input clock, reset, req_0, req_1; 11output gnt_0, gnt_1; 1213reg gnt_0, gnt_1; 1415always (posedge clock or posedge reset) 16if (reset) begin 17gnt_0 = 0; 18gnt_1 = 0; 19end else if (req_0) begin 20gnt_0 = 1; 21gnt_1 = 0; 22end else if (req_1) begin 23gnt_0 = 0; 24gnt_1 = 1; 25end 2627endmodule 29module arbiter_tb; 3031reg clock, reset, req0,req1; 32wire gnt0,gnt1; 3334initial begin 35$monitor ( req0=%b,req1=%b,gnt0=%b,gnt1=%b , req0,req1,gnt0,gnt1); 36clock = 0; 37reset = 0; 38req0 = 0; 39req1 = 0; 40#5 reset = 1; 41#15 reset = 0; 42#10 req0 = 1; 43#10 req0 = 0; 44#10 req1 = 1; 45#10 req1 = 0; 46#10 req0,req1 = 2b11; 47#10 req0,req1 = 2b00; 48#10 $finish; 49end 5051always begin 52#5 clock = clock; 53end

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论