独热编码即 One-Hot 编码,又称一位有效编码,其方法是使用N位状态寄存器来对N个状态进行编码,每个状态都有它独立的寄存器位,并且在任意时候,其中只有一位有效。
例如对六个状态进行编码:
自然顺序码为 000,001,010,011,100,101
独热编码则是 000001,000010,000100,001000,010000,100000
module top_module(
input in,
input [9:0] state,
output [9:0] next_state,
output out1,
output out2);
assign next_state[0]=(state[0]&(~in)) |(state[1]&(~in)) |(state[2]&(~in))
|(state[3]&(~in)) |(state[4]&(~in)) |(state[8]&(~in)) |(state[9]&(~in))|(state[7]&(~in));
assign next_state[1]=(state[0]&in) |(state[8]&in) |(state[9]&in);
assign next_state[2]=state[1]∈
assign next_state[3]=state[2]∈
assign next_state[4]=state[3]∈
assign next_state[5]=state[4]∈
assign next_state[6]=state[5]∈
assign next_state[7]=(state[6]&in)|(state[7]&in);
assign next_state[8]=state[5]&(~in);
assign next_state[9]=state[6]&(~in);
assign out1=(state[8]|state[9])?1:0;
assign out2=(state[9]|state[7])?1:0;
endmodule
没有回复内容