lin-win-share/DA4008_V1.3/model/DEM_Reverse.v

30 lines
794 B
Verilog
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

module DEM_Reverse (
input clk, // 时钟输入
input [6:0] therm_in, // 7位温度计码输入 (MSB部分)
input [4:0] bin_in, // 5位二进制码输入 (LSB部分)
output reg [7:0] data_out // 恢复的8位DAC输入
);
// 统计温度计码中1的个数权重总和
function [2:0] count_ones;
input [6:0] data;
integer i;
begin
count_ones = 0;
for (i = 0; i < 7; i = i + 1) begin
if (data[i]) count_ones = count_ones + 1;
end
end
endfunction
// 组合逻辑计算中间值
wire [2:0] msb_value = count_ones(therm_in);
wire [4:0] lsb_value = bin_in;
wire [7:0] data_comb = {msb_value, lsb_value};
// 在时钟上升沿寄存输出
always @(posedge clk) begin
data_out <= data_comb;
end
endmodule