[41] | 1 | module adc_lvds
|
---|
[63] | 2 | #(
|
---|
| 3 | parameter size = 3, // number of channels
|
---|
| 4 | parameter width = 12 // channel resolution
|
---|
| 5 | )
|
---|
[41] | 6 | (
|
---|
[107] | 7 | input wire clock,
|
---|
| 8 |
|
---|
[63] | 9 | input wire lvds_dco,
|
---|
| 10 | input wire lvds_fco,
|
---|
[72] | 11 | input wire [size-1:0] lvds_d,
|
---|
[41] | 12 |
|
---|
[107] | 13 | input wire [11:0] test,
|
---|
| 14 | input wire [11:0] trig,
|
---|
| 15 |
|
---|
| 16 | output wire adc_frame,
|
---|
| 17 | output wire [size*width-1+12:0] adc_data
|
---|
| 18 |
|
---|
[41] | 19 | );
|
---|
| 20 |
|
---|
[107] | 21 | reg state, int_rdreq, adc_frame_reg;
|
---|
| 22 | wire int_wrfull, int_rdempty;
|
---|
[41] | 23 |
|
---|
[107] | 24 | reg [size-1:0] int_data_h, int_data_l;
|
---|
[63] | 25 |
|
---|
[107] | 26 | reg [size*width-1:0] int_data_reg;
|
---|
| 27 | wire [size*width-1:0] int_data_wire;
|
---|
| 28 |
|
---|
| 29 | wire [size*width-1+12:0] int_q_wire;
|
---|
| 30 | reg [size*width-1+12:0] adc_data_reg;
|
---|
| 31 |
|
---|
| 32 |
|
---|
[63] | 33 | genvar j;
|
---|
| 34 |
|
---|
[107] | 35 | generate
|
---|
| 36 | for (j = 0; j < size-1; j = j + 1)
|
---|
| 37 | begin : INT_DATA
|
---|
| 38 | assign int_data_wire[j*width+width-1:j*width] = {int_data_reg[j*width+width-3:j*width], int_data_h[j], int_data_l[j]};
|
---|
| 39 | // assign int_data_wire[j*width+width-1:j*width] = test;
|
---|
| 40 | end
|
---|
| 41 | endgenerate
|
---|
| 42 | assign int_data_wire[(size-1)*width+width-1:(size-1)*width] = test;
|
---|
| 43 |
|
---|
| 44 | dcfifo #(
|
---|
[41] | 45 | .intended_device_family("Cyclone III"),
|
---|
[107] | 46 | .lpm_numwords(16),
|
---|
| 47 | .lpm_showahead("ON"),
|
---|
| 48 | .lpm_type("dcfifo"),
|
---|
| 49 | .lpm_width(size*width+12),
|
---|
| 50 | .lpm_widthu(4),
|
---|
| 51 | .rdsync_delaypipe(4),
|
---|
| 52 | .wrsync_delaypipe(4),
|
---|
| 53 | .overflow_checking("ON"),
|
---|
| 54 | .underflow_checking("ON"),
|
---|
| 55 | .use_eab("ON")) fifo_unit (
|
---|
| 56 | .data({trig, int_data_wire}),
|
---|
| 57 | .rdclk(clock),
|
---|
| 58 | .rdreq((~int_rdempty) & int_rdreq),
|
---|
| 59 | .wrclk(lvds_fco),
|
---|
| 60 | .wrreq(~int_wrfull),
|
---|
| 61 | .q(int_q_wire),
|
---|
| 62 | .rdempty(int_rdempty),
|
---|
| 63 | .wrfull(int_wrfull),
|
---|
| 64 | .aclr(),
|
---|
| 65 | .rdfull(),
|
---|
| 66 | .rdusedw(),
|
---|
| 67 | .wrempty(),
|
---|
| 68 | .wrusedw());
|
---|
[41] | 69 |
|
---|
[107] | 70 | always @ (posedge clock)
|
---|
[41] | 71 | begin
|
---|
[107] | 72 | case (state)
|
---|
| 73 | 1'b0:
|
---|
| 74 | begin
|
---|
| 75 | int_rdreq <= 1'b1;
|
---|
| 76 | adc_frame_reg <= 1'b0;
|
---|
| 77 | state <= 1'b1;
|
---|
| 78 | end
|
---|
| 79 |
|
---|
| 80 | 1'b1:
|
---|
| 81 | begin
|
---|
| 82 | if (~int_rdempty)
|
---|
| 83 | begin
|
---|
| 84 | int_rdreq <= 1'b0;
|
---|
| 85 | adc_frame_reg <= 1'b1;
|
---|
| 86 | adc_data_reg <= int_q_wire;
|
---|
| 87 | state <= 1'b0;
|
---|
| 88 | end
|
---|
| 89 | end
|
---|
| 90 | endcase
|
---|
[42] | 91 | end
|
---|
[107] | 92 |
|
---|
| 93 | always @ (negedge lvds_dco)
|
---|
[42] | 94 | begin
|
---|
[107] | 95 | int_data_l <= lvds_d;
|
---|
[41] | 96 | end
|
---|
| 97 |
|
---|
[107] | 98 | always @ (posedge lvds_dco)
|
---|
[42] | 99 | begin
|
---|
[107] | 100 | int_data_h <= lvds_d;
|
---|
| 101 | int_data_reg <= int_data_wire;
|
---|
[42] | 102 | end
|
---|
[41] | 103 |
|
---|
[107] | 104 | assign adc_frame = adc_frame_reg;
|
---|
| 105 | assign adc_data = adc_data_reg;
|
---|
[63] | 106 |
|
---|
[58] | 107 | endmodule
|
---|