Subversion Repositories shark

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1013 mauro 1
/*****************************************************************************
2
* Filename:       ADC.C                                                      *      
3
* Author:         Ghiro Andrea,Franchino Gianluca                            *
4
* Date:           06/06/2001                                                 *
5
* Description:    Analog 2 digital conversion functions                      *
6
*----------------------------------------------------------------------------*
7
* Notes:                Funcion for one sample from Ch0                      *
8
*****************************************************************************/
9
 
10
/* This file is part of the S.Ha.R.K. Project - http://shark.sssup.it
11
 *
12
 * Copyright (C) 2003 Ghiro Andrea,Franchino Gianluca
13
 *
14
 * This program is free software; you can redistribute it and/or modify
15
 * it under the terms of the GNU General Public License as published by
16
 * the Free Software Foundation; either version 2 of the License, or
17
 * (at your option) any later version.
18
 *
19
 * This program is distributed in the hope that it will be useful,
20
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22
 * GNU General Public License for more details.
23
 *
24
 * You should have received a copy of the GNU General Public License
25
 * along with this program; if not, write to the Free Software
26
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
27
 *
28
 */
29
 
30
#include <drivers/pci6025e/adc.h>
31
 
32
/*
33
* Call this function to configure board options.
34
*/
35
 
36
void Configure_Board(BYTE numch)
37
{
38
WORD memhi;
39
  /*
40
  * Writing to register Write_Strobe_0_Register with address 82.
41
  *    Write_Strobe_0 <= 1
42
  * New pattern = 0x0001
43
  */
44
  DAQ_STC_Windowed_Mode_Write(WRITE_STROBE_0,0x0001);
45
 
46
  /*
47
  * Writing to register Write_Strobe_1_Register with address 83.
48
  *    Write_Strobe_1 <= 1
49
  * New pattern = 0x0001
50
  */
51
  DAQ_STC_Windowed_Mode_Write(WRITE_STROBE_1,0x0001);
52
 
53
  /*
54
  * Writing to register Config_Memory_High_Register with address 18.
55
  *    CM_Channel_Number <= channel_number (0)
56
  *    CM_Channel_Bank <= channel_bank (0)
57
  *    CM_Channel_Type <= channel_type_for_rev_b (3)
58
  * New pattern = 0x3000
59
  */
60
  memhi = 0x3000 | numch;
61
  Immediate_Writew(ADC_CONFIG_HI,memhi);
62
 
63
  /*
64
  * Writing to register Config_Memory_Low_Register with address 16.
65
  *    CM_Last_Channel <= last_channel (1)
66
  *    CM_Trigger <= trigger (0)
67
  *    CM_AI_Gain <= ai_gain (1)
68
  *    CM_AI_Polarity <= ai_polarity (0)
69
  *    CM_AI_Dither_Enable <= ai_dither_enable (0)
70
  * New pattern = 0x8001
71
  */
72
  Immediate_Writew(ADC_CONFIG_LO,0x8100);
73
  return;
74
 }
75
 
76
/*
77
* program the ADC_STC
78
*/
79
 
80
void ADC_Init()
81
{
82
/*
83
* configure the timebase options.
84
*/
85
  /*
86
  * Writing to register Clock_and_FOUT_Register with address 56.
87
  *    Slow_Internal_Timebase <= p->msc_slow_int_tb_enable (1)
88
  *    Slow_Internal_Time_Divide_By_2 <= p->msc_slow_int_tb_divide_by_2 (1)
89
  *    Clock_To_Board <= p->msc_clock_to_board_enable (1)
90
  *    Clock_To_Board_Divide_By_2 <= p->msc_clock_to_board_divide_by_2 (1)
91
  * New pattern = 0x1B00
92
  */
93
  DAQ_STC_Windowed_Mode_Write(CLOCK_AND_FOUT,0x1B00);
94
 
95
/*
96
* clear the AI FIFO.
97
*/
98
  /*
99
  * Writing to register Write_Strobe_1_Register with address 83.
100
  *    Write_Strobe_1 <= 1
101
  * New pattern = 0x0001
102
  */
103
  DAQ_STC_Windowed_Mode_Write(WRITE_STROBE_1,0x0001);
104
 
105
/*
106
* stop any activities in progress.
107
*/
108
  /*
109
  * Writing to register Joint_Reset_Register with address 72.
110
  *    AI_Reset <= 1
111
  * New pattern = 0x0001
112
  */
113
  DAQ_STC_Windowed_Mode_Write(JOINT_RESET,0x0001);
114
 
115
  /*
116
  * Writing to register Joint_Reset_Register with address 72.
117
  *    AI_Configuration_Start <= 1
118
  * New pattern = 0x0010
119
  */
120
  DAQ_STC_Windowed_Mode_Write(JOINT_RESET,0x0010);
121
 
122
  /*
123
  * Writing to register Interrupt_A_Ack_Register with address 2.
124
  *    AI_SC_TC_Error_Confirm <= 1
125
  *    AI_SC_TC_Interrupt_Ack <= 1
126
  *    AI_START1_Interrupt_Ack <= 1
127
  *    AI_START2_Interrupt_Ack <= 1
128
  *    AI_START_Interrupt_Ack <= 1
129
  *    AI_STOP_Interrupt_Ack <= 1
130
  *    AI_Error_Interrupt_Ack <= 1
131
  * New pattern = 0x3F80
132
  */
133
  DAQ_STC_Windowed_Mode_Write(INTERRUPT_A_ACK,0x3F80);
134
 
135
  /*
136
  * Writing to register AI_Command_1_Register with address 8.
137
  *    AI_Command_1_Register <= 0
138
  * New pattern = 0x0000
139
  */
140
  DAQ_STC_Windowed_Mode_Write(AI_COMMAND_1,0x0000);
141
 
142
  /*
143
  * Writing to register AI_Mode_1_Register with address 12.
144
  *    Reserved_One <= 1
145
  *    AI_Start_Stop <= 1
146
  * New pattern = 0x000C
147
  */
148
  DAQ_STC_Windowed_Mode_Write(AI_MODE_1,0x000C);
149
 
150
  /*
151
  * Writing to register Joint_Reset_Register with address 72.
152
  *    AI_Configuration_Start <= 0
153
  *    AI_Configuration_End <= 1
154
  * New pattern = 0x0100
155
  */
156
  DAQ_STC_Windowed_Mode_Write(JOINT_RESET,0x0100);
157
 
158
/*
159
* setup the board.
160
*/
161
  /*
162
  * Writing to register Joint_Reset_Register with address 72.
163
  *    AI_Configuration_Start <= 1
164
  * New pattern = 0x0010
165
  */
166
  DAQ_STC_Windowed_Mode_Write(JOINT_RESET,0x0010);
167
 
168
  /*
169
  * Writing to register Clock_and_FOUT_Register with address 56.
170
  *    AI_Source_Divide_By_2 <= p->ai_source_divide_by_2 (0)
171
  *    AI_Output_Divide_By_2 <= p->ai_output_divide_by_2 (1)
172
  * New pattern = 0x1B80
173
  */
174
  DAQ_STC_Windowed_Mode_Write(CLOCK_AND_FOUT,0x1B80);
175
 
176
  /*
177
  * Writing to register AI_Personal_Register with address 77.
178
  *    AI_CONVERT_Pulse_Timebase <= p->ai_convert_pulse_timebase (0)
179
  *    AI_CONVERT_Pulse_Width <= p->ai_convert_pulse_width (1)
180
  *    AI_FIFO_Flags_Polarity <= p->ai_fifo_flags_polarity (0)
181
  *    AI_LOCALMUX_CLK_Pulse_Width <= p->ai_localmux_clk_pulse_width (1)
182
  *    AI_AIFREQ_Polarity <= p->ai_aifreq_polarity (0)
183
  *    AI_SHIFTIN_Polarity <= p->ai_shiftin_polarity (0)
184
  *    AI_SHIFTIN_Pulse_Width <= p->ai_shiftin_pulse_width (1)
185
  *    AI_EOC_Polarity <= p->ai_eoc_polarity (0)
186
  *    AI_SOC_Polarity <= p->ai_soc_polarity (1)
187
  *    AI_Overrun_Mode <= p->ai_overrun_mode (1)
188
  * New pattern = 0xA4A0
189
  */
190
  DAQ_STC_Windowed_Mode_Write(AI_PERSONAL,0xA4A0);
191
 
192
  /*
193
  * Writing to register AI_Output_Control_Register with address 60.
194
  *    AI_CONVERT_Output_Select <= p->ai_convert_output_select (2)
195
  *    AI_SC_TC_Output_Select <= p->ai_sc_tc_output_select (3)
196
  *    AI_SCAN_IN_PROG_Output_Select <= p->ai_scan_in_prog_output_select (3)
197
  *    AI_LOCALMUX_CLK_Output_Select <= p->ai_localmux_clk_output_select (2)
198
  * New pattern = 0x032E
199
  */
200
  DAQ_STC_Windowed_Mode_Write(AI_OUTPUT_CONTROL,0x032E);
201
 
202
  /*
203
  * Writing to register Joint_Reset_Register with address 72.
204
  *    AI_Configuration_Start <= 0
205
  *    AI_Configuration_End <= 1
206
  * New pattern = 0x0100
207
  */
208
  DAQ_STC_Windowed_Mode_Write(JOINT_RESET,0x0100);
209
 
210
/*
211
* access the first value in the configuration
212
* FIFO.
213
*/
214
  /*
215
  * Writing to register AI_Command_1_Register with address 8.
216
  *    AI_CONVERT_Pulse <= 1
217
  * New pattern = 0x0001
218
  */
219
  DAQ_STC_Windowed_Mode_Write(AI_COMMAND_1,0x0001);
220
 
221
/*
222
* setup for external hardware.
223
*/
224
  /*
225
  * Writing to register Joint_Reset_Register with address 72.
226
  *    AI_Configuration_Start <= 1
227
  * New pattern = 0x0010
228
  */
229
  DAQ_STC_Windowed_Mode_Write(JOINT_RESET,0x0010);
230
 
231
  /*
232
  * Writing to register AI_Mode_2_Register with address 13.
233
  *    AI_External_MUX_Present <= 0
234
  * New pattern = 0x0000
235
  */
236
  DAQ_STC_Windowed_Mode_Write(AI_MODE_2,0x0000);
237
 
238
  /*
239
  * Writing to register AI_Output_Control_Register with address 60.
240
  *    AI_EXTMUX_CLK_Output_Select <= p->ai_extmux_clk_output_select (0)
241
  * New pattern = 0x032E
242
  */
243
  DAQ_STC_Windowed_Mode_Write(AI_OUTPUT_CONTROL,0x032E);
244
 
245
  /*
246
  * Writing to register Joint_Reset_Register with address 72.
247
  *    AI_Configuration_Start <= 0
248
  *    AI_Configuration_End <= 1
249
  * New pattern = 0x0100
250
  */
251
  DAQ_STC_Windowed_Mode_Write(JOINT_RESET,0x0100);
252
 
253
/*
254
* enable or disable retriggering.
255
*/
256
  /*
257
  * Writing to register Joint_Reset_Register with address 72.
258
  *    AI_Configuration_Start <= 1
259
  * New pattern = 0x0010
260
  */
261
  DAQ_STC_Windowed_Mode_Write(JOINT_RESET,0x0010);
262
 
263
  /*
264
  * Writing to register AI_Mode_1_Register with address 12.
265
  *    AI_Trigger_Once <= 1
266
  * New pattern = 0x000D
267
  */
268
  DAQ_STC_Windowed_Mode_Write(AI_MODE_1,0x000D);
269
 
270
  /*
271
  * Writing to register AI_Trigger_Select_Register with address 63.
272
  *    AI_START1_Select <= 0
273
  *    AI_START1_Polarity <= 0
274
  *    AI_START1_Edge <= 1
275
  *    AI_START1_Sync <= 1
276
  * New pattern = 0x0060
277
  */
278
  DAQ_STC_Windowed_Mode_Write(AI_TRIGGER_SELECT,0x0060);
279
 
280
  /*
281
  * Writing to register Joint_Reset_Register with address 72.
282
  *    AI_Configuration_Start <= 0
283
  *    AI_Configuration_End <= 1
284
  * New pattern = 0x0100
285
  */
286
  DAQ_STC_Windowed_Mode_Write(JOINT_RESET,0x0100);
287
 
288
/*
289
* select the number of scans.
290
*/
291
/*
292
  * Writing to register Joint_Reset_Register with address 72.
293
  *    AI_Configuration_Start <= 1
294
  * New pattern = 0x0010
295
  */
296
  DAQ_STC_Windowed_Mode_Write(JOINT_RESET,0x0010);
297
 
298
  DAQ_STC_Windowed_Mode_Write(AI_MODE_1,0x000F);
299
 
300
  /*
301
  * Writing to register Joint_Reset_Register with address 72.
302
  *    AI_Configuration_Start <= 0
303
  *    AI_Configuration_End <= 1
304
  * New pattern = 0x0100
305
  */
306
  DAQ_STC_Windowed_Mode_Write(JOINT_RESET,0x0100);
307
 
308
/*
309
* select the scan start event.
310
*/
311
  /*
312
  * Writing to register Joint_Reset_Register with address 72.
313
  *    AI_Configuration_Start <= 1
314
  * New pattern = 0x0010
315
  */
316
  DAQ_STC_Windowed_Mode_Write(JOINT_RESET,0x0010);
317
 
318
  /*
319
  * Writing to register AI_START_STOP_Select_Register with address 62.
320
  *    AI_START_Select <= 0
321
  *    AI_START_Edge <= 1
322
  *    AI_START_Sync <= 1
323
  *    AI_START_Polarity <= 0
324
  * New pattern = 0x0060
325
  */
326
  DAQ_STC_Windowed_Mode_Write(AI_START_STOP_SELECT,0x0060);
327
 
328
 
329
  /*
330
  * Writing to register Joint_Reset_Register with address 72.
331
  *    AI_Configuration_Start <= 0
332
  *    AI_Configuration_End <= 1
333
  * New pattern = 0x0100
334
  */
335
  DAQ_STC_Windowed_Mode_Write(JOINT_RESET,0x0100);
336
 
337
/*
338
* select the end of scan event.
339
*/
340
  /*
341
  * Writing to register Joint_Reset_Register with address 72.
342
  *    AI_Configuration_Start <= 1
343
  * New pattern = 0x0010
344
  */
345
  DAQ_STC_Windowed_Mode_Write(JOINT_RESET,0x0010);
346
 
347
  /*
348
  * Writing to register AI_START_STOP_Select_Register with address 62.
349
  *    AI_STOP_Select <= p->ai_stop_select (19)
350
  *    AI_STOP_Edge <= 0
351
  *    AI_STOP_Polarity <= p->ai_stop_polarity (0)
352
  *    AI_STOP_Sync <= 1
353
  * New pattern = 0x29E0
354
  */
355
  DAQ_STC_Windowed_Mode_Write(AI_START_STOP_SELECT,0x29E0);
356
 
357
  /*
358
  * Writing to register Joint_Reset_Register with address 72.
359
  *    AI_Configuration_Start <= 0
360
  *    AI_Configuration_End <= 1
361
  * New pattern = 0x0100
362
  */
363
  DAQ_STC_Windowed_Mode_Write(JOINT_RESET,0x0100);
364
 
365
/*
366
* clear the AI FIFO.
367
*/
368
  /*
369
  * Writing to register Write_Strobe_1_Register with address 83.
370
  *    Write_Strobe_1 <= 1
371
  * New pattern = 0x0001
372
  */
373
  DAQ_STC_Windowed_Mode_Write(WRITE_STROBE_1,0x0001);
374
return;
375
}
376
 
377
/*
378
* Call this function to start the acquistion.
379
*/
380
 
381
void AI_Start_The_Acquisition()
382
{
383
  /*
384
  * Writing to register AI_Command_1_Register with address 8.
385
  *    AI_CONVERT_Pulse <= 1
386
  * New pattern = 0x0001
387
  */
388
  DAQ_STC_Windowed_Mode_Write(AI_COMMAND_1,0x0001);
389
  return;
390
 }
391
 
392
/*End of file:    adc.c*/
393
 
394
 
395
 
396
 
397
 
398
 
399
 
400