竹林听雨早晨 发表于 2010-10-28 21:40:33

各位看看我这程序怎么不出波形呀???

主程序module counter_10(clock,counter);
    input clock;
    output counter;
    reg counter;
   
    initial
   begin
         counter=6;
   end
   
   always @(posedge clock)
      begin
          if(counter<16)
            counter <= counter + 1 ;
          else
            counter <= 6;
      end
endmodule
      
测试模块
`include"counter_10.v"
module TESTcounter_10;
    reg clock;
    wire counter;
   counter_10 U(clock,counter);
   
    initial
    begin
   clock=0;
    end
   always #50 clock=~clock;
   
   
   
endmodule

竹林听雨早晨 发表于 2010-10-28 21:53:37

我想设计一个十进制计数器

njithjw 发表于 2010-10-28 22:22:33

module counter_10(clock,counter);
    input clock;
    output counter;
    reg counter;
   
//    initial
//   begin
//         counter=6;
//   end
   
//   always @(posedge clock)
//      begin
//          if(counter<16)
//            counter <= counter + 1 ;
//          else
//            counter <= 6;
//      end

always @ (posedge clock)
begin
    if (counter>=4'd9)
      counter <= 4'd0;
    else
      counter <= counter + 4'd1;      
end

endmodule

竹林听雨早晨 发表于 2010-10-28 23:17:25

回复 3# njithjw


    这是十进制的吗

njithjw 发表于 2010-10-28 23:48:02

你可以自己仿真一下看看就知道了。

不过不知道你想要的是自然二进制编码下的十进制,还是8421BCD码的十进制。

xuanyuanchen 发表于 2010-10-29 00:43:13

回复 1# 竹林听雨早晨


    你这个在测试文件的开头没有加`timescale这一句,这个不能丢

liyujie 发表于 2010-10-29 08:36:49

6和16是做什么用的?

fullattack 发表于 2010-10-29 19:43:27

counter_10 U(.clock(clock),.counter(counter));测试文件这句应该这样写吧。

fullattack 发表于 2010-10-29 19:45:41

counter也不会超过16最多=15
always @(posedge clock)
//      begin
//          if(counter<16)
//            counter <= counter + 1 ;
//          else
//            counter <= 6;
//      end
不会执行的

竹林听雨早晨 发表于 2010-10-31 20:06:50

回复 6# xuanyuanchen


    他有啥用啊
页: [1] 2
查看完整版本: 各位看看我这程序怎么不出波形呀???