11module adc_ltc2308 (
2- clk, // max 40mhz
3-
4- // start measure
5- measure_start, // posedge triggle
6- measure_ch,
7- measure_done,
8- measure_dataread ,
9-
10- // adc interface
11- ADC_CONVST,
12- ADC_SCK,
13- ADC_SDI,
14- ADC_SDO
2+ clk, // max 40mhz
3+
4+ // start measure
5+ measure_start, // posedge triggle
6+ measure_ch,
7+ measure_done,
8+ measured_data ,
9+
10+ // adc interface
11+ ADC_CONVST,
12+ ADC_SCK,
13+ ADC_SDI,
14+ ADC_SDO
1515);
1616
17- input clk;
17+ input clk;
1818
1919// start measure
20- input measure_start;
21- input [2 :0 ] measure_ch;
22- output reg measure_done;
23- output [11 :0 ] measure_dataread ;
20+ input measure_start;
21+ input [2 :0 ] measure_ch;
22+ output reg measure_done;
23+ output reg [11 :0 ] measured_data ;
2424
2525
2626
27- output ADC_CONVST;
28- output ADC_SCK;
29- output reg ADC_SDI;
30- input ADC_SDO;
27+ output ADC_CONVST;
28+ output ADC_SCK;
29+ output reg ADC_SDI;
30+ input ADC_SDO;
3131
3232
3333// ///////////////////////////////
34- // Timing definition
34+ // Timing definition
3535
3636// using 40MHz clock
3737// to acheive fsample = 500KHz
3838// ntcyc = 2us / 25ns = 80
3939
4040
4141
42- `define DATA_BITS_NUM 12
43- `define CMD_BITS_NUM 6
44- `define CH_NUM 8
42+ `define DATA_BITS_NUM 12
43+ `define CMD_BITS_NUM 6
44+ `define CH_NUM 8
4545
46- `define tWHCONV 1 // CONVST High Time, min 20 ns
47- `define tCONV 64 // 52 // tCONV: type 1.3 us, MAX 1.6 us, 1600/25(assumed clk is 40mhz)=64 -> 1.3us/25ns = 52
48- // set 64 for suite for 1.6 us max
49- // +12 //data
46+ `define tWHCONV 1 // CONVST High Time, min 20 ns
47+ `define tCONV 64 // 52 // tCONV: type 1.3 us, MAX 1.6 us, 1600/25(assumed clk is 40mhz)=64 -> 1.3us/25ns = 52
48+ // set 64 for suite for 1.6 us max
49+ // +12 //data
5050
51- `define tHCONVST 320 // 12 // here set 320( fsample = 100KHz) for if ADC input impedance is high, see below
51+ `define tHCONVST 320 // 12 // here set 320( fsample = 100KHz) for if ADC input impedance is high, see below
5252 // If the source impedance of the driving circuit is low, the ADC inputs can be driven directly.
5353 // Otherwise, more acquisition time should be allowed for a source with higher impedance.
5454
55- // for acheiving 500KHz fmax. set n cyc = 80.
56- `define tCONVST_HIGH_START 0
57- `define tCONVST_HIGH_END (`tCONVST_HIGH_START+ `tWHCONV)
55+ // for acheiving 500KHz fmax. set n cyc = 80.
56+ `define tCONVST_HIGH_START 0
57+ `define tCONVST_HIGH_END (`tCONVST_HIGH_START+ `tWHCONV)
5858
59- `define tCONFIG_START (`tCONVST_HIGH_END)
60- `define tCONFIG_END (`tCLK_START+ `CMD_BITS_NUM - 1 )
59+ `define tCONFIG_START (`tCONVST_HIGH_END)
60+ `define tCONFIG_END (`tCLK_START+ `CMD_BITS_NUM - 1 )
6161
62- `define tCLK_START (`tCONVST_HIGH_START+ `tCONV)
63- `define tCLK_END (`tCLK_START+ `DATA_BITS_NUM)
62+ `define tCLK_START (`tCONVST_HIGH_START+ `tCONV)
63+ `define tCLK_END (`tCLK_START+ `DATA_BITS_NUM)
6464
65- `define tDONE (`tCLK_END+ `tHCONVST)
65+ `define tDONE (`tCLK_END+ `tHCONVST)
6666
6767// create triggle message: reset_n
6868reg pre_measure_start;
69- always @ (posedge clk)
69+ always @ (posedge clk)
7070begin
71- pre_measure_start <= measure_start;
71+ pre_measure_start <= measure_start;
7272end
7373
7474wire reset_n;
7575assign reset_n = (! pre_measure_start & measure_start)?1'b0 :1'b1 ;
7676
7777// tick
78- reg [15 :0 ] tick;
79- always @ (posedge clk or negedge reset_n)
78+ reg [15 :0 ] tick;
79+ always @ (posedge clk or negedge reset_n)
8080begin
81- if (! reset_n)
82- tick <= 0 ;
83- else if (tick < `tDONE)
84- tick <= tick + 1 ;
81+ if (! reset_n)
82+ tick <= 0 ;
83+ else if (tick < `tDONE)
84+ tick <= tick + 1 ;
8585end
8686
8787
8888// ///////////////////////////////
89- // ADC_CONVST
89+ // ADC_CONVST
9090assign ADC_CONVST = (tick >= `tCONVST_HIGH_START && tick < `tCONVST_HIGH_END)?1'b1 :1'b0 ;
9191
9292// ///////////////////////////////
93- // ADC_SCK
93+ // ADC_SCK
9494
9595reg clk_enable; // must sync to clk in clk low
96- always @ (negedge clk or negedge reset_n)
96+ always @ (negedge clk or negedge reset_n)
9797begin
98- if (! reset_n)
99- clk_enable <= 1'b0 ;
100- else if ((tick >= `tCLK_START && tick < `tCLK_END))
101- clk_enable <= 1'b1 ;
102- else
103- clk_enable <= 1'b0 ;
98+ if (! reset_n)
99+ clk_enable <= 1'b0 ;
100+ else if ((tick >= `tCLK_START && tick < `tCLK_END))
101+ clk_enable <= 1'b1 ;
102+ else
103+ clk_enable <= 1'b0 ;
104104end
105105
106106assign ADC_SCK = clk_enable?clk:1'b0 ;
107107
108108
109109// /////////////////////////////
110110// read data
111- reg [(`DATA_BITS_NUM- 1 ):0 ] read_data ;
111+ // reg [(`DATA_BITS_NUM-1):0] measured_data ;
112112reg [3 :0 ] write_pos;
113113
114114
115115
116- assign measure_dataread = read_data ;
116+ assign measured_data = measured_data ;
117117
118- always @ (negedge clk or negedge reset_n)
118+ always @ (negedge clk or negedge reset_n)
119119begin
120- if (! reset_n)
121- begin
122- read_data <= 0 ;
123- write_pos <= `DATA_BITS_NUM- 1 ;
124- end
125- else if (clk_enable)
126- begin
127- read_data [write_pos] <= ADC_SDO;
128- write_pos <= write_pos - 1 ;
129- end
120+ if (! reset_n)
121+ begin
122+ measured_data <= 0 ;
123+ write_pos <= `DATA_BITS_NUM- 1 ;
124+ end
125+ else if (clk_enable)
126+ begin
127+ measured_data [write_pos] <= ADC_SDO;
128+ write_pos <= write_pos - 1 ;
129+ end
130130end
131131
132132// /////////////////////////////
@@ -135,12 +135,12 @@ wire read_ch_done;
135135
136136assign read_ch_done = (tick == `tDONE)?1'b1 :1'b0 ;
137137
138- always @ (posedge clk or negedge reset_n)
138+ always @ (posedge clk or negedge reset_n)
139139begin
140- if (! reset_n)
141- measure_done <= 1'b0 ;
142- else if (read_ch_done)
143- measure_done <= 1'b1 ;
140+ if (! reset_n)
141+ measure_done <= 1'b0 ;
142+ else if (read_ch_done)
143+ measure_done <= 1'b1 ;
144144end
145145
146146// /////////////////////////////
@@ -150,25 +150,25 @@ end
150150reg [(`CMD_BITS_NUM- 1 ):0 ] config_cmd;
151151
152152
153- `define UNI_MODE 1'b1 // 1: Unipolar, 0:Bipolar
154- `define SLP_MODE 1'b0 // 1: enable sleep
153+ `define UNI_MODE 1'b1 // 1: Unipolar, 0:Bipolar
154+ `define SLP_MODE 1'b0 // 1: enable sleep
155155
156156always @(negedge reset_n)
157157begin
158- if (! reset_n)
159- begin
160- case (measure_ch)
161- 0 : config_cmd <= {4'h8 , `UNI_MODE, `SLP_MODE};
162- 1 : config_cmd <= {4'hC , `UNI_MODE, `SLP_MODE};
163- 2 : config_cmd <= {4'h9 , `UNI_MODE, `SLP_MODE};
164- 3 : config_cmd <= {4'hD , `UNI_MODE, `SLP_MODE};
165- 4 : config_cmd <= {4'hA , `UNI_MODE, `SLP_MODE};
166- 5 : config_cmd <= {4'hE , `UNI_MODE, `SLP_MODE};
167- 6 : config_cmd <= {4'hB , `UNI_MODE, `SLP_MODE};
168- 7 : config_cmd <= {4'hF , `UNI_MODE, `SLP_MODE};
169- default : config_cmd <= {4'hF , 2'b00 };
170- endcase
171- end
158+ if (! reset_n)
159+ begin
160+ case (measure_ch)
161+ 0 : config_cmd <= {4'h8 , `UNI_MODE, `SLP_MODE};
162+ 1 : config_cmd <= {4'hC , `UNI_MODE, `SLP_MODE};
163+ 2 : config_cmd <= {4'h9 , `UNI_MODE, `SLP_MODE};
164+ 3 : config_cmd <= {4'hD , `UNI_MODE, `SLP_MODE};
165+ 4 : config_cmd <= {4'hA , `UNI_MODE, `SLP_MODE};
166+ 5 : config_cmd <= {4'hE , `UNI_MODE, `SLP_MODE};
167+ 6 : config_cmd <= {4'hB , `UNI_MODE, `SLP_MODE};
168+ 7 : config_cmd <= {4'hF , `UNI_MODE, `SLP_MODE};
169+ default : config_cmd <= {4'hF , 2'b00 };
170+ endcase
171+ end
172172end
173173
174174// serial config command to adc chip
@@ -177,27 +177,24 @@ wire config_enable;
177177wire config_done;
178178reg [2 :0 ] sdi_index;
179179
180- assign config_init = (tick == `tCONFIG_START)?1'b1 :1'b0 ;
180+ assign config_init = (tick == `tCONFIG_START)?1'b1 :1'b0 ;
181181assign config_enable = (tick > `tCLK_START && tick <= `tCONFIG_END)?1'b1 :1'b0 ; // > because this is negative edge triggle
182- assign config_done = (tick > `tCONFIG_END)?1'b1 :1'b0 ;
183- always @(negedge clk)
182+ assign config_done = (tick > `tCONFIG_END)?1'b1 :1'b0 ;
183+ always @(negedge clk)
184184begin
185- if (config_init)
186- begin
187- ADC_SDI <= config_cmd[`CMD_BITS_NUM- 1 ];
188- sdi_index <= `CMD_BITS_NUM- 2 ;
189- end
190- else if (config_enable)
191- begin
192- ADC_SDI <= config_cmd[sdi_index];
193- sdi_index <= sdi_index - 1 ;
194- end
195- else if (config_done)
196- ADC_SDI <= 1'b0 ; //
185+ if (config_init)
186+ begin
187+ ADC_SDI <= config_cmd[`CMD_BITS_NUM- 1 ];
188+ sdi_index <= `CMD_BITS_NUM- 2 ;
189+ end
190+ else if (config_enable)
191+ begin
192+ ADC_SDI <= config_cmd[sdi_index];
193+ sdi_index <= sdi_index - 1 ;
194+ end
195+ else if (config_done)
196+ ADC_SDI <= 1'b0 ; //
197197end
198198
199-
200-
201-
202199endmodule
203200
0 commit comments