-
Notifications
You must be signed in to change notification settings - Fork 0
/
k11-lc.ino
157 lines (124 loc) · 3.68 KB
/
k11-lc.ino
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
/***************************************************
* Multi-instrumento
*
* Author: Pavel Milanes Costa
* Email: [email protected]
****************************************************/
/******************************************************************************
* Calc either L or C
*
* In parameter f (Mhz) and l (nH) or C (pF)
* Out the other L or C in nH or pF
******************************************************************************/
unsigned long calcLorC(unsigned long f, unsigned long lorc) {
// vars
unsigned long ret;
unsigned long f2;
// scale and ^2
f2 = f / 10000;
f2 *= f2;
// calc the dividend
f2 *= lorc;
f2 /= 100;
// calc
ret = 2533000000 / f2;
// ret
return ret;
}
// draw interface
void lcInterface() {
// advice
tft.setTextColor(ILI9340_CYAN);
tft.setTextSize(2);
tft.setCursor(2, 30);
tft.print((char *)"Make a parallel LC circuit");
tft.setCursor(2, 50);
tft.print((char *)"put a good known cap on it");
tft.setCursor(2, 70);
tft.print((char *)"choose its value here, hit");
tft.setCursor(2, 90);
tft.print((char *)"OK button to know results.");
// ask for cap
tft.setTextColor(ILI9340_YELLOW);
tft.setCursor(2, 120);
tft.print((char *)"Cap value:");
lcdUpdateC();
// results
tft.setCursor(2, 145);
tft.print((char *)"Res Freq:");
tft.setCursor(2, 165);
tft.print((char *)"Inductance:");
}
// update the data
void lcdUpdateC() {
// print selected cap value
tft.setCursor(135, 120);
tft.setTextColor(ILI9340_WHITE, ILI9340_BLACK);
// reset the print buffers
cleanPrintbuffer();
// load the value to the temp buffer
ltoa(getcap() * 10, t, DEC);
// prep the print buffer
prepValue4Print(strlen(t));
// add ending fp and print
strcat(f, " pF");
tft.print(f);
}
// get the actual cap value
unsigned long getcap() {
long resmult = 1;
byte mult = cmult;
while (mult--) {resmult *= 10;}
// calc the value
resmult *= kcaps[cindex];
// return
return long(resmult);
}
// calc the inductor value
/****************************************************************************
* The algorithm is like this
*
* - Make a scan from min to max
* detect the minimum
* - Make a second scan with a span of 3 Mhz and centered on the min
* detect the minimum
* - calc L
* - Show L
*****************************************************************************/
void makeCCalcs() {
// set scan parameters for the first round
scan_low = LIMI_LOW;
scan_high = LIMI_HIGH;
sstep = (scan_high - scan_low) / TFT_WIDTH;
// make first scan
makeScan2Flash(136, false);
// erase bar
tft.fillRect(0, 136, TFT_WIDTH, 5, ILI9340_BLACK);
// now minf/minv has the aprox resonant freq
// set it to center and +/- 1.5 Mhz
scan_low = minf - 1500000; // -1.5 MHz
scan_high = minf + 1500000; // +1.5 MHz
sstep = 9375; // ~10 khz
// make second scan
makeScan2Flash(136, false);
// erase bar
tft.fillRect(0, 136, TFT_WIDTH, 5, ILI9340_BLACK);
// print freq
tft.setTextColor(ILI9340_YELLOW, ILI9340_BLACK);
tft.setCursor(112, 145);
prepFreq4Print(minf, true);
tft.print(f);
// now minf has the value, calc
unsigned long capt = getcap();
long ind = calcLorC(minf, capt);
// reset the print buffers
cleanPrintbuffer();
// load the value to the temp buffer
ltoa(ind * 10, t, DEC);
// prep the print buffer
prepValue4Print(strlen(t));
// add ending fp and print
strcat(f, " nH");
tft.setCursor(140, 165);
tft.print(f);
}