fpga-lab-2/HDL/sdmod.sv

24 lines
448 B
Systemverilog
Raw Normal View History

2023-01-27 17:06:29 +03:00
module sdmod (
input signed [7:0] val,
input clk,
input reset,
output daco
);
logic out;
logic signed [7:0] eps;
2023-02-07 16:10:37 +03:00
logic signed [8:0] un;
2023-01-27 17:06:29 +03:00
always_ff @(posedge clk, negedge reset) begin
if (~reset) begin
2023-02-07 16:10:37 +03:00
un <= 9'd0;
2023-01-27 17:06:29 +03:00
end else begin
un <= val - eps;
end
end
2023-02-07 16:10:37 +03:00
assign out = (un >= $signed(9'd0)) ? 1'd1 : 1'd0;
assign eps = (un >= $signed(9'd0)) ? $signed(9'd126) - un : $signed(-9'd126) - un;
assign daco = out;
2023-01-27 17:06:29 +03:00
endmodule