source: sandbox/MultiChannelUSB/adc_lvds.v@ 140

Last change on this file since 140 was 140, checked in by demin, 13 years ago

adapt to afe8551

File size: 2.7 KB
Line 
1module adc_lvds
2 #(
3 parameter size = 8, // number of channels
4 parameter width = 24 // channel resolution
5 )
6 (
7 input wire clock,
8
9 input wire lvds_dco,
10 input wire lvds_fco,
11 input wire [size-1:0] lvds_d,
12
13 output wire adc_frame,
14 output wire [size*width-1:0] adc_data
15
16 );
17 localparam width2 = width + 1;
18
19 reg state, int_rdreq, adc_frame_reg;
20 wire int_wrfull, int_rdempty;
21
22 reg [size-1:0] int_data_p, int_data_n;
23
24 reg [2:0] int_edge_reg;
25
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;
34
35
36
37 genvar j;
38
39 generate
40 for (j = 0; j < size; j = j + 1)
41 begin : INT_DATA
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];
48 end
49 endgenerate
50
51 dcfifo #(
52 .intended_device_family("Cyclone III"),
53 .lpm_numwords(16),
54 .lpm_showahead("ON"),
55 .lpm_type("dcfifo"),
56 .lpm_width(size*width),
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 (
63// .data(int_data_wire),
64 .data(int_fifo_reg),
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());
77
78 always @ (posedge clock)
79 begin
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
99 end
100
101 always @ (negedge lvds_dco)
102 begin
103 int_data_n <= lvds_d;
104 end
105
106 always @ (posedge lvds_dco)
107 begin
108 int_data_p <= lvds_d;
109 int_data_reg <= int_data_wire;
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
115 end
116
117 assign adc_frame = adc_frame_reg;
118 assign adc_data = adc_data_reg;
119
120endmodule
Note: See TracBrowser for help on using the repository browser.