栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

二进制码转独热码

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

二进制码转独热码

特点:位宽参数化

实现代码如下:

`timescale 1ns / 1ps
//
// Company: nssc
// Engineer: liumeng
// Create Date:    09:34:27 12/28/2021
// Module Name:    bin_to_one_hot
// Revision 0.01 - File Created
//
module bin_to_one_hot #
       (
           parameter BIN_WIDTH = 4
       )(
           input[BIN_WIDTH-1:0]        d_bin,
           output[2**BIN_WIDTH-1:0]    q_one_hot
       );

parameter PART_NUMBER = BIN_WIDTH>>1;
parameter EXT_BIT = BIN_WIDTH%2;
wire[3:0] q_one_hot_temp [PART_NUMBER-1:0];
wire[PART_NUMBER-1+1:0] q_one_hot_cal[2**BIN_WIDTH-1:0];

genvar i,j;
generate
    for (i=0; i 

其中使用到的bin_to_one_hot_2_4代码:

`timescale 1ns / 1ps
//
// Company: nssc
// Engineer: liumeng
// Create Date:    20:07:24 12/20/2021
// Module Name:    bin_to_one_hot_2_4
// Revision 0.01 - File Created
//
module bin_to_one_hot_2_4(
           input[1:0]      d_bin,
           output[3:0]     q_one_hot
       );

assign q_one_hot[0] = ~d_bin[1] & ~d_bin[0];
assign q_one_hot[1] = ~d_bin[1] & d_bin[0];
assign q_one_hot[2] = d_bin[1] & ~d_bin[0];
assign q_one_hot[3] = d_bin[1] & d_bin[0];

endmodule

仿真代码如下:

`timescale 1ns / 1ps
//
// Company: nssc
// Engineer: liumeng
// Create Date:    11:03:55 12/28/2021
// Module Name:    sim_bin_to_one_hot
// Revision 0.01 - File Created
//
module sim_bin_to_one_hot;
	parameter BIN_WIDTH = 3;
	reg [BIN_WIDTH-1:0]			d_bin;
	wire [2**BIN_WIDTH-1:0]		q_one_hot;

	bin_to_one_hot #(.BIN_WIDTH(BIN_WIDTH)) uut (
		.d_bin(d_bin), 
		.q_one_hot(q_one_hot)
	);

	initial begin
		d_bin = {BIN_WIDTH{1'b0}};
		#200;
		repeat(100) begin
			d_bin = d_bin + 1;
			#200;
		end
        
	end
	
endmodule

仿真波形见下图:

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/680399.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号