关于分频程序问题
时间:10-02
整理:3721RD
点击:
初学Verilog,编了一小段关于分频的程序(输出50%占空比,5分频信号),但编译就是通不过,各位高手有兴趣就请帮忙看看,不胜感激!
下面是源程序:
下面是源程序:
- module hh(clk,k,k1,k2);
- input clk;
- output k,k1,k2;
- reg [2:0]c1;
- reg m1;
- always @(posedge clk)…………………………第29行
- begin
- if (c1==4)
- begin
- c1
- end
- else c1
- end
- always @(negedge clk)………………………………第37行
- begin
- if (c1==4)
- begin
- c1
- end
- else c1
- end
- assign k=m1;
- endmodule
- 编译提示的错误:
- Error (10028): Can't resolve multiple constant drivers for net "c1[2]" at hh.v(37)
- Error (10029): Constant driver at hh.v(29)
- Error (10028): Can't resolve multiple constant drivers for net "c1[1]" at hh.v(37)
- Error (10028): Can't resolve multiple constant drivers for net "c1[0]" at hh.v(37)
- Error (10028): Can't resolve multiple constant drivers for net "m1" at hh.v(37)
- Error: Can't elaborate top-level user hierarchy
- Error: Quartus II Analysis & Synthesis was unsuccessful. 6 error s, 4 warnings
- Error: Peak virtual memory: 170 megabytes
- Error: Processing ended: Thu Oct 21 14:37:21 2010
- Error: Elapsed time: 00:00:01
- Error: Total CPU time (on all processors): 00:00:01
- Error: Quartus II Full Compilation was unsuccessful. 8 errors, 4 warnings
首先,你的程序写的不甚规范(连rst信号都没有),刚开始写,一定要养成一个好的编程习惯才好;
其次,分频的程序其实用不着这么复杂的,不知道你为什么要用两个always块儿。
这也直接导致了错误的发生(多驱动)---------不能在多个always块中对同一个变量进行赋值。
你程序中的c1和m1在两个always块中都赋值了。
根据楼上的指正,小弟又写了一段,但是结果还是不是想要的,望赐教!
源程序如下:
module hh(clk,k,k1,k2);
input clk;
output k,k1,k2;
(*synthesis,probe_port,keep*) reg [2:0]c1,c2;
reg m1,c;
always @(posedge clk)
c1<=c1+1;
always @(negedge clk)
c2<=c2+1;
always@(c1 or c2)
begin
c<=c1+c2;
if (c==4)
begin
c<=0;
c1<=0;
c2<=0;
m1<=~m1;
end
end
assign k=m1;
endmodule
编译提示没有错误,就是结果出不来,多谢指正!
你可以把三个always合并在一个里面写,没必要分开来,因为分频器是同步设计,进城的激活都是依赖于时钟触发的。