-
Notifications
You must be signed in to change notification settings - Fork 0
/
ADC_SetCal.txt
121 lines (91 loc) · 3.49 KB
/
ADC_SetCal.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
[8:25 PM] jdolan-acces: How do I go about testing SetCal()?
May 25, 2021
[9:31 AM] JohnHentges-ACCESIO: If you call "ADC_SetCal(":NONE:"), acquire one scan of all channels with at least one of them grounded, call ADC_SetCal(":AUTO:") and acquire a second scan, the second scan should show a better zero for the grounded channel than the first
//Makes use of a ChunkSize which is based off of the speed of the port the device
//is connected to
ADC_SetCal()
const
LoRefRef = 0 * 6553.6;
HiRefRef = 9.9339 * 6553.6;
Does device validation, check bADC bulk, check results of read AUR_PROBE_CALFEATURE
Reads config from board and saves it.
//if else if on :AUTO:, :NORM:, :1TO1:, :NONE:, <filename>
if ":AUTO:"
Initialize low ref and high ref and dref
create modified config config[0x10] = 0x05, and config[0] = 0x01
For loop of 0 to 1 (i)
Initialize cal table ==> uint16[0x10000] where value = index
DoLoadCalTable()
config[$11] := $04; //scan software-start
config[$12] := $00; //select 1 channel
config[$13] := Min($FF, ChunkSize-1); //Max oversample the FX2 can buffer at once
ThisRef = HiRef
if first time through loop (i == 0)
ThisRef := 1/2 * (ThisRef + $10000);
config[0x10] |= 0x02; //cal low ref
HiRead = ConfigureAndBulkAcquire() //configures the board and reads one channel
if abs(HiRead - ThisRef) > 0x1000 then return ERROR_INVALID_DATA
sleep(10ms);
ThisRef = LoRef
if first time through loop (i == o)
ThisRef = 1/2 * (ThisRef + $10000);
config[0x10] &= ~0x02;
LoRead = ConfigureAndBulkAcquire() //configures the board and reads one channel
if abs (LoRead - ThisRef) > 0x100 then return ERROR_INVALID_DATA
sleep(10ms)
dRead = HiRead - LoRead
for loop 0 to 0x10000 (j)
F = (j LoRead) / dRead;
F = (LoRef + F * dRef)
if (i == 0) F = 1/2 * (F + 0x10000)
J = Round(F)
if (J <= 0) J = 0;
if (J >= 0xFFFF) J = 0xFFFF
CalTable[j] = J
DoLoadCalTable();
config[0x10] = 1;
config[0] = 1;
WriteCalTableToFile() //if user provided a filename
else if ":NORM:"
Initialize low ref, high ref, dref, LoRead, HiRead, and dRead
for loop 0 to 0x10000 (i)
F = ( i - LoRead) / dRead
F = LoRef + F * dRef
J = Round(F);
if (J <= 0) J = 0
if (J >= 0xFFFF) J = 0xFFFF
CalTable[i] = J
config[0x10] = 0x05
for loop 0 to 1 (i)
ADCSetconfig(config)
DoLoadCalTable()
WriteCalTableToFile() //if user provided a filename
config[0x10] = 0x01
else if ":1to1" or ":NONE:"
Initialize cal table ==> uint16[0x10000] where value = index
config[0x10] = 0x05
for loop 0 to 1 (i)
ADCSetconfig(config)
DoLoadCalTable()
WriteCalTableToFile() //if user provided a filename
config[0x10] = 0x01
elsif filename starts with ':'
error out because of unknown mode
else it is a filename
open the file and check Length
if Length >= 0x20000 //"double" cal file
config[0x10] = 0x05
config[0x00] = 0x01
for loop 0 to 1 (i)
ADCSetconfig()
ReadCalTableFromFile()
DoLoadCalTable()
WriteCalTableToFile() //if user provided a filename
config[0x10] = 0x01
config[0x00] = 0x00
else if Length >= 0x10000
ReadCalTableFromFile
DoLoadCalTable()
WriteCalTableToFile() //if user provided a filename
else
return error (EOF?)