Attention

This documentation is a work in progress. Expect to see errors and unfinished things.

mixer Source File

 1`timescale 1ns / 1ns
 2
 3module mixer #(
 4   parameter NORMALIZE = 0,
 5   parameter NUM_DROP_BITS = 1, // Number of bits to drop at the output.
 6                                // The typical case is where mult is never
 7                                // -FS, so we can drop at least 1 redundant
 8                                // sign bit from the output
 9   parameter dwi       = 16, // Width of ADC input
10   parameter davr      = 4,  // Guard bits to keep at output. E.g. if downstream
11                             // CIC averaging is 64, the useful data increase is sqrt(64),
12                             // so add 3 bits; 4 bits to account for rounding error
13   parameter dwlo      = 18  // Width of local-oscillator input
14) (
15   input                        clk,
16   input  signed [dwi-1:0]      adcf,
17   input  signed [dwlo-1:0]     mult,
18   output signed [dwi+davr-1:0] mixout
19);
20
21   reg signed [dwi-1+davr:0] mixout_r = 0;
22   reg signed [dwi-1:0]      adcf1 = 0;
23   reg signed [dwlo-1:0]     mult1 = 0;
24   reg signed [dwi+dwlo-1:0] mix_out_r = 0;
25   reg signed [dwi-1+davr:0] mix_out1 = 0, mix_out2 = 0;
26
27   generate
28   if (NORMALIZE==1) begin : g_normalize
29      reg  signed [dwi+dwlo-1:0] mixmulti=0;
30      wire signed [dwi+dwlo-1:0] mix_out_w=mixmulti;//adcf*mult;
31      always @(posedge clk) begin
32         mixmulti <= adcf * mult;
33         mixout_r <= mix_out_w[dwi+dwlo-1:dwlo-davr] + mix_out_w[dwlo-davr-1];
34      end
35      assign mixout = mixout_r;
36   end
37   else begin : ng_normalize
38      always @(posedge clk) begin
39         adcf1     <= adcf;
40         mult1     <= mult;
41         mix_out_r <= adcf1 * mult1;  // internal multiplier pipeline
42         mix_out1  <= mix_out_r[dwi+dwlo-NUM_DROP_BITS-1:dwlo-davr-NUM_DROP_BITS];
43         mix_out2  <= mix_out1;
44      end
45      assign mixout = mix_out2;
46   end
47   endgenerate
48
49endmodule