我在试着教自己一些Verilog。我试着做一个mod-10计数器,它每秒钟重复一次。我试图修改的代码是一些我在一个旧论坛上找到的。
我试着使用第二个计数器,在第26位“计数器”的每一个上升边缘上迭代。我不允许检查这样的事件吗?我怎样才能用其他方式做到这一点呢?
always @(posedge clk) begin
if (!enable) begin
counter <= counter + 1;
if (posedge counter[26]) begin
seven_output = seven_output + 1; //iterate the cumulative output state every second ish
end
end
end在这里,seven_output只是另一个计数器,它的目的是按描述迭代,并传递到一个单独的模块,它的任务是确定LED的组合状态返回。
我得到的唯一错误描述是
第73行:接近“后置”的语法错误。
第73行是最内部的if语句.
发布于 2022-01-17 20:51:35
您会得到语法错误,因为在下面的行中使用posedge关键字是非法的:
if (posedge counter[26]) begin 这是非法的,因为没有定时事件控制。例如,@(posedge something)使用posedge关键字和边缘控件构造:@( )。
与其在那里使用posedge,不如为edge detector的count[26]信号创建单独的逻辑;让我们称它为pe_count26。
此外,我建议将两个计数器分成两个单独的always块。
always @(posedge clk) begin
if (!enable) begin
counter <= counter + 1;
end
end
always @(posedge clk) begin
if (pe_count26) begin
seven_output <= seven_output + 1;
end
end对顺序逻辑使用非阻塞分配(<=)是一种推荐的良好编码实践。我相应地改变了你的seven_output作业。
https://stackoverflow.com/questions/70746877
复制相似问题