1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | module my_ex2( clk , rst_n , en , dout ); input clk ; input rst_n ; input en ; output dout ; reg [ 2:0] cnt ; wire add_cnt ; wire end_cnt ; reg flag_add ; reg dout ; always @(posedge clk or negedge rst_n)begin if(!rst_n)begin cnt <= 0; end else if(add_cnt)begin if(end_cnt) cnt <= 0; else cnt <= cnt + 1; end end assign add_cnt = flag_add==1; assign end_cnt = add_cnt && cnt==5-1 ; always @(posedge clk or negedge rst_n)begin if(rst_n==1'b0)begin flag_add <= 0; end else if(en==1)begin flag_add <= 1; end else if(end_cnt)begin flag_add <= 0; end end always @(posedge clk or negedge rst_n)begin if(rst_n==1'b0)begin dout <= 0; end else if(add_cnt && cnt==3-1)begin dout <= 1; end else if(end_cnt)begin dout <= 0; end end endmodule |
欢迎光临 (http://www.51hei.com/bbs/) | Powered by Discuz! X3.1 |