File: iq_to_float.v

package info (click to toggle)
uhd 3.7.3-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 456,376 kB
  • ctags: 89,637
  • sloc: ansic: 51,090; cpp: 42,755; xml: 19,627; vhdl: 12,678; tcl: 5,944; python: 5,870; ada: 2,760; sh: 2,175; makefile: 615; pascal: 230; csh: 224; perl: 11
file content (92 lines) | stat: -rw-r--r-- 1,570 bytes parent folder | download | duplicates (4)
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
module iq_to_float
  
  #(parameter BITS_IN =16,
    parameter BITS_OUT = 32
    )

   (
    input [15:0] in,
    output [31:0] out

    );

   //imaginary
   

   //2s complement
   wire [15:0] unsigned_mag;
   wire [15:0] complement;
 
   //leading bit registers
   wire [15:0] lead;
   wire [15:0] reversed_mag;
   
   //16-4 encoder
   wire [3:0] binary_out;

   wire [22:0] fraction;
   wire [7:0] exponent;

   wire [15:0] binary_in;
   
   binary_encoder #(.SIZE(16))
   encoding
     (.in(binary_in),.out(binary_out));
   
   

   
  
   
   // Detect sign, if negative detected perform 2's complement
   
   assign unsigned_mag = (in[15] == 1)?((~in[15:0])+1'b1):in[15:0];

   //detect leading one 
   
   assign complement = ((~reversed_mag[BITS_IN-1:0])+1'b1);
   
   assign lead = complement & reversed_mag;

   
   
   
   
   //calculate fraction and exponent using shift value generated

  wire [15:0] pre_frac = unsigned_mag << ((15 - binary_out));
  assign fraction = {pre_frac[14:0],8'h0};
  assign exponent = (in == 16'b0)?(8'b0):(binary_out +'d127);


      
   
   //construct the output
   assign out = {in[15], exponent, fraction};

   //reverse the signed input

   genvar r;
   
   generate
      for (r = 0; r < 16; r = r+1) begin:bit_reverse
	assign reversed_mag[r] = unsigned_mag[BITS_IN-r-1];
      end
   endgenerate

   //reversed the output of the detect the leading bit procedure

   genvar i;
    generate 
	for (i= 0; i < 16; i = i+1) begin: i_rev
			assign binary_in[i] = lead[BITS_IN-i-1];
	end
	endgenerate 
	
   
   


endmodule