source: sandbox/MultiChannelUSB/adc_lvds.v@ 148

Last change on this file since 148 was 148, checked in by demin, 14 years ago

correctly working version

File size: 2.8 KB
Line 
1
2(* ALTERA_ATTRIBUTE = {"{-to int_data_p} DDIO_INPUT_REGISTER=HIGH; {-to int_data_n} DDIO_INPUT_REGISTER=LOW"} *)
3
4module adc_lvds
5 #(
6 parameter size = 8, // number of channels
7 parameter width = 24 // channel resolution
8 )
9 (
10 input wire clock,
11
12 input wire lvds_dco,
13 input wire lvds_fco,
14 input wire [size-1:0] lvds_d,
15
16 output wire adc_frame,
17 output wire [size*width-1:0] adc_data
18
19 );
20 localparam width2 = width + 2;
21
22 reg state, int_rdreq, adc_frame_reg;
23 wire int_wrfull, int_rdempty;
24
25 reg [size-1:0] int_data_p, int_data_n;
26
27 reg [2:0] int_edge_reg;
28
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
35 wire [size*width-1:0] int_q_wire;
36 reg [size*width-1:0] adc_data_reg;
37
38
39
40 genvar j;
41
42 generate
43 for (j = 0; j < size; j = j + 1)
44 begin : INT_DATA
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
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];
51 end
52 endgenerate
53
54 dcfifo #(
55 .intended_device_family("Cyclone III"),
56 .lpm_numwords(16),
57 .lpm_showahead("ON"),
58 .lpm_type("dcfifo"),
59 .lpm_width(size*width),
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 (
66// .data(int_data_wire),
67 .data(int_fifo_reg),
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());
80
81 always @ (posedge clock)
82 begin
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
102 end
103
104 always @ (negedge lvds_dco)
105 begin
106 int_data_n <= lvds_d;
107 end
108
109 always @ (posedge lvds_dco)
110 begin
111 int_data_p <= lvds_d;
112 int_data_reg <= int_data_wire;
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
118 end
119
120 assign adc_frame = adc_frame_reg;
121 assign adc_data = adc_data_reg;
122
123endmodule
Note: See TracBrowser for help on using the repository browser.