source: trunk/3DEES/adc_lvds.v@ 181

Last change on this file since 181 was 178, checked in by demin, 11 years ago

adapt to 6ch

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