-
Notifications
You must be signed in to change notification settings - Fork 0
/
ItoF.sv
99 lines (79 loc) · 2.08 KB
/
ItoF.sv
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Jose Jaime
// 3/6/20
// EE 371
// ItoF Module
//
// Converts Integers into Floats by implementing the Nios II floatingpoint IP Catalog
module ItoF #(parameter N = 1024, data_width = 24, fp_width = 32, mag_width = 9, MAX_X = 640, MAX_Y = 480)
(
input logic clk, rst, read,
input logic [data_width - 1:0] data_in,
output logic [fp_width - 1:0] ItoF_data,
output logic ItoF_done
);
// Control Flags
logic start_ItoF;
logic clk_en_ItoF;
// Current Sample
logic [data_width - 1:0] curr_sample;
enum {idle, processing} ps, ns;
// Signal span of valid data output
assign clk_en_ItoF = (ps == processing);
floatingpoint ItoF1 (.clk(clk), .clk_en(clk_en_ItoF), .dataa({{8{curr_sample[data_width - 1]}}, curr_sample}), .datab(0),
.n(2), .reset(rst), .reset_req(1'b0), .start(start_ItoF),
.done(ItoF_done), .result(ItoF_data));
always_comb begin
case (ps)
idle: if (read) ns = processing;
else ns = idle;
processing: if (ItoF_done) ns = idle;
else ns = processing;
endcase
end
always_ff @(posedge clk) begin
if (rst) begin
ps <= idle;
end else begin
ps <= ns;
end
end
always_ff @(posedge clk) begin
if (rst) begin
start_ItoF <= 1'b0;
end
// Signal start of data pipeline
if ((ps == idle) && read) begin
curr_sample <= data_in;
start_ItoF <= 1'b1;
end
if (start_ItoF) begin
start_ItoF <= 1'b0;
end
end
endmodule
`timescale 1 ps / 1 ps
module ItoF_testbench();
parameter N = 1024, data_width = 24, fp_width = 32, mag_width = 9, MAX_X = 640, MAX_Y = 480;
logic clk, rst, read;
logic [data_width - 1:0] data_in;
logic [fp_width - 1:0] ItoF_data;
logic ItoF_done;
ItoF dut (.*);
// Set up the clock
integer ctr;
parameter CLOCK_PERIOD = 100;
initial begin
ctr <= 0;
clk <= 0;
forever #(CLOCK_PERIOD / 2) clk <= ~clk;
end
initial begin
rst <= 1'b1; @(posedge clk);
rst <= 1'b0; @(posedge clk);
read <= 1'b1; @(posedge clk);
repeat (500) begin
read <= ~read; data_in <= ctr; ctr <= ctr + 1'b1; @(posedge clk);
end
$stop;
end
endmodule