-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathInstrumentCal.h
1662 lines (1427 loc) · 64.8 KB
/
InstrumentCal.h
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//
// Copyright 2004-2010 Thomas C. McDermott, N5EG
// This file is part of VNAR - the Vector Network Analyzer program.
//
// VNAR is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// VNAR is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with VNAR, if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// Modified: 05-10-2005 TCM Add routines for Internal Crystal Calibration
// Modified: 08-05-2006 TCM Add Error-Checking in case the cal results are poor
//
#pragma once
#include "DisplayRoutines.h"
#include "USB_EZ_interface.h"
#include "Constants.h"
#include <math.h>
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::IO;
#define NUMCALSTEPS 8 // 8 mandatory calibration steps
namespace VNAR3
{
/// <summary>
/// Summary for InstrumentCal
///
/// WARNING: If you change the name of this class, you will need to change the
/// 'Resource File Name' property for the managed resource compiler tool
/// associated with all .resx files this class depends on. Otherwise,
/// the designers will not be able to interact properly with localized
/// resources associated with this form.
/// </summary>
/// Instrument Detector Calibration
public ref class InstrumentCal : public System::Windows::Forms::Form
{
public:
InstrumentCal(InstrumentCalDataSet^ CalDS, VNADevice^ VNADev, FrequencyGrid^ fg, String^ StartDir)
{
InitializeComponent();
VNA = VNADev; ///< VNA hardware device
Cal = CalDS; ///< Calibration Dataset
AllUsersDir = StartDir; ///< Application data directory common to all users
FG = fg; ///< Frequency Grid from parent
Iphase = gcnew array<UInt16>(1024); ///< I-Phase measurements
Qphase = gcnew array<UInt16>(1024); ///< Q-Phase Measurements
IphaseLo = gcnew array<UInt16>(1024); ///< I-phase low ref measurements
ReflMagRegression = gcnew array<UInt16,2>(21, 60); ///< Shorted Reflection amplitude measurements
ReflMagPhDir = gcnew array<UInt16,2>(PHASECALGRIDSIZE, 3); ///< Directivity Reflection raw ADC counts
ReflMagPhOpen = gcnew array<UInt16,2>(PHASECALGRIDSIZE, 3); ///< Open Reflection raw ADC counts
ReflMagPhShort = gcnew array<UInt16,2>(PHASECALGRIDSIZE, 3); ///< Shorted Reflection raw ADC counts
ReflDetailMagPhShort = gcnew array<UInt16,2>(1024, 3); ///< Shorted Detailed Reflection raw ADC counts
ReflDetailMagPhOpen = gcnew array<UInt16,2>(1024, 3); ///< Open Detailed Reflection raw ADC counts
ReflLongDetailMagPhOpen = gcnew array<UInt16,2>(1024, 3); ///< Terminated Detailed Reflection raw ADC counts
ReflLongDetailMagPhShort = gcnew array<UInt16,2>(1024, 3); ///< Terminated Detailed Reflection raw ADC counts
//ReflOpen100MHz = new int __gc[3]; ///< ConnectorOpen at 100 MHz raw ADC counts
TranMag = gcnew array<UInt16,2>(21, 60); ///< Transmission Amplitude raw ADC counts
BufferI = gcnew array<UInt16>(7); ///< holds raw I reading set
BufferQ = gcnew array<UInt16>(7); ///< holds raw Q reading set
BufferILo = gcnew array<UInt16>(7); ///< holds raw I-Low readging set
BufferM = gcnew array<UInt16>(7); ///< holds raw magnitude reading set Lo
BufferN = gcnew array<UInt16>(7); ///< holds raw magnitude reading set Hi
BufferP = gcnew array<UInt16>(7); ///< holds raw magnitude reading set Mid
CalStepPass = gcnew array<Boolean>(NUMCALSTEPS);
for(int k=0; k<NUMCALSTEPS; k++)
CalStepPass[k] = false; ///< pass/fail for each calibration step
}
protected:
~InstrumentCal()
{
if(components)
delete(components);
}
private: System::Windows::Forms::Label^ label1;
private: System::Windows::Forms::Button^ OKbutton;
private: System::Windows::Forms::Button^ Cancelbutton;
private: System::Windows::Forms::Label^ label2;
private: System::Windows::Forms::Button^ RxPhaseButton;
private: System::Windows::Forms::Button^ TxPhaseButton;
private: System::Windows::Forms::Label^ label4;
private: System::Windows::Forms::Label^ label5;
private: System::Windows::Forms::Label^ RxPhaseStat;
private: System::Windows::Forms::Label^ TxPhaseStat;
private: System::Windows::Forms::ProgressBar^ progressBar1;
private: System::Windows::Forms::Label^ label6;
private: System::Windows::Forms::Label^ label7;
private: System::Windows::Forms::Button^ TxLowAmpButton;
private: System::Windows::Forms::Label^ label8;
private: System::Windows::Forms::Label^ TxLowAmpStat;
private: System::Windows::Forms::Button^ FrequencyCalButton;
private: System::Windows::Forms::Label^ label3;
private: System::Windows::Forms::Label^ FrequencyCalStat;
private: System::Windows::Forms::TextBox^ MeasFreqTextBox;
private: System::Windows::Forms::Label^ label9;
private: System::Windows::Forms::Button^ FreqEnterButton;
private: System::Windows::Forms::Label^ label10;
private: System::Windows::Forms::Label^ label11;
private: System::Windows::Forms::Label^ label12;
private: System::Windows::Forms::Button^ DirectivityCalButton;
private: System::Windows::Forms::Label^ DirectivityCalStat;
private: System::Windows::Forms::Label^ label14;
private: System::Windows::Forms::Button^ RxAmpButtonOpen;
private: System::Windows::Forms::Label^ RxAmpStatShort;
private: System::Windows::Forms::Label^ label15;
private: System::Windows::Forms::Label^ RxAmpStatOpen;
private: System::Windows::Forms::Button^ RxAmpButtonShort;
private: System::Windows::Forms::Label^ ICO1Label;
private: System::Windows::Forms::Label^ ICO2Label;
private: System::Windows::Forms::GroupBox^ Optional;
private: System::Windows::Forms::Button^ TxLongCableOpenButton;
private: System::Windows::Forms::Label^ label13;
private: System::Windows::Forms::Label^ label16;
private: System::Windows::Forms::Label^ TxLongCableShortStat;
private: System::Windows::Forms::Label^ TxLongCableOpenStat;
private: System::Windows::Forms::Button^ TxLongCableShortButton;
private: System::ComponentModel::IContainer^ components;
private:
/// <summary>
/// Required designer variable.
/// </summary>
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(InstrumentCal::typeid));
this->label1 = (gcnew System::Windows::Forms::Label());
this->OKbutton = (gcnew System::Windows::Forms::Button());
this->Cancelbutton = (gcnew System::Windows::Forms::Button());
this->RxPhaseButton = (gcnew System::Windows::Forms::Button());
this->label2 = (gcnew System::Windows::Forms::Label());
this->TxPhaseButton = (gcnew System::Windows::Forms::Button());
this->label4 = (gcnew System::Windows::Forms::Label());
this->label5 = (gcnew System::Windows::Forms::Label());
this->RxPhaseStat = (gcnew System::Windows::Forms::Label());
this->RxAmpStatShort = (gcnew System::Windows::Forms::Label());
this->TxPhaseStat = (gcnew System::Windows::Forms::Label());
this->progressBar1 = (gcnew System::Windows::Forms::ProgressBar());
this->label6 = (gcnew System::Windows::Forms::Label());
this->label7 = (gcnew System::Windows::Forms::Label());
this->TxLowAmpButton = (gcnew System::Windows::Forms::Button());
this->label8 = (gcnew System::Windows::Forms::Label());
this->TxLowAmpStat = (gcnew System::Windows::Forms::Label());
this->FrequencyCalButton = (gcnew System::Windows::Forms::Button());
this->label3 = (gcnew System::Windows::Forms::Label());
this->FrequencyCalStat = (gcnew System::Windows::Forms::Label());
this->MeasFreqTextBox = (gcnew System::Windows::Forms::TextBox());
this->label9 = (gcnew System::Windows::Forms::Label());
this->FreqEnterButton = (gcnew System::Windows::Forms::Button());
this->label10 = (gcnew System::Windows::Forms::Label());
this->label11 = (gcnew System::Windows::Forms::Label());
this->label12 = (gcnew System::Windows::Forms::Label());
this->DirectivityCalButton = (gcnew System::Windows::Forms::Button());
this->DirectivityCalStat = (gcnew System::Windows::Forms::Label());
this->label14 = (gcnew System::Windows::Forms::Label());
this->RxAmpButtonOpen = (gcnew System::Windows::Forms::Button());
this->label15 = (gcnew System::Windows::Forms::Label());
this->RxAmpStatOpen = (gcnew System::Windows::Forms::Label());
this->RxAmpButtonShort = (gcnew System::Windows::Forms::Button());
this->ICO1Label = (gcnew System::Windows::Forms::Label());
this->ICO2Label = (gcnew System::Windows::Forms::Label());
this->Optional = (gcnew System::Windows::Forms::GroupBox());
this->TxLongCableOpenButton = (gcnew System::Windows::Forms::Button());
this->label13 = (gcnew System::Windows::Forms::Label());
this->label16 = (gcnew System::Windows::Forms::Label());
this->TxLongCableShortStat = (gcnew System::Windows::Forms::Label());
this->TxLongCableOpenStat = (gcnew System::Windows::Forms::Label());
this->TxLongCableShortButton = (gcnew System::Windows::Forms::Button());
this->SuspendLayout();
//
// label1
//
this->label1->BackColor = System::Drawing::Color::Transparent;
this->label1->Font = (gcnew System::Drawing::Font(L"Verdana", 15.75F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->label1->Location = System::Drawing::Point(144, 6);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(426, 29);
this->label1->TabIndex = 0;
this->label1->Text = L"Detector Calibration";
this->label1->TextAlign = System::Drawing::ContentAlignment::MiddleCenter;
//
// OKbutton
//
this->OKbutton->FlatStyle = System::Windows::Forms::FlatStyle::System;
this->OKbutton->Location = System::Drawing::Point(456, 578);
this->OKbutton->Name = L"OKbutton";
this->OKbutton->Size = System::Drawing::Size(101, 30);
this->OKbutton->TabIndex = 1;
this->OKbutton->Text = L"Save";
this->OKbutton->Click += gcnew System::EventHandler(this, &InstrumentCal::OKbutton_Click);
//
// Cancelbutton
//
this->Cancelbutton->DialogResult = System::Windows::Forms::DialogResult::Cancel;
this->Cancelbutton->FlatStyle = System::Windows::Forms::FlatStyle::System;
this->Cancelbutton->Location = System::Drawing::Point(584, 578);
this->Cancelbutton->Name = L"Cancelbutton";
this->Cancelbutton->Size = System::Drawing::Size(105, 28);
this->Cancelbutton->TabIndex = 2;
this->Cancelbutton->Text = L"Cancel";
this->Cancelbutton->Click += gcnew System::EventHandler(this, &InstrumentCal::Cancelbutton_Click);
//
// RxPhaseButton
//
this->RxPhaseButton->FlatStyle = System::Windows::Forms::FlatStyle::System;
this->RxPhaseButton->Font = (gcnew System::Drawing::Font(L"Verdana", 9.75F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->RxPhaseButton->Location = System::Drawing::Point(520, 64);
this->RxPhaseButton->Name = L"RxPhaseButton";
this->RxPhaseButton->Size = System::Drawing::Size(176, 48);
this->RxPhaseButton->TabIndex = 3;
this->RxPhaseButton->Text = L"Refl Phase Detector Calibration";
this->RxPhaseButton->Click += gcnew System::EventHandler(this, &InstrumentCal::RxPhaseButton_Click);
//
// label2
//
this->label2->BackColor = System::Drawing::Color::Transparent;
this->label2->Font = (gcnew System::Drawing::Font(L"Verdana", 9.75F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->label2->Location = System::Drawing::Point(96, 66);
this->label2->Name = L"label2";
this->label2->Size = System::Drawing::Size(414, 48);
this->label2->TabIndex = 5;
this->label2->Text = L"Connect one meter long 50-ohm cable, shorted at far end, to Tx connector.";
//
// TxPhaseButton
//
this->TxPhaseButton->FlatStyle = System::Windows::Forms::FlatStyle::System;
this->TxPhaseButton->Font = (gcnew System::Drawing::Font(L"Verdana", 9.75F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->TxPhaseButton->Location = System::Drawing::Point(520, 208);
this->TxPhaseButton->Name = L"TxPhaseButton";
this->TxPhaseButton->Size = System::Drawing::Size(176, 48);
this->TxPhaseButton->TabIndex = 6;
this->TxPhaseButton->Text = L"Trans Phase Detector Calibration";
this->TxPhaseButton->Click += gcnew System::EventHandler(this, &InstrumentCal::TxPhaseButton_Click);
//
// label4
//
this->label4->BackColor = System::Drawing::Color::Transparent;
this->label4->Location = System::Drawing::Point(152, 32);
this->label4->Name = L"label4";
this->label4->Size = System::Drawing::Size(415, 28);
this->label4->TabIndex = 9;
this->label4->Text = L"(This calibration normally needs to be run only one time.)";
this->label4->TextAlign = System::Drawing::ContentAlignment::MiddleCenter;
//
// label5
//
this->label5->BackColor = System::Drawing::Color::Transparent;
this->label5->Font = (gcnew System::Drawing::Font(L"Verdana", 9.75F, System::Drawing::FontStyle::Underline, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->label5->Location = System::Drawing::Point(16, 38);
this->label5->Name = L"label5";
this->label5->Size = System::Drawing::Size(67, 20);
this->label5->TabIndex = 10;
this->label5->Text = L"Status";
//
// RxPhaseStat
//
this->RxPhaseStat->BackColor = System::Drawing::Color::Transparent;
this->RxPhaseStat->Location = System::Drawing::Point(17, 56);
this->RxPhaseStat->Name = L"RxPhaseStat";
this->RxPhaseStat->Size = System::Drawing::Size(48, 48);
this->RxPhaseStat->TabIndex = 11;
this->RxPhaseStat->Visible = false;
//
// RxAmpStatShort
//
this->RxAmpStatShort->BackColor = System::Drawing::Color::Transparent;
this->RxAmpStatShort->Location = System::Drawing::Point(17, 104);
this->RxAmpStatShort->Name = L"RxAmpStatShort";
this->RxAmpStatShort->Size = System::Drawing::Size(48, 48);
this->RxAmpStatShort->TabIndex = 12;
this->RxAmpStatShort->Visible = false;
//
// TxPhaseStat
//
this->TxPhaseStat->BackColor = System::Drawing::Color::Transparent;
this->TxPhaseStat->Location = System::Drawing::Point(17, 200);
this->TxPhaseStat->Name = L"TxPhaseStat";
this->TxPhaseStat->Size = System::Drawing::Size(48, 48);
this->TxPhaseStat->TabIndex = 13;
this->TxPhaseStat->Visible = false;
//
// progressBar1
//
this->progressBar1->Location = System::Drawing::Point(32, 610);
this->progressBar1->Maximum = 1024;
this->progressBar1->Name = L"progressBar1";
this->progressBar1->Size = System::Drawing::Size(664, 13);
this->progressBar1->TabIndex = 15;
//
// label6
//
this->label6->BackColor = System::Drawing::Color::Transparent;
this->label6->Font = (gcnew System::Drawing::Font(L"Verdana", 9.75F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->label6->Location = System::Drawing::Point(96, 211);
this->label6->Name = L"label6";
this->label6->Size = System::Drawing::Size(408, 45);
this->label6->TabIndex = 16;
this->label6->Text = L"Connect three meter long 50-ohm cable and 40 dB attenuator from Rx to Tx.";
//
// label7
//
this->label7->BackColor = System::Drawing::Color::Transparent;
this->label7->Font = (gcnew System::Drawing::Font(L"Verdana", 9.75F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->label7->Location = System::Drawing::Point(96, 114);
this->label7->Name = L"label7";
this->label7->Size = System::Drawing::Size(414, 48);
this->label7->TabIndex = 17;
this->label7->Text = L"Connect one meter long 50-ohm cable, shorted at far end, to Tx connector.";
//
// TxLowAmpButton
//
this->TxLowAmpButton->FlatStyle = System::Windows::Forms::FlatStyle::System;
this->TxLowAmpButton->Font = (gcnew System::Drawing::Font(L"Verdana", 9.75F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->TxLowAmpButton->Location = System::Drawing::Point(520, 256);
this->TxLowAmpButton->Name = L"TxLowAmpButton";
this->TxLowAmpButton->Size = System::Drawing::Size(176, 48);
this->TxLowAmpButton->TabIndex = 18;
this->TxLowAmpButton->Text = L"Trans Amplitude Detector Calibration";
this->TxLowAmpButton->Click += gcnew System::EventHandler(this, &InstrumentCal::TxLowAmpButton_Click);
//
// label8
//
this->label8->BackColor = System::Drawing::Color::Transparent;
this->label8->Font = (gcnew System::Drawing::Font(L"Verdana", 9.75F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->label8->Location = System::Drawing::Point(96, 261);
this->label8->Name = L"label8";
this->label8->Size = System::Drawing::Size(408, 45);
this->label8->TabIndex = 19;
this->label8->Text = L"Connect 40 dB attenuator (50 ohm type) from Rx to Tx. (Use three-meter cable and "
L"setup from previous step).";
//
// TxLowAmpStat
//
this->TxLowAmpStat->BackColor = System::Drawing::Color::Transparent;
this->TxLowAmpStat->Location = System::Drawing::Point(17, 256);
this->TxLowAmpStat->Name = L"TxLowAmpStat";
this->TxLowAmpStat->Size = System::Drawing::Size(48, 48);
this->TxLowAmpStat->TabIndex = 20;
this->TxLowAmpStat->Visible = false;
//
// FrequencyCalButton
//
this->FrequencyCalButton->FlatStyle = System::Windows::Forms::FlatStyle::System;
this->FrequencyCalButton->Font = (gcnew System::Drawing::Font(L"Verdana", 9.75F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->FrequencyCalButton->Location = System::Drawing::Point(512, 474);
this->FrequencyCalButton->Name = L"FrequencyCalButton";
this->FrequencyCalButton->Size = System::Drawing::Size(176, 48);
this->FrequencyCalButton->TabIndex = 21;
this->FrequencyCalButton->Text = L"Internal Crystal Frequency Calibration";
this->FrequencyCalButton->Click += gcnew System::EventHandler(this, &InstrumentCal::FrequencyCalButton_Click);
//
// label3
//
this->label3->BackColor = System::Drawing::Color::Transparent;
this->label3->Location = System::Drawing::Point(96, 458);
this->label3->Name = L"label3";
this->label3->Size = System::Drawing::Size(408, 24);
this->label3->TabIndex = 22;
this->label3->Text = L"1. Connect frequency counter to TX.";
//
// FrequencyCalStat
//
this->FrequencyCalStat->BackColor = System::Drawing::Color::Transparent;
this->FrequencyCalStat->Location = System::Drawing::Point(16, 474);
this->FrequencyCalStat->Name = L"FrequencyCalStat";
this->FrequencyCalStat->Size = System::Drawing::Size(56, 49);
this->FrequencyCalStat->TabIndex = 23;
this->FrequencyCalStat->Visible = false;
//
// MeasFreqTextBox
//
this->MeasFreqTextBox->Location = System::Drawing::Point(256, 546);
this->MeasFreqTextBox->Name = L"MeasFreqTextBox";
this->MeasFreqTextBox->Size = System::Drawing::Size(111, 23);
this->MeasFreqTextBox->TabIndex = 24;
this->MeasFreqTextBox->Text = L"100000000";
//
// label9
//
this->label9->BackColor = System::Drawing::Color::Transparent;
this->label9->Location = System::Drawing::Point(96, 546);
this->label9->Name = L"label9";
this->label9->Size = System::Drawing::Size(153, 23);
this->label9->TabIndex = 25;
this->label9->Text = L"Measured Frequency";
//
// FreqEnterButton
//
this->FreqEnterButton->FlatStyle = System::Windows::Forms::FlatStyle::System;
this->FreqEnterButton->Location = System::Drawing::Point(376, 546);
this->FreqEnterButton->Name = L"FreqEnterButton";
this->FreqEnterButton->Size = System::Drawing::Size(56, 24);
this->FreqEnterButton->TabIndex = 26;
this->FreqEnterButton->Text = L"Enter";
this->FreqEnterButton->Click += gcnew System::EventHandler(this, &InstrumentCal::FreqEnterButton_Click);
//
// label10
//
this->label10->BackColor = System::Drawing::Color::Transparent;
this->label10->Location = System::Drawing::Point(96, 474);
this->label10->Name = L"label10";
this->label10->Size = System::Drawing::Size(408, 16);
this->label10->TabIndex = 27;
this->label10->Text = L"2. Click \"Internal Crystal Frequency Calibration\" button.";
//
// label11
//
this->label11->BackColor = System::Drawing::Color::Transparent;
this->label11->Location = System::Drawing::Point(96, 498);
this->label11->Name = L"label11";
this->label11->Size = System::Drawing::Size(408, 32);
this->label11->TabIndex = 28;
this->label11->Text = L"3. Measure and enter frequency to nearest hertz (approximately 100 MHz).";
//
// label12
//
this->label12->BackColor = System::Drawing::Color::Transparent;
this->label12->Location = System::Drawing::Point(96, 530);
this->label12->Name = L"label12";
this->label12->Size = System::Drawing::Size(408, 16);
this->label12->TabIndex = 29;
this->label12->Text = L"4. Click \"Enter\" button.";
//
// DirectivityCalButton
//
this->DirectivityCalButton->FlatStyle = System::Windows::Forms::FlatStyle::System;
this->DirectivityCalButton->Font = (gcnew System::Drawing::Font(L"Verdana", 9.75F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->DirectivityCalButton->Location = System::Drawing::Point(520, 304);
this->DirectivityCalButton->Name = L"DirectivityCalButton";
this->DirectivityCalButton->Size = System::Drawing::Size(176, 48);
this->DirectivityCalButton->TabIndex = 31;
this->DirectivityCalButton->Text = L"Coupler Directivity Calibration";
this->DirectivityCalButton->Click += gcnew System::EventHandler(this, &InstrumentCal::DirectivityCalButton_Click);
//
// DirectivityCalStat
//
this->DirectivityCalStat->BackColor = System::Drawing::Color::Transparent;
this->DirectivityCalStat->Location = System::Drawing::Point(17, 304);
this->DirectivityCalStat->Name = L"DirectivityCalStat";
this->DirectivityCalStat->Size = System::Drawing::Size(48, 48);
this->DirectivityCalStat->TabIndex = 32;
this->DirectivityCalStat->Visible = false;
//
// label14
//
this->label14->BackColor = System::Drawing::Color::Transparent;
this->label14->Location = System::Drawing::Point(96, 312);
this->label14->Name = L"label14";
this->label14->Size = System::Drawing::Size(408, 32);
this->label14->TabIndex = 33;
this->label14->Text = L"Connect 40 dB attenuator directly to the TX connector (no cable).";
//
// RxAmpButtonOpen
//
this->RxAmpButtonOpen->FlatStyle = System::Windows::Forms::FlatStyle::System;
this->RxAmpButtonOpen->Font = (gcnew System::Drawing::Font(L"Verdana", 9.75F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->RxAmpButtonOpen->Location = System::Drawing::Point(520, 160);
this->RxAmpButtonOpen->Name = L"RxAmpButtonOpen";
this->RxAmpButtonOpen->Size = System::Drawing::Size(176, 48);
this->RxAmpButtonOpen->TabIndex = 34;
this->RxAmpButtonOpen->Text = L"Refl Amplitude Detector Cal Open";
this->RxAmpButtonOpen->Click += gcnew System::EventHandler(this, &InstrumentCal::RxAmpButtonOpen_Click);
//
// label15
//
this->label15->BackColor = System::Drawing::Color::Transparent;
this->label15->Location = System::Drawing::Point(96, 161);
this->label15->Name = L"label15";
this->label15->Size = System::Drawing::Size(408, 48);
this->label15->TabIndex = 35;
this->label15->Text = L"Connect one meter long 50-ohm cable, open at far end, to Tx connector.";
//
// RxAmpStatOpen
//
this->RxAmpStatOpen->BackColor = System::Drawing::Color::Transparent;
this->RxAmpStatOpen->Location = System::Drawing::Point(17, 152);
this->RxAmpStatOpen->Name = L"RxAmpStatOpen";
this->RxAmpStatOpen->Size = System::Drawing::Size(48, 48);
this->RxAmpStatOpen->TabIndex = 36;
this->RxAmpStatOpen->Visible = false;
//
// RxAmpButtonShort
//
this->RxAmpButtonShort->FlatStyle = System::Windows::Forms::FlatStyle::System;
this->RxAmpButtonShort->Font = (gcnew System::Drawing::Font(L"Verdana", 9.75F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->RxAmpButtonShort->Location = System::Drawing::Point(520, 112);
this->RxAmpButtonShort->Name = L"RxAmpButtonShort";
this->RxAmpButtonShort->Size = System::Drawing::Size(176, 48);
this->RxAmpButtonShort->TabIndex = 37;
this->RxAmpButtonShort->Text = L"Refl Amplitude Detector Cal Short";
this->RxAmpButtonShort->Click += gcnew System::EventHandler(this, &InstrumentCal::RxAmpButtonShort_Click);
//
// ICO1Label
//
this->ICO1Label->BackColor = System::Drawing::Color::Transparent;
this->ICO1Label->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"ICO1Label.Image")));
this->ICO1Label->Location = System::Drawing::Point(19, 538);
this->ICO1Label->Name = L"ICO1Label";
this->ICO1Label->Size = System::Drawing::Size(37, 25);
this->ICO1Label->TabIndex = 38;
this->ICO1Label->Visible = false;
//
// ICO2Label
//
this->ICO2Label->BackColor = System::Drawing::Color::Transparent;
this->ICO2Label->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"ICO2Label.Image")));
this->ICO2Label->Location = System::Drawing::Point(25, 570);
this->ICO2Label->Name = L"ICO2Label";
this->ICO2Label->Size = System::Drawing::Size(25, 25);
this->ICO2Label->TabIndex = 39;
this->ICO2Label->Visible = false;
//
// Optional
//
this->Optional->BackColor = System::Drawing::Color::Transparent;
this->Optional->Location = System::Drawing::Point(87, 442);
this->Optional->Name = L"Optional";
this->Optional->Size = System::Drawing::Size(609, 134);
this->Optional->TabIndex = 40;
this->Optional->TabStop = false;
this->Optional->Text = L"Optional";
//
// TxLongCableOpenButton
//
this->TxLongCableOpenButton->Font = (gcnew System::Drawing::Font(L"Verdana", 9.75F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->TxLongCableOpenButton->Location = System::Drawing::Point(520, 400);
this->TxLongCableOpenButton->Name = L"TxLongCableOpenButton";
this->TxLongCableOpenButton->Size = System::Drawing::Size(176, 48);
this->TxLongCableOpenButton->TabIndex = 42;
this->TxLongCableOpenButton->Text = L"Directional Coupler Ripple Cal Open";
this->TxLongCableOpenButton->UseVisualStyleBackColor = true;
this->TxLongCableOpenButton->Click += gcnew System::EventHandler(this, &InstrumentCal::TxLongCableOpenButton_Click);
//
// label13
//
this->label13->BackColor = System::Drawing::Color::Transparent;
this->label13->Location = System::Drawing::Point(96, 358);
this->label13->Name = L"label13";
this->label13->Size = System::Drawing::Size(394, 35);
this->label13->TabIndex = 43;
this->label13->Text = L"Connect three meter long 50-ohm cable, shorted at far end, to Tx connector.";
//
// label16
//
this->label16->BackColor = System::Drawing::Color::Transparent;
this->label16->Location = System::Drawing::Point(96, 403);
this->label16->Name = L"label16";
this->label16->Size = System::Drawing::Size(394, 38);
this->label16->TabIndex = 44;
this->label16->Text = L"Connect three meter long 50-ohm cable, open at far end, to Tx connector.";
//
// TxLongCableShortStat
//
this->TxLongCableShortStat->BackColor = System::Drawing::Color::Transparent;
this->TxLongCableShortStat->Location = System::Drawing::Point(17, 349);
this->TxLongCableShortStat->Name = L"TxLongCableShortStat";
this->TxLongCableShortStat->Size = System::Drawing::Size(48, 48);
this->TxLongCableShortStat->TabIndex = 45;
this->TxLongCableShortStat->Visible = false;
//
// TxLongCableOpenStat
//
this->TxLongCableOpenStat->BackColor = System::Drawing::Color::Transparent;
this->TxLongCableOpenStat->Location = System::Drawing::Point(17, 395);
this->TxLongCableOpenStat->Name = L"TxLongCableOpenStat";
this->TxLongCableOpenStat->Size = System::Drawing::Size(48, 48);
this->TxLongCableOpenStat->TabIndex = 46;
this->TxLongCableOpenStat->Visible = false;
//
// TxLongCableShortButton
//
this->TxLongCableShortButton->Font = (gcnew System::Drawing::Font(L"Verdana", 9.75F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->TxLongCableShortButton->Location = System::Drawing::Point(520, 352);
this->TxLongCableShortButton->Name = L"TxLongCableShortButton";
this->TxLongCableShortButton->Size = System::Drawing::Size(176, 48);
this->TxLongCableShortButton->TabIndex = 48;
this->TxLongCableShortButton->Text = L"Directional Coupler Ripple Cal Short";
this->TxLongCableShortButton->UseVisualStyleBackColor = true;
this->TxLongCableShortButton->Click += gcnew System::EventHandler(this, &InstrumentCal::TxLongCableShortButton_Click);
//
// InstrumentCal
//
this->AcceptButton = this->OKbutton;
this->AutoScroll = true;
this->AutoValidate = System::Windows::Forms::AutoValidate::EnableAllowFocusChange;
this->BackgroundImage = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"$this.BackgroundImage")));
this->BackgroundImageLayout = System::Windows::Forms::ImageLayout::Stretch;
this->CancelButton = this->Cancelbutton;
this->ClientSize = System::Drawing::Size(736, 629);
this->Controls->Add(this->TxLongCableShortButton);
this->Controls->Add(this->TxLongCableOpenStat);
this->Controls->Add(this->TxLongCableShortStat);
this->Controls->Add(this->label16);
this->Controls->Add(this->label13);
this->Controls->Add(this->TxLongCableOpenButton);
this->Controls->Add(this->ICO2Label);
this->Controls->Add(this->ICO1Label);
this->Controls->Add(this->RxAmpButtonShort);
this->Controls->Add(this->RxAmpStatOpen);
this->Controls->Add(this->label15);
this->Controls->Add(this->RxAmpButtonOpen);
this->Controls->Add(this->label14);
this->Controls->Add(this->DirectivityCalStat);
this->Controls->Add(this->DirectivityCalButton);
this->Controls->Add(this->label12);
this->Controls->Add(this->label11);
this->Controls->Add(this->label10);
this->Controls->Add(this->FreqEnterButton);
this->Controls->Add(this->label9);
this->Controls->Add(this->MeasFreqTextBox);
this->Controls->Add(this->FrequencyCalStat);
this->Controls->Add(this->label3);
this->Controls->Add(this->FrequencyCalButton);
this->Controls->Add(this->TxLowAmpStat);
this->Controls->Add(this->label8);
this->Controls->Add(this->TxLowAmpButton);
this->Controls->Add(this->label7);
this->Controls->Add(this->label6);
this->Controls->Add(this->progressBar1);
this->Controls->Add(this->TxPhaseStat);
this->Controls->Add(this->RxAmpStatShort);
this->Controls->Add(this->RxPhaseStat);
this->Controls->Add(this->label5);
this->Controls->Add(this->label4);
this->Controls->Add(this->TxPhaseButton);
this->Controls->Add(this->label2);
this->Controls->Add(this->RxPhaseButton);
this->Controls->Add(this->Cancelbutton);
this->Controls->Add(this->OKbutton);
this->Controls->Add(this->label1);
this->Controls->Add(this->Optional);
this->Font = (gcnew System::Drawing::Font(L"Verdana", 9.75F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->Location = System::Drawing::Point(128, 239);
this->Name = L"InstrumentCal";
this->Text = L"Detector Cal";
this->Load += gcnew System::EventHandler(this, &InstrumentCal::InstrumentCal_Load);
this->ResumeLayout(false);
this->PerformLayout();
}
private: VNADevice^ VNA; ///< Vector Network Analyzer hardware object
private: InstrumentCalDataSet^ Cal; ///< Calibration Data Set
private: FrequencyGrid^ FG; ///< Our frequency grid
private: String^ AllUsersDir; ///< Application data directory common to all users
private: array<UInt16>^ Iphase, ^Qphase; ///< hold phase detector results from sweep
private: array<UInt16>^ IphaseLo; ///< hold tran I phase from -20 db sweep.
private: array<UInt16,2>^ ReflMagRegression; ///< Reflection Magnitude vs level sweep
private: array<UInt16,2>^ ReflMagPhDir; ///< Directivity Magnitude & Phase data from reflection sweep
private: array<UInt16,2>^ ReflMagPhOpen; ///< Open Magnitude & Phase data from reflection sweep
private: array<UInt16,2>^ ReflMagPhShort; ///< Shorted Magnitude & Phase data from reflection sweep
private: array<UInt16,2>^ ReflDetailMagPhShort; ///< Shorted Cable Detailed Mag & Phase data from reflection sweep
private: array<UInt16,2>^ ReflDetailMagPhOpen; ///< Open Cable Detailed Mag & Phase data from reflection sweep
private: array<UInt16,2>^ ReflLongDetailMagPhOpen; ///< Terminated 3m Cable Detailed Mag & Phase data from reflection sweep
private: array<UInt16,2>^ ReflLongDetailMagPhShort; ///< Terminated 3m Cable Detailed Mag & Phase data from reflection sweep
private: array<UInt16,2>^ TranMag; ///< Transmission magnitude detector vs level sweep
private: array<UInt16>^ BufferI, ^BufferQ, ^BufferILo;
private: array<UInt16>^ BufferN, ^BufferM; ///< Temporary raw readings
private: array<UInt16>^ BufferP;
private: int MeasFrequency; ///< Measured Frequency from crystal calibration
private: array<Boolean>^CalStepPass; ///< Array of Calibrations Steps. TRUE = step passed
// TODO: Measure surge impedance of calibration cable (R+jX) using 50 ohm load,
// then compute complex reflection expected from that surge impedance vs. angle,
// and fit the S11 measurements to it. NB: The jX component of the surge impedance
// causes negative return loss at angles in the same direction as the sign of jX !
/// Reflection Phase Detector Calibration button click handler
private: System::Void RxPhaseButton_Click(System::Object^ sender, System::EventArgs^ e)
{
// Reflection Phase Detector Calibration
progressBar1->Value = 0;
#if 0
VNA_RXBUFFER *RxBuf = new VNA_RXBUFFER;
VNA_TXBUFFER *TxBuf = new VNA_TXBUFFER;
int Fdesired;
// run a sweep of 1024 points, calibrating Rx phase detector
VNA->Sweep(Cal->GetFreqFromPhaseCalGrid(0), Cal->GetFreqFromPhaseCalGrid(1) - Cal->GetFreqFromPhaseCalGrid(0), PHASECALGRIDSIZE, 10);
for (long i=0; i<PHASECALGRIDSIZE; i++)
{
// Compute spot frequency
Fdesired = Cal->GetFreqFromPhaseCalGrid(i);
TxBuf->TxAccum = i; //FG->DDS(Fdesired);
TxBuf->IDAClevelHi = MAX_DDS_LEVEL; // Max transmit level
TxBuf->ReplyType = 0;
TxBuf->MeasureDelay = 0;
TxBuf->QDAClevel = QDAC_ZERODBM; // Reference level
// Take 7 readings at the same frequency
// for(int k=0; k<7; k++)
// {
VNA->WriteRead(TxBuf, RxBuf, DIR_REFL);
// BufferI[k] = RxBuf->ReflPI;
// BufferQ[k] = RxBuf->ReflPQ;
// }
Iphase[i] = RxBuf->ReflPI; // Median7(BufferI); // use median filter to smooth raw value
Qphase[i] = RxBuf->ReflPQ; // Median7(BufferQ);
progressBar1->Value = i;
if(i%20 == 0)
progressBar1->Update();
}
// Set calibrations to false. PhaseCal sets phaseCalibrated to false when
// it starts. Thus, this needs to be the first step in the instrument cal
// process and makes instrument cal irreversible at this point.
// If the user cancels the cal, then nothing is saved to disk, but
// the user will have to close then restart the application.
// A better solution would be to have each cal step just measure raw data,
// and put all processing and flag alterations in the 'OK' loop.
Cal->DirCoupler->DirCalibrated = false;
Cal->DirCoupler->RippleCalibrated = false;
#endif
// Note that IphaseLo is not meaningful for REFL measurements.
if(true /*Cal->RxDet->PhaseCal(Iphase, Qphase, IphaseLo) */) // TRUE if cal sucessful
{
RxPhaseStat->Image = ICO1Label->Image; // checkmark
CalStepPass[0] = true;
}
else
{
RxPhaseStat->Image = ICO2Label->Image; // 'x'
CalStepPass[0] = false;
ShowCalStepFailMessage();
}
RxPhaseStat->Visible = true;
}
/// Transmission Phase Detector Calibration button click handler
private: System::Void TxPhaseButton_Click(System::Object^ sender, System::EventArgs^ e)
{
// Transmission Phase Detector Calibration
#if 0
VNA_RXBUFFER *RxBuf = new VNA_RXBUFFER;
VNA_TXBUFFER *TxBuf = new VNA_TXBUFFER;
int Fdesired;
progressBar1->Value = 0;
// run a sweep of ~1024 points, calibrating Tx phase detector
// skip really low frequencies and really high frequencies
VNA->Sweep(Cal->GetFreqFromPhaseCalGrid(0), Cal->GetFreqFromPhaseCalGrid(1) - Cal->GetFreqFromPhaseCalGrid(0), PHASECALGRIDSIZE, 10);
for (long i=0; i<PHASECALGRIDSIZE; i++)
{
// Compute spot frequency
Fdesired = Cal->GetFreqFromPhaseCalGrid(i);
TxBuf->TxAccum = i; //FG->DDS(Fdesired);
TxBuf->IDAClevelHi = MAX_DDS_LEVEL; // Max transmit level
TxBuf->ReplyType = 0;
TxBuf->MeasureDelay = 0;
TxBuf->QDAClevel = QDAC_ZERODBM; // Reference level
TxBuf->IDAClevelPhLow = TxLevLinear(0-TARGETPHLOMAG); // Phase Low Ref Level 09-30-2007
// Take 7 readings at the same frequency
// for(int k=0; k<7; k++)
// {
VNA->WriteRead(TxBuf, RxBuf, DIR_TRANS);
// BufferI[k] = RxBuf->TranPI;
// BufferQ[k] = RxBuf->TranPQ;
// BufferILo[k] = RxBuf->TranPILow;
// }
Iphase[i] = RxBuf->TranPI; // Median7(BufferI); // use median filter to smooth raw reading
Qphase[i] = RxBuf->TranPQ; // Median7(BufferQ);
IphaseLo[i] = RxBuf->TranPILow; // Median7(BufferILo);
progressBar1->Value = i;
if(i%20 == 0)
progressBar1->Update();
}
#endif
if(true /* Cal->TxDet->PhaseCal(Iphase, Qphase, IphaseLo) */ ) // TRUE if phase cal was sucessful
{
TxPhaseStat->Image = ICO1Label->Image; // checkmark
CalStepPass[1] = true;
}
else
{
TxPhaseStat->Image = ICO2Label->Image; // 'x'
CalStepPass[1] = false;
ShowCalStepFailMessage();
}
TxPhaseStat->Visible = true;
}
/// OK button click handler
/// Transmission Amplitude Detector Calibration button click handler
private: System::Void TxLowAmpButton_Click(System::Object^ sender, System::EventArgs^ e)
{
// Transmission Amplitude detector Calibration - with 40 dB attenuator in path
#if 0
VNA_RXBUFFER *RxBuf = new VNA_RXBUFFER;
VNA_TXBUFFER *TxBuf = new VNA_TXBUFFER;
int Fdesired;
TxBuf->ReplyType = 0;
TxBuf->MeasureDelay = 0; // No delay
TxBuf->QDAClevel = QDAC_ZERODBM; // Reference level
progressBar1->Value = 0;
// run a sweep of 21 frequencies, calibrating Trans Amplitude detector
VNA->Sweep(Cal->GetFreqFromDetMagCalGrid(0), Cal->GetFreqFromDetMagCalGrid(1) - Cal->GetFreqFromDetMagCalGrid(0), 21, 10);
for (long FreqIdx=0; FreqIdx<21; FreqIdx++)
{
// Compute spot frequency from DetCalGrid Point
Fdesired = Cal->GetFreqFromDetMagCalGrid(FreqIdx);
TxBuf->TxAccum = FreqIdx; //FG->DDS(Fdesired);
for (int levelDB=0; levelDB<30; levelDB++) // Measure over 60 dB range
{
TxBuf->IDAClevelHi = TxLevLinear(-levelDB); // 0 to -29 dbm
TxBuf->IDAClevelLo = TxLevLinear(-levelDB-30); // -30 to -59 dbm
for(int k=0; k<7; k++) // Take 7 readings at each point
{
VNA->WriteRead(TxBuf, RxBuf, DIR_TRANS);
BufferM[k] = RxBuf->TranMQHi;
BufferN[k] = RxBuf->TranMQLo;
}
TranMag[FreqIdx, levelDB] = RxBuf->TranMQHi; // Median7(BufferM); // Filter the readings
TranMag[FreqIdx, levelDB+30] = Median7(BufferN);
}
progressBar1->Value = FreqIdx * progressBar1->Maximum/20;
progressBar1->Update();
}
#endif
// if(Cal->TxDet->AmpCal(TranMag)) // AmpCal forms y = mx + b for transmission detector
{
CalStepPass[2] = true;
TxLowAmpStat->Image = ICO1Label->Image;
}
// else
// {
// CalStepPass[2] = false;
// TxLowAmpStat->Image = ICO2Label->Image;
// ShowCalStepFailMessage();
// }
TxLowAmpStat->Visible = true;
}
private: System::Void FrequencyCalButton_Click(System::Object^ sender, System::EventArgs^ e)
{
// Internal Crystal Frequency Calibration
// Starts out with whatever initial value of FG->Error happens to be.
// This allows iterating to a better error estimate over several
// frequency cal cycles if desired.
VNA_RXBUFFER *RxBuf = new VNA_RXBUFFER;
VNA_TXBUFFER *TxBuf = new VNA_TXBUFFER;
int Fdesired;
Fdesired = 100000000; // output 100 MHz
TxBuf->TxAccum = FG->DDS(Fdesired);
TxBuf->IDAClevelHi = MAX_DDS_LEVEL; // Max transmit level
TxBuf->ReplyType = 0;
TxBuf->MeasureDelay = 0;
TxBuf->QDAClevel = QDAC_ZERODBM; // Reference level
VNA->WriteRead(TxBuf, RxBuf, DIR_TRANS); // write the VNA with CW frequency output
}
private: System::Void FreqEnterButton_Click(System::Object^ sender, System::EventArgs^ e)
{
// Get frequency error from the text box and error check it.
// If valid, update the frequency error.
try
{
MeasFrequency = Convert::ToInt32(MeasFreqTextBox->Text);
}
catch (System::FormatException^ pe)
{
MessageBox::Show(pe->Message, "Error");
}
catch (System::OverflowException^ pe)
{
MessageBox::Show(pe->Message, "Error");
}
if((MeasFrequency > 103000000) || (MeasFrequency < 97000000)) // bad data likely
MessageBox::Show("Value appears to be invalid, re-enter","Error");
else
{
FrequencyCalStat->Visible = true;
FG->ferror += MeasFrequency - 100000000;
}
}
private: System::Void DirectivityCalButton_Click(System::Object^ sender, System::EventArgs^ e)
{
// Measure the directivity of the coupler at 21 frequency points
// by using a well-terminated load directly on the TX connector.
VNA_RXBUFFER *RxBuf = new VNA_RXBUFFER;
VNA_TXBUFFER *TxBuf = new VNA_TXBUFFER;
__int64 Fdesired;
__int64 maxFreq = VNA->GetMaxFreq();
__int64 minFreq = VNA->GetMinFreq();
TxBuf->ReplyType = 0;
TxBuf->MeasureDelay = 0;
TxBuf->QDAClevel = QDAC_ZERODBM; // Reference level
TxBuf->IDAClevelHi = MAX_DDS_LEVEL; // Max transmit level
progressBar1->Value = 0;
// run a sweep of 1024 frequencies, calibrating Refl Amplitude detector
VNA->Sweep(Cal->GetFreqFromPhaseCalGrid(0), Cal->GetFreqFromPhaseCalGrid(1) - Cal->GetFreqFromPhaseCalGrid(0), PHASECALGRIDSIZE, 10, progressBar1);
VNA->Sweep(minFreq, (maxFreq/PHASECALGRIDSIZE), PHASECALGRIDSIZE, 10, progressBar1);
for (long FreqIdx=0; FreqIdx<PHASECALGRIDSIZE; FreqIdx++)
{
// Compute spot frequency
Fdesired = Cal->GetFreqFromPhaseCalGrid(FreqIdx);
TxBuf->TxAccum = FreqIdx; //FG->DDS(Fdesired);
TxBuf->IDAClevelHi = TxLevLinear(0); // 0 dbm
VNA->WriteRead(TxBuf, RxBuf, DIR_REFL);