あなたが持っているデザインはおそらく合成可能ですが、上記のコメントごとにラッチが表示されます。 casex文は、ラッチを取り除くことを条件として、より読みやすくなります。
私が使用している小型のエンコーダです。私はそれを有効にするように修正しました。 "enable + select"入力の幅を{1'b1,6'bxxxxxx}のベクトルの幅と一致させることが重要です。この場合、1 + 6 = 7.必要に応じて拡大することができます。
function [2:0] prienc6;
input enable;
input [5:0] select;
reg [2:0] out;
begin
casex({enable,select})
{1'b1,6'b000001}: out = 3'b101;
{1'b1,6'b00001x}: out = 3'b100;
{1'b1,6'b0001xx}: out = 3'b011;
{1'b1,6'b001xxx}: out = 3'b010;
{1'b1,6'b01xxxx}: out = 3'b001;
{1'b1,6'b1xxxxx}: out = 3'b000;
{1'b0,6'bxxxxxx}: out = 3'b000; // if you assign out = out, then you get latches.
endcase
prienc6 = out ;
end
endfunction
あなたは、このような
reg [2:0] encode_out;
function [2:0] prienc6;
input enable;
input [5:0] select;
input [2:0] prev_out;
reg [2:0] out;
begin
casex({enable,select})
{1'b1,6'b000001}: out = 3'b101;
{1'b1,6'b00001x}: out = 3'b100;
{1'b1,6'b0001xx}: out = 3'b011;
{1'b1,6'b001xxx}: out = 3'b010;
{1'b1,6'b01xxxx}: out = 3'b001;
{1'b1,6'b1xxxxx}: out = 3'b000;
{1'b0,6'bxxxxxx}: out = prev_out;
endcase
prienc6 = out ;
end
endfunction
always @ (posedge clk or posedge reset)
begin
if (reset) encode_out <= 3'b000;
else encode_out <= prienc6(some_enable,some_select,encode_out); //latch avoided.
end
として、これが適している場合、私は知りませんが、それは私の好ましい解決策である、ラッチを避けるためにprev_out、およびクロックが含まれるように、これを拡張することができます。私は機能の外部を有効にします。
reg [2:0] encode_out;
function [2:0] prienc6;
input [5:0] select;
reg [2:0] out;
begin
casex(select)
6'b000001: out = 3'b101;
6'b00001x: out = 3'b100;
6'b0001xx: out = 3'b011;
6'b001xxx: out = 3'b010;
6'b01xxxx: out = 3'b001;
6'b1xxxxx: out = 3'b000;
default : out = 3'b000;
endcase
prienc6 = out ;
end
endfunction
always @ (posedge clk or posedge reset)
begin
if (reset) encode_out <= 3'b000;
else encode_out <= enable ? prienc6(some_input) : encode_out;
end
コンビナトリアルブロックの 'if(enable)'は、ラッチを意味します。 – Morgan