-
Notifications
You must be signed in to change notification settings - Fork 13
/
calibration.cpp
179 lines (138 loc) · 4.5 KB
/
calibration.cpp
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/*
* Do pinTest and basic auto calibration
*
*/
#include "fancyLock.h"
#include "testPins.h"
#include "allComponents.h"
#include "testerGfx.h"
#include "nvm_default.h"
#include "testerControl.h"
extern TestPin pin1,pin2,pin3;
extern bool pinTest();
/**
*
*/
void title(const char *v)
{
TesterGfx::title(v);
}
#define TINTER(x) (36+16*x)
#define ZINTER(x) (32+18*x)
#define INTER 18
/**
*
* @param cal
* @param p1
* @param p2
*/
void veryLowCapCalibration(int pinNumber,TestPinCalibration &cal,TestPin &pin1,TestPin &pin2)
{
#if 1
float cap;
char st[20];
for(int i=0;i<CALIBRATION_VERY_SMALL_SIZE;i++)
{
int mul16;
Capacitor::calibrationVeryLow(i,pin1,pin2,mul16);
TesterGfx::clear();
sprintf(st,"Fine Pin%d",pinNumber);
TesterGfx::title(st);
sprintf(st," %d/%d",i+1,CALIBRATION_VERY_SMALL_SIZE);
TesterGfx::print(5,INTER*3,st);
sprintf(st,"C=%2.2f pf",(float)mul16/16.);
TesterGfx::print(5,INTER*4,st);
cal.capOffsetHighInPfMu16[i]=mul16;
}
#endif
}
void calibration()
{
TesterGfx::title("Calibration");
TesterGfx::drawZif();
TesterGfx::print(10,TINTER(0),"Clear socket");
TesterGfx::print(10,TINTER(1),"and press ");
TesterGfx::print(10,TINTER(2),"button");
TesterControl::waitForAnyEvent();
//--------------------------------------
// Check pins are correctly connected
//--------------------------------------
if(!pinTest())
{
TesterGfx::print(1,120,"*** FAIL ***");
while(1)
{
}
}
//---------------------------------------
// Eval internal up & down resistances
// Around 20 Ohms
//---------------------------------------
TesterGfx::clear();
title("Resistor");
int resup3,resdown3;
int resup1,resdown1;
int resup2,resdown2;
pin1.evalInternalResistance (resdown1,resup1);
pin2.evalInternalResistance (resdown2,resup2);
pin3.evalInternalResistance (resdown3,resup3);
TestPinCalibration calibration1,calibration2,calibration3;
char st[20];
#define ALLRES(x) {calibration##x.resUp=resup##x;calibration##x.resDown=resdown##x;sprintf(st,"RU:%d:RD:%d",resup##x,resdown##x),TesterGfx::print(1,ZINTER(x-1),st);}
ALLRES(1);
ALLRES(2);
ALLRES(3);
TesterGfx::bottomLine("Press button");
TesterControl::waitForAnyEvent();
float val;
#define ALLCAP(pin,a,b,c) { \
float avgCap=0;\
for(int i=0;i<8;i++) \
{\
float cap;\
Capacitor::calibrationLow(a,b,cap); \
avgCap+=cap;\
}\
avgCap/=8.;\
calibration##pin.capOffsetInPf=(int)(avgCap*pPICO+0.49);\
sprintf(st,"%d pf",calibration##pin.capOffsetInPf);TesterGfx::print(1,ZINTER(pin),st); \
}
//--------------------------------------
// Eval internal cap in // with the test pins
// They are in the 200 pf range
//--------------------------------------
TesterGfx::clear();
TesterGfx::title("Cap");
ALLCAP(1,pin1,pin2,pin3);
ALLCAP(2,pin2,pin1,pin3);
ALLCAP(3,pin3,pin2,pin1);
TesterGfx::bottomLine("Press button");
TesterControl::waitForAnyEvent();
// Cap calibration for lower value i.e. stroboscopic mode
// below ~ 200 Pf
// One of the pin must be the 2nd one
// Stroboscopic calibration, only on pin2
TesterGfx::clear();
TesterGfx::title("Fine Cap");
TesterGfx::print(5,INTER*2,"This is slow");
TesterGfx::print(5,INTER*3,"Please wait");
pin1.setToGround();
pin3.setToGround();
pin2.setToGround();
xDelay(10);
veryLowCapCalibration(1,calibration1,pin1,pin2);
veryLowCapCalibration(3,calibration3,pin3,pin2);
// and save
TesterGfx::clear();
TesterGfx::title("Saving");
NVM::reset();
NVM::saveTestPin(1,calibration1);
NVM::saveTestPin(2,calibration2);
NVM::saveTestPin(3,calibration3);
NVM::doneWriting();
TesterGfx::bottomLine("RESTART");
TesterControl::waitForAnyEvent();
while(1)
{
}
}