Attention
This documentation is a work in progress. Expect to see errors and unfinished things.
doublediff Source File
1`timescale 1ns / 1ns
2// Differentiate when the gate is HIGH
3module doublediff #(
4 parameter dw=28,
5 parameter dsr_len=4
6) (
7 input clk,
8 input [dw-1:0] d_in, // Input data
9 input g_in, // A gate when set to high differentiates input data
10 output [dw-1:0] d_out,
11 output g_out
12);
13
14reg signed [dw-1:0] d1=0, d2=0;
15reg valid1=0, valid2=0;
16wire [dw-1:0] dpass1, dpass2;
17wire svalid=g_in;
18
19reg_delay #(.dw(dw), .len(dsr_len))
20 s1(.clk(clk), .reset(1'b0), .gate(svalid), .din(d_in), .dout(dpass1));
21
22reg_delay #(.dw(dw), .len(dsr_len))
23 s2(.clk(clk), .reset(1'b0), .gate(valid1), .din(d1), .dout(dpass2));
24
25always @(posedge clk) begin
26 if (svalid) d1 <= d_in - dpass1;
27 valid1 <= svalid;
28 if (valid1) d2 <= d1 - dpass2;
29 valid2 <= valid1;
30end
31assign d_out = d2;
32assign g_out = valid2;
33endmodule