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