Attention
This documentation is a work in progress. Expect to see errors and unfinished things.
flevel_set Source File
1`timescale 1ns / 1ns
2
3// Name: Set carrier level from I and Q
4//% Provide LO at cosd and sind ports
5// Essentially a dot product of the LO signal [cosd, sind] with [i_data, q_data]
6// N.B.: full-scale negative is an invalid LO value.
7module flevel_set #(
8 parameter i_dw=17, // XXX don't change this
9 parameter q_dw=17, // XXX don't change this
10 parameter o_dw=16 // XXX don't change this
11) (
12 input clk,
13 input signed [17:0] cosd, // LO input
14 input signed [17:0] sind, // LO input
15 input signed [i_dw-1:0] i_data,
16 input i_gate,
17 input i_trig, // I baseband
18 input signed [q_dw-1:0] q_data,
19 input q_gate,
20 input q_trig, // Q baseband
21 output signed [o_dw-1:0] o_data,
22 output o_gate, o_trig, // carrier
23 output time_err
24);
25
26`define SAT(x,old,new) ((~|x[old:new] | &x[old:new]) ? x[new:0] : {x[old],{new{~x[old]}}})
27reg signed [34:0] cosp = 0, sinp = 0; // 17-bit i_data * 18-bit cosd
28wire signed [16:0] cosp_msb = cosp[33:17];
29wire signed [16:0] sinp_msb = sinp[33:17];
30reg signed [17:0] sum = 0;
31reg signed [16:0] sum2 = 0;
32always @(posedge clk) begin
33 cosp <= i_data * cosd;
34 sinp <= q_data * sind;
35 sum <= cosp_msb + sinp_msb + 1;
36 sum2 <= `SAT(sum,17,16);
37end
38
39reg time_err_r=0;
40always @(posedge clk) begin
41 time_err_r <= ~i_gate | ~q_gate;
42end
43
44`undef SAT
45
46assign o_data = sum2[16:1];
47assign o_gate = 1'b1;
48assign o_trig = 1'b0;
49assign time_err = time_err_r;
50
51endmodule