// QPSK transmitter: Gray mapper, zero-stuffing upsampler, RRC pulse shaping // on I and Q, and an NCO mixer. One output sample per clock, SPS samples // per symbol. A symbol is accepted when sym_valid and sym_ready are both // high; sym_ready is high in one clock out of every SPS. If no symbol is // offered at that moment, the filters receive zeros. `timescale 1ns / 1ps module qpsk_tx #( parameter int SPS = 8, parameter int NTAPS = 49, parameter TAP_FILE = "rrc_taps.hex", parameter SINE_FILE = "sine256.hex" ) ( input logic clk, input logic rst, input logic [31:0] tuning_word, input logic sym_valid, input logic [1:0] sym_bits, output logic sym_ready, output logic signed [15:0] i_bb, // shaped baseband I (Q1.15) output logic signed [15:0] q_bb, // shaped baseband Q (Q1.15) output logic signed [15:0] s_out // passband sample ); localparam int CW = $clog2(SPS); // SPS must be 2 or more logic [CW-1:0] cnt; logic signed [1:0] i_sym, q_sym, i_x, q_x; always_ff @(posedge clk) begin if (rst || cnt == CW'(SPS - 1)) cnt <= '0; else cnt <= cnt + 1'b1; end assign sym_ready = (cnt == '0); qpsk_mapper u_map (.bits(sym_bits), .i_sym(i_sym), .q_sym(q_sym)); // Upsample by SPS: the symbol in one sample, zeros in the others. assign i_x = (sym_valid && sym_ready) ? i_sym : 2'sd0; assign q_x = (sym_valid && sym_ready) ? q_sym : 2'sd0; pulse_shaper #(.NTAPS(NTAPS), .TAP_FILE(TAP_FILE)) u_fir_i ( .clk(clk), .rst(rst), .x_in(i_x), .y(i_bb)); pulse_shaper #(.NTAPS(NTAPS), .TAP_FILE(TAP_FILE)) u_fir_q ( .clk(clk), .rst(rst), .x_in(q_x), .y(q_bb)); nco_mixer #(.SINE_FILE(SINE_FILE)) u_mix ( .clk(clk), .rst(rst), .tuning_word(tuning_word), .i_in(i_bb), .q_in(q_bb), .s_out(s_out)); endmodule