码迷,mamicode.com
首页 > 其他好文 > 详细

ADC TEST

时间:2016-01-28 01:57:58      阅读:225      评论:0      收藏:0      [点我收藏+]

标签:

  1 `timescale 1ns / 1ps
  2 //////////////////////////////////////////////////////////////////////////////////
  3 // Company: 
  4 // Engineer: 
  5 // 
  6 // Create Date:    13:33:13 10/23/2015 
  7 // Design Name: 
  8 // Module Name:    adc_test 
  9 // Project Name: 
 10 // Target Devices: 
 11 // Tool versions: 
 12 // Description: 
 13 //
 14 // Dependencies: 
 15 //
 16 // Revision: 
 17 // Revision 0.01 - File Created
 18 // Additional Comments: 
 19 //
 20 //////////////////////////////////////////////////////////////////////////////////
 21  module adc_test
 22     (
 23         input sys_clk,
 24         input    sys_rst,
 25         
 26         input    [9:0] adc_din,
 27         input  adc_finish,
 28         
 29         output adc_enb,
 30         output     adc_samp_en,
 31         output   adc_go,
 32         output     adc_samp,
 33         output     adc_clk,
 34         output    [2:0] adc_M_out,
 35         
 36         //inout sda,
 37         //output scl,
 38         
 39 //        input            uart_rx,
 40         output         uart_tx
 41 );
 42 
 43 
 44 reg    [7:0]        tx_data;
 45 reg    tx_en;
 46 wire    tx_done;
 47 uart_tx U1
 48 (
 49     .sys_clk(sys_clk),
 50     .rst(sys_rst),
 51     .tx_en(tx_en),
 52     .tx_data(tx_data),
 53     .tx_done(tx_done),
 54     .tx_pin_out(uart_tx)
 55 );    
 56 
 57 /*wire [11:0] adc_out;
 58 
 59 adc_module U2
 60 (
 61         .sys_clk(sys_clk),//100MHz
 62         .rst_n(sys_rst),
 63         
 64         .sda(sda),
 65         .scl(scl),
 66         .data(adc_out)
 67 );
 68 
 69 wire  adc_enb_1;
 70 
 71 wire [2:0] M_in;
 72 
 73 wire [9:0] adc_out1; 
 74 adc_test_module U3
 75 (
 76         .sys_clk(sys_clk),
 77         .sys_rst(sys_rst),
 78         
 79         .adc_din(adc_din),
 80         .adc_finish(adc_finish),
 81         
 82         .adc_enb(adc_enb_1),
 83         .adc_samp_en(adc_samp_en),
 84         .adc_go(adc_go),
 85         .adc_samp(adc_samp),
 86         .adc_clk(adc_clk),
 87         
 88         .adc_out(adc_out1),
 89         .M_out(M_in)
 90 
 91 );
 92 
 93 
 94 reg L2H_F1;
 95 reg L2H_F2;
 96 reg L2H_sw;
 97 reg L2H_sw1;
 98 wire L2H_Sig;
 99 
100 always @(posedge sys_clk)
101 begin
102     if(sys_rst)begin
103         L2H_F1 <= 1‘b1;
104         L2H_F2 <= 1‘b1;
105     end else begin
106         L2H_F1 <= adc_enb_1;        
107         L2H_F2 <= L2H_F1;
108 
109     end
110 end
111 assign L2H_Sig = !L2H_F1 & L2H_F2;
112 */
113 reg [2:0] state;
114 reg [7:0] tx_L;
115 reg [7:0] tx_H;
116 reg [7:0] tx_H2;
117 reg tx_start;
118 reg [15:0]delay_cont;
119 reg adc_io;
120 wire [9:0]adc_data;
121 reg [11:0]adc_data0;
122 reg [11:0]adc_data1;
123 //reg [11:0]adc_data2;
124 //reg [11:0]adc_data3;
125 wire [11:0]adc_data5;
126 assign adc_data5 = adc_out;
127 wire [11:0]adc_data4;
128 reg adc_data0_0;
129 //assign adc_data = {~adc_out};
130 reg uart_out = 0;
131 reg [15:0] M_delay = 0;
132 always @(posedge sys_clk)
133 begin
134     if(L2H_F1 & !L2H_F2)begin
135             case(M_in)
136                 3d0:begin
137                         adc_data0 <={adc_data[9:0],2b00};
138     //                    adc_data0_0 <= adc_data0[2];
139                       end
140                 3d1:begin
141                         adc_data1[0] <= {adc_data[0]};
142     //                    adc_data0_0 <=adc_data0[2:2];
143                       end
144                 3d3:begin
145                         adc_data1[1] <= {adc_data[0]};
146                         end
147                 3d7:begin
148                         adc_data1[2] <= {adc_data[0]};
149                         uart_out <= 1;
150                       end
151             endcase
152     end
153     else begin
154             uart_out <= 0;
155     end
156 end
157 //assign adc_data4 = adc_data0[2] ?  ((!adc_data1[0]) + (!adc_data1[1]) + (!adc_data1[2]))  : (adc_data1[0] + adc_data1[1] + adc_data1[2]);
158 //assign adc_data5 = adc_data4 + adc_data0;
159 
160 always @(posedge sys_clk)
161 begin
162     if(sys_rst)begin
163         tx_en        <= 1b0;
164         state        <= 3d0;
165         tx_start <= 1d0;
166         delay_cont <= 16d0;
167         adc_io <= 1b1; 
168     end else begin
169         if(uart_out)begin
170             state <= 3d0;
171             delay_cont <= 16d0;
172             tx_start <= 1d1;
173         end else begin
174             case(state)
175                 3d0:
176                     begin
177 //                        adc_data4 <= adc_data0 + adc_data0[2] +  adc_data1[2] + adc_data2[2] + adc_data3[2];
178                         delay_cont <= delay_cont + 16d1;
179                         if(delay_cont == 16d32000) begin
180                                 delay_cont <= 16d0;
181                                 state          <= 3d1;
182                                 
183                                 case(adc_data5[3:0])
184                                     4d0:  tx_L <= 8h30;
185                                     4d1:  tx_L <= 8h31;
186                                     4d2:  tx_L <= 8h32;
187                                     4d3:  tx_L <= 8h33;
188                                     4d4:  tx_L <= 8h34;
189                                     4d5:  tx_L <= 8h35;
190                                     4d6:  tx_L <= 8h36;
191                                     4d7:  tx_L <= 8h37;
192                                     4d8:  tx_L <= 8h38;
193                                     4d9:   tx_L <= 8h39;
194                                     4d10:  tx_L <= 8h41;
195                                     4d11:  tx_L <= 8h42;
196                                     4d12: tx_L <= 8h43;
197                                     4d13:  tx_L <= 8h44;
198                                     4d14:  tx_L <= 8h45;
199                                     4d15:  tx_L <= 8h46;
200                                     default:begin tx_L <= 8h58;end
201                                 endcase
202                                 case(adc_data5[7:4])
203                                     4d0: begin tx_H <= 8h30; end
204                                     4d1:begin tx_H <= 8h31;end
205                                     4d2:begin tx_H <= 8h32;end
206                                     4d3:begin tx_H <= 8h33;end
207                                     4d4:begin tx_H <= 8h34;end
208                                     4d5:begin tx_H <= 8h35;end
209                                     4d6:begin tx_H <= 8h36;end
210                                     4d7:begin tx_H <= 8h37;end
211                                     4d8:begin tx_H <= 8h38;end
212                                     4d9:begin tx_H <= 8h39;end
213                                     4d10:begin  tx_H <= 8h41;end
214                                     4d11:begin  tx_H <= 8h42;end
215                                     4d12:begin  tx_H <= 8h43;end
216                                     4d13:begin  tx_H <= 8h44;end
217                                     4d14:begin  tx_H <= 8h45;end
218                                     4d15:begin  tx_H <= 8h46;end
219                                     default:begin tx_H <= 8h58;end
220                                 endcase    
221                                 case(adc_data5[11:8])
222                                     4d0:  tx_H2 <= 8h30;
223                                     4d1:  tx_H2 <= 8h31;
224                                     4d2:  tx_H2 <= 8h32;
225                                     4d3:  tx_H2 <= 8h33;
226                                     4d4:  tx_H2 <= 8h34;
227                                     4d5:  tx_H2 <= 8h35;
228                                     4d6:  tx_H2 <= 8h36;
229                                     4d7:  tx_H2 <= 8h37;
230                                     4d8:  tx_H2 <= 8h38;
231                                     4d9:   tx_H2 <= 8h39;
232                                     4d10:  tx_H2 <= 8h41;
233                                     4d11:  tx_H2 <= 8h42;
234                                     4d12:  tx_H2 <= 8h43;
235                                     4d13:  tx_H2 <= 8h44;
236                                     4d14:  tx_H2 <= 8h45;
237                                     4d15:  tx_H2 <= 8h46;
238                                     default:tx_H2 <= 8h58;
239                                 endcase    
240                                 adc_io <= 1b1;
241                         end else if(delay_cont == 16d1000) begin
242                                 adc_io <= 1b0;
243                         end else begin
244                             delay_cont <= delay_cont + 16d1;
245                         end
246                     end
247                     
248                 3d1:
249                     begin
250                         if(tx_start == 1d1) 
251                             begin
252                                 tx_en        <= 1b1;
253                                 tx_data    <= tx_H2;
254                                 tx_start    <= 1d0;
255                             end else if(tx_done) begin
256                                 tx_en        <= 1b0;
257                                 tx_start    <= 1d1;
258                                 state <= state +3d1;
259                             end
260                     end
261                  3d2:
262                     begin
263                             if(tx_start == 1d1) 
264                             begin
265                                 tx_en        <= 1b1;
266                                 tx_data    <= tx_H;
267                                 tx_start    <= 1d0;
268                             end else if(tx_done) begin
269                                 tx_en        <= 1b0;
270                                 tx_start    <= 1d1;
271                                 state <= state +3d1;
272                             end
273                     end
274                 3d3:
275                     begin
276                             if(tx_start == 1d1) 
277                             begin
278                                 tx_en        <= 1b1;
279                                 tx_data    <= tx_L;
280                                 tx_start    <= 1d0;
281                             end else if(tx_done) begin
282                                 tx_en        <= 1b0;
283                                 tx_start    <= 1d1;
284                                 state <= state +3d1;
285                             end
286                     end
287                 3d4:
288                     begin
289                             if(tx_start == 1d1) 
290                             begin
291                                 tx_en        <= 1b1;
292                                 tx_data    <= 8h0A;
293                                 tx_start    <= 1d0;
294                             end else if(tx_done) begin
295                                 tx_en        <= 1b0;
296                                 tx_start    <= 1d1;
297                                 state <= state +3d1;
298                             end
299                     end
300                 3d5:
301                     begin
302                             if(tx_start == 1d1) 
303                             begin
304                                 tx_en        <= 1b1;
305                                 tx_data    <= 8h0d;
306                                 tx_start    <= 1d0;
307                             end else if(tx_done) begin
308                                 tx_en        <= 1b0;
309                                 tx_start    <= 1d1;
310                                 state <= 3d6;
311                             end
312                     end
313                  default: state <= 3d6;
314             endcase    
315          end
316     end
317 end
318 assign adc_enb = adc_io;
319 assign adc_M_out = M_in;
320 endmodule

 

ADC TEST

标签:

原文地址:http://www.cnblogs.com/loves6036/p/5165014.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!