在线咨询
eetop公众号 创芯大讲堂 创芯人才网
切换到宽版

EETOP 创芯网论坛 (原名:电子顶级开发网)

手机号码,快捷登录

手机号码,快捷登录

找回密码

  登录   注册  

快捷导航
搜帖子
查看: 2758|回复: 6

[求助] verilog实例化出问题

[复制链接]
发表于 2013-4-9 14:12:20 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

x
本帖最后由 guozheng 于 2013-4-9 14:13 编辑

用verilog对输入脉冲信号进行实时的计数,每秒钟输出一次计数值;因为使用8段数码管进行显示,所以在程序中有实例化的部分,但实例化的部分一直报错,求指导。 时钟频率100MHz;
主模块:




  1. module pulse_counter(pulse,clk,rst_n,counter2,counter1,out1,out2,out3,out4,out5);
  2. output reg [7:0] out1,out2,out3,out4,out5;
  3. //output wire [9:0] di;
  4. input pulse;
  5. input clk;
  6. input rst_n;

  7. wire  [7:0]out_1,out_2,out_3,out_4,out_5;
  8. output reg [26:0]counter1; //每秒显示一次数字;  
  9. output reg [16:0] counter2;//显示的数字;
  10. reg rst;
  11. reg [26:0] reference=27'd0;//通过reference来判断是否在1s之内;

  12. assign di=10'd0;
  13. parameter range=27'd100000000;

  14. always @(posedge clk)
  15.         rst=rst_n;

  16. always @(posedge clk or negedge rst)
  17.         if(!rst)
  18.                 counter1=0;
  19.         else if(counter1<range-1)
  20.                 counter1=counter1+1;
  21.                 else
  22.                         counter1=0;

  23. always @(posedge pulse or negedge rst)
  24.         begin
  25.         if(!rst)
  26.                 counter2=0;
  27.                 else if(counter1>reference)
  28.                         counter2=counter2+1;
  29.                         else
  30.                                 begin
  31.                   xianshi uxianshi(counter2,out_1,out_2,out_3,out_4,out_5);
  32.                //xianshi u_xianshi(counter2,out_1,out_2,out_3,out_4,out_5);
  33.                                 out1=out_1;
  34.                                 out2=out_2;
  35.                                 out3=out_3;
  36.                                 out4=out_4;
  37.                                 out5=out_5;                                
  38.                                 counter2=1;
  39.                                 end
  40.         //reference=counter1;
  41.         end

  42. always @(posedge pulse or negedge rst)
  43.         if(!rst)
  44.                 reference=0;
  45.         else
  46.                 reference=counter1;
  47.                
  48.                
  49. //xianshi u_xianshi(counter2,out1,out2,out3,out4,out5);

  50. endmodule


复制代码





被调用的模块:




  1. module xianshi(in,out1,out2,out3,out4,out5);
  2. input [16:0] in;
  3. output wire [7:0] out1,out2,out3,out4,out5;
  4. //output wire [9:0] di;
  5. wire [3:0] num5,num4,num3,num2,num1;
  6. reg [7:0] temp1,temp2,temp3,temp4,temp5;
  7. assign num5=in/10000;
  8. assign num4=(in-num5*10000)/1000;
  9. assign num3=(in-num5*10000-num4*1000)/100;
  10. assign num2=(in-num5*10000-num4*1000-num3*100)/10;
  11. assign num1=in-num5*10000-num4*1000-num3*100-num2*10;
  12. parameter num_0=8'b11100111;
  13. parameter num_1=8'b00100001;
  14. parameter num_2=8'b11001011;
  15. parameter num_3=8'b01101011;   
  16. parameter num_4=8'b00101101;   
  17. parameter num_5=8'b01101110;
  18. parameter num_6=8'b11101110;
  19. parameter num_7=8'b00100011;
  20. parameter num_8=8'b11101111;   
  21. parameter num_9=8'b00101111;   

  22. case(num5)
  23.     0:assign out5=num_0;
  24.     1:assign out5=num_1;
  25.     2:assign out5=num_2;
  26.     3:assign out5=num_3;   
  27.     4:assign out5=num_4;
  28.     5:assign out5=num_5;
  29.     6:assign out5=num_6;
  30.     7:assign out5=num_7;
  31.     8:assign out5=num_8;
  32.     9:assign out5=num_9;   
  33. endcase

  34. case(num4)
  35.     0:assign out4=num_0;
  36.     1:assign out4=num_1;
  37.     2:assign out4=num_2;
  38.     3:assign out4=num_3;   
  39.     4:assign out4=num_4;
  40.     5:assign out4=num_5;
  41.     6:assign out4=num_6;
  42.     7:assign out4=num_7;
  43.     8:assign out4=num_8;
  44.     9:assign out4=num_9;   
  45. endcase

  46. case(num3)
  47.     0:assign out3=num_0;
  48.     1:assign out3=num_1;
  49.     2:assign out3=num_2;
  50.     3:assign out3=num_3;   
  51.     4:assign out3=num_4;
  52.     5:assign out3=num_5;
  53.     6:assign out3=num_6;
  54.     7:assign out3=num_7;
  55.     8:assign out3=num_8;
  56.     9:assign out3=num_9;   
  57. endcase

  58. case(num2)
  59.     0:assign out2=num_0;
  60.     1:assign out2=num_1;
  61.     2:assign out2=num_2;
  62.     3:assign out2=num_3;   
  63.     4:assign out2=num_4;
  64.     5:assign out2=num_5;
  65.     6:assign out2=num_6;
  66.     7:assign out2=num_7;
  67.     8:assign out2=num_8;
  68.     9:assign out2=num_9;   
  69. endcase

  70. case(num1)
  71.     0:assign out1=num_0;
  72.     1:assign out1=num_1;
  73.     2:assign out1=num_2;
  74.     3:assign out1=num_3;   
  75.     4:assign out1=num_4;
  76.     5:assign out1=num_5;
  77.     6:assign out1=num_6;
  78.     7:assign out1=num_7;
  79.     8:assign out1=num_8;
  80.     9:assign out1=num_9;   
  81. endcase

  82. endmodule


复制代码





错误提示如下:

@E: CG285 :"E:\FPGA\pulse_counter.v":36:13:36:20|Expecting statement
@E: CS187 :"E:\FPGA\pulse_counter.v":57:0:57:8|Expecting endmodule
 楼主| 发表于 2013-4-9 14:23:59 | 显示全部楼层
已经解决了,实例化的部分是对wire型变量的操作,不能放在always语句中。
发表于 2013-4-9 15:27:54 | 显示全部楼层
回复 2# guozheng


    你好,你的reg型变量也不使用非阻塞赋值吗
 楼主| 发表于 2013-4-9 21:09:53 | 显示全部楼层
回复 3# feitianzhilu287

?   我是用的都是阻塞型赋值
发表于 2013-4-10 13:10:24 | 显示全部楼层
我怎么感觉你这是用软件思维在写RTL代码呢?你能想清楚这段代码实现的电路是什么样么?
发表于 2013-4-11 23:23:41 | 显示全部楼层
回复 5# mirson


    同意楼上,这代码肯定会有很多锁存器生成。
发表于 2013-4-12 11:34:52 | 显示全部楼层
回复 4# guozheng


    最好用非阻塞赋值,我建议。不过我都是使用非阻塞的,所以阻塞赋值会引起什么时序问题没遇到过,不过网上别人的例子
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

站长推荐 上一条 /2 下一条

X

小黑屋| 手机版| 关于我们| 联系我们| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2025-6-17 20:20 , Processed in 0.021326 second(s), 10 queries , Gzip On, MemCached On.

eetop公众号 创芯大讲堂 创芯人才网
快速回复 返回顶部 返回列表