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