适合协议操作
通过某些协议而对某些寄存器操作,例如通过AMBA协议对寄存器操作。
只要instruction_set和instruction_clear能够条件互斥,即满足
| instruction_set | instruction_clear | |
|---|---|---|
| 0 | 1 | 清除 |
| 1 | 0 | 设置 |
| 0 | 0 | 保持 |
| 1 | 1 | 无效 |
原来有点像锁存器的概念了。
assign instruction_set = //写某些寄存器 A的指令
assign instruction_clear = //写某些寄存器 B的指令
reg instruction;
always @(posedge clk or negedge rst_n)
begin
if (~rst_n)
instruction <= 1'b0;
else if (instruction_set | instruction_clear)
instruction <= instruction_set;
end
异步复位
module top_module (
input clk,
input areset,
input [7:0] d,
output [7:0] q
);
always@(posedge clk,posedge areset)
if(!areset)
q<=8'h0;
else
q<=d;
endmodule
综合时候报错:
cannot match operand(s) in the condition to the corresponding edges in the enclosing event control of the always construct File。
意味着综合无法推断出异步复位的极性,always块里面的事件控制表达式(@(…))描述为上升沿异步复位,然而if(!areset)表达式却表达相反的控制逻辑出错,正确的应是
module top_module (
input clk,
input areset,
input [7:0] d,
output [7:0] q
);
always@(posedge clk,posedge areset)
if(areset)
q<=8'h0;
else
q<=d;
endmodule
verilog 固定位宽分割
当要创建一个4bit位宽,256个MUX,256MUX分割1024bit位宽的输入,sel = 0,输出为3:0,sel =1 输出为7:4, 以此类推。
module top_module(
input [1023:0] in,
input [7:0] sel,
output [3:0] out );
assign out = in[sel*4+:4];
endmodule
此时verilog可以自动推导位宽固定为4,而
assign out = in[ sel*4+3 : sel*4 ];
无法工作,因为sel*4并不是常数。

4070

被折叠的 条评论
为什么被折叠?



