OpenCores
URL https://opencores.org/ocsvn/openmsp430/openmsp430/trunk

Subversion Repositories openmsp430

[/] [openmsp430/] [trunk/] [fpga/] [altera_de0_nano_soc/] [doc/] [Terasic/] [DE0_NANO_SOC/] [Demonstrations/] [FPGA/] [DE0_NANO_SOC_ADC/] [DE0_NANO_SOC_QSYS/] [synthesis/] [submodules/] [adc_ltc2308.v] - Blame information for rev 221

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 221 olivier.gi
module 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
15
);
16
 
17
input                                                           clk;
18
 
19
// start measure
20
input                                                           measure_start;
21
input           [2:0]                                    measure_ch;
22
output  reg                                     measure_done;
23
output  [11:0]                           measure_dataread;
24
 
25
 
26
 
27
output                                  ADC_CONVST;
28
output                                  ADC_SCK;
29
output  reg                     ADC_SDI;
30
input                                   ADC_SDO;
31
 
32
 
33
/////////////////////////////////
34
// Timing definition 
35
 
36
// using 40MHz clock
37
// to acheive fsample = 500KHz
38
// ntcyc = 2us / 25ns  = 80
39
 
40
 
41
 
42
`define DATA_BITS_NUM           12
43
`define CMD_BITS_NUM                    6
44
`define CH_NUM                                  8
45
 
46
`define tWHCONV            3   // 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
50
 
51
`define tHCONVST           320 // 12  // here set 320( fsample = 100KHz) for if ADC input impedance is high, see below  
52
                                // If the source impedance of the driving circuit is low, the ADC inputs can be driven directly.
53
                                //Otherwise, more acquisition time should be allowed for a source with higher impedance.
54
 
55
                                                                                  // for acheiving 500KHz  fmax. set n cyc = 80.
56
`define tCONVST_HIGH_START      0
57
`define tCONVST_HIGH_END        (`tCONVST_HIGH_START+`tWHCONV)
58
 
59
`define tCONFIG_START           (`tCONVST_HIGH_END)
60
`define tCONFIG_END             (`tCLK_START+`CMD_BITS_NUM - 1)
61
 
62
`define tCLK_START                      (`tCONVST_HIGH_START+`tCONV)
63
`define tCLK_END                        (`tCLK_START+`DATA_BITS_NUM)
64
 
65
`define tDONE                           (`tCLK_END+`tHCONVST)
66
 
67
// create triggle message: reset_n
68
reg pre_measure_start;
69
always @ (posedge clk)
70
begin
71
        pre_measure_start <= measure_start;
72
end
73
 
74
wire reset_n;
75
assign reset_n = (~pre_measure_start & measure_start)?1'b0:1'b1;
76
 
77
// tick
78
reg [15:0] tick;
79
always @ (posedge clk or negedge reset_n)
80
begin
81
        if (~reset_n)
82
                tick <= 0;
83
        else if (tick < `tDONE)
84
                tick <= tick + 1;
85
end
86
 
87
 
88
/////////////////////////////////
89
// ADC_CONVST 
90
assign ADC_CONVST = (tick >= `tCONVST_HIGH_START && tick < `tCONVST_HIGH_END)?1'b1:1'b0;
91
 
92
/////////////////////////////////
93
// ADC_SCK 
94
 
95
reg clk_enable; // must sync to clk in clk low
96
always @ (negedge clk or negedge reset_n)
97
begin
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;
104
end
105
 
106
assign ADC_SCK = clk_enable?clk:1'b0;
107
 
108
 
109
///////////////////////////////
110
// read data
111
reg [(`DATA_BITS_NUM-1):0] read_data;
112
reg [3:0] write_pos;
113
 
114
 
115
 
116
assign measure_dataread = read_data;
117
 
118
always @ (negedge clk or negedge reset_n)
119
begin
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
130
end
131
 
132
///////////////////////////////
133
// measure done
134
wire read_ch_done;
135
 
136
assign read_ch_done = (tick == `tDONE)?1'b1:1'b0;
137
 
138
always @ (posedge clk or negedge reset_n)
139
begin
140
        if (~reset_n)
141
                measure_done <= 1'b0;
142
        else if (read_ch_done)
143
                measure_done <= 1'b1;
144
end
145
 
146
///////////////////////////////
147
// adc channel config
148
 
149
// pre-build config command
150
reg [(`CMD_BITS_NUM-1):0] config_cmd;
151
 
152
 
153
`define UNI_MODE                1'b1   //1: Unipolar, 0:Bipolar
154
`define SLP_MODE                1'b0   //1: enable sleep
155
 
156
always @(negedge reset_n)
157
begin
158
        if (~reset_n)
159
        begin
160
                case (measure_ch)
161
 
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
172
end
173
 
174
// serial config command to adc chip
175
wire config_init;
176
wire config_enable;
177
wire config_done;
178
reg [2:0] sdi_index;
179
 
180
assign config_init = (tick == `tCONFIG_START)?1'b1:1'b0;
181
assign 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)
184
begin
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; //
197
end
198
 
199
 
200
 
201
 
202
endmodule
203
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.