SEPIA
Software documentation for the APEX SEPIA receivers
cartridge.h
Go to the documentation of this file.
1 /* Copyright 2017 Michael Olberg <michael.olberg@chalmers.se> */
2 #ifndef CARTRIDGE_H
3 #define CARTRIDGE_H
4 
5 #include <QTimerEvent>
6 #include <QString>
7 #include <QStringList>
8 #include <QVector>
9 #include <QSettings>
10 #include <QFileSystemWatcher>
11 #include <QMutex>
12 #include <QRunnable>
13 
14 #include <unistd.h>
15 
16 #include "tuning.h"
17 #include "network.h"
18 
19 #include "CANbus/inireader.h"
20 #include "CANbus/mcunit.h"
21 #include "Synthesizer/agilent.h"
22 #include "Synthesizer/anritsu.h"
23 #include "PowerMeter/powermeter.h"
24 
25 #include "GUI/mixer.h"
26 #include "GUI/lownoiseamplifier.h"
27 #include "constants.h"
28 
37 class Cartridge;
38 
51 QMutex *mutex(Mixer::Polarization pol, Mixer::Element sis);
52 
62 class PolRunnable : public QRunnable
63 {
64  public:
72 
76  virtual void run() = 0;
77 
78  protected:
79  Cartridge *band;
80  Mixer::Polarization m_pol;
81 };
82 
94 class SisRunnable : public QRunnable
95 {
96  public:
105 
109  virtual void run() = 0;
110 
111  protected:
112  Cartridge *band;
113  Mixer::Polarization m_pol;
114  Mixer::Element m_sis;
115 };
116 
121 class BiasSetter : public SisRunnable
122 {
123  public:
132  BiasSetter(Cartridge *parent, Mixer::Polarization pol, Mixer::Element sis, float value);
133 
137  void run();
138  private:
139  float m_val;
140 };
141 
146 class CoilSetter : public SisRunnable
147 {
148  public:
157  CoilSetter(Cartridge *parent, Mixer::Polarization pol, Mixer::Element sis, float value);
158 
162  void run();
163  private:
164  float m_val;
165 };
166 
171 class IVscanner : public SisRunnable
172 {
173  public:
185  double V0, double V1, int steps);
186 
190  void run();
191  private:
192  double m_v0;
193  double m_v1;
194  int m_steps;
195 };
196 
205 class Demagnetizer : public SisRunnable
206 {
207  public:
216 
220  void run();
221 };
222 
227 class Defluxer : public PolRunnable
228 {
229  public:
236  Defluxer(Cartridge *parent, Mixer::Polarization pol);
237 
241  void run();
242 };
243 
267 class Cartridge : public QObject
268 {
269  Q_OBJECT
270  Q_PROPERTY(int yig READ getYIG WRITE updateYIG);
271  Q_PROPERTY(InternalState state READ state WRITE setState NOTIFY stateChanged)
272  Q_PROPERTY(TuneState tuneState READ tuneState WRITE setTuneState NOTIFY tuneStateChanged)
273 
274  friend class BiasSetter;
275  friend class CoilSetter;
276  static const double lockRange;
277  static const float invalid;
278 
279  public:
280  enum InternalState {
281  SHUTDOWN,
282  INITIALIZED,
283  RESET,
284  DISABLED,
285  ENABLED,
286  FAULTED
287  };
288  Q_ENUM(InternalState)
289 
290  enum TuneState {
291  UNTUNED,
292  TUNING,
293  TUNED
294  };
295  Q_ENUM(TuneState)
296 
297 
313  Cartridge(const QString &name, Sepia::Channel channel, double WCAmultiplier, double YIGmultiplier,
314  double lowerYigLimit, double upperYigLimit, QObject *parent = 0);
318  virtual ~Cartridge();
319 
320  InternalState state() const { return m_state; }
321  TuneState tuneState() const { return t_state; }
322 
333  void setMonitorChannels(const QStringList &channels);
334 
339  double lowerLimit() const { return m_range[0]; }
340 
345  double upperLimit() const { return m_range[1]; }
346 
354  float biasOffset(int pol, int sis) const { return offV[pol][sis-1]; }
355 
363  float currentOffset(int pol, int sis) const { return offC[pol][sis-1]; }
364 
372  float coilCurrentPreset(int pol, int sis) const { return coilC[pol][sis-1]; }
373 
379  float gateVoltagePreset(int pol) const { return gateV[pol]; }
380 
388  QVector<double> biasTrace(int pol, int sis) const { return t_mV[pol][sis-1]; }
389 
397  QVector<double> currentTrace(int pol, int sis) const { return t_uA[pol][sis-1]; }
398 
408  QVector<double> powerTrace(int pol, int sis) const { return t_mW[pol][sis-1]; }
409 
415  int getYIG() const { return lastYIG; }
416 
422  double synthFreq() const { return _synthGHz; }
423 
429  double synthLevel() const { return _synthdBm; }
430 
438  float sisCurrent(Mixer::Polarization pol, Mixer::Element sis);
439 
447  float sisVoltage(Mixer::Polarization pol, Mixer::Element sis);
448 
458  float sisPower(Mixer::Polarization pol, Mixer::Element sis);
459 
468  float drainVoltage(Mixer::Polarization pol, Mixer::Element sis, LNA::Stage stage);
469 
478  float drainCurrent(Mixer::Polarization pol, Mixer::Element sis, LNA::Stage stage);
479 
488  float gateVoltage(Mixer::Polarization pol, Mixer::Element sis, LNA::Stage stage);
489 
496  float paGateVoltage(Mixer::Polarization pol);
497 
504  float paDrainVoltage(Mixer::Polarization pol);
505 
512  float paDrainCurrent(Mixer::Polarization pol);
513 
527  void setCoilCurrent(Mixer::Polarization pol, Mixer::Element sis, float mA, bool fast = false);
528 
542  void setSisVoltage(Mixer::Polarization pol, Mixer::Element sis, float mV, bool fast = false);
543 
551  bool sisOpenLoop(Mixer::Polarization pol, Mixer::Element sis);
552 
560  void setSisOpenLoop(Mixer::Polarization pol, Mixer::Element sis, bool flag);
561 
570  void setDrainVoltage(Mixer::Polarization pol, Mixer::Element sis, LNA::Stage stage, float V);
571 
580  void setDrainCurrent(Mixer::Polarization pol, Mixer::Element sis, LNA::Stage, float mA);
581 
589  void setLNAenable(Mixer::Polarization pol, Mixer::Element sis, bool flag);
590 
597  void setPaGateVoltage(Mixer::Polarization pol, float V);
598 
605  void setPaDrainVoltage(Mixer::Polarization pol, float V);
606 
611  void setAmcADrainVoltage(float V) { setRealValue("SET_AMC_A_DRAIN_V", V); }
612 
617  void setAmcBDrainVoltage(float V) { setRealValue("SET_AMC_B_DRAIN_V", V); }
618 
623  void setAmcEDrainVoltage(float V) { setRealValue("SET_AMC_E_DRAIN_V", V); }
624 
629  void setAmcAGateVoltage(float V) { setRealValue("SET_AMC_A_GATE_V", V); }
630 
635  void setAmcBGateVoltage(float V) { setRealValue("SET_AMC_B_GATE_V", V); }
636 
641  void setAmcEGateVoltage(float V) { setRealValue("SET_AMC_E_GATE_V", V); }
642 
648  void setAmcDMultVoltage(float V) { setRealValue("SET_AMC_D_MULT_V", V); }
649 
654  float amcAGateVoltage() { return getRealValue("GET_AMC_A_GATE_V"); }
655 
660  float amcADrainVoltage() { return getRealValue("GET_AMC_A_DRAIN_V"); }
661 
666  float amcADrainCurrent() { return getRealValue("GET_AMC_A_DRAIN_C"); }
667 
672  float amcBGateVoltage() { return getRealValue("GET_AMC_B_GATE_V"); }
673 
678  float amcBDrainVoltage() { return getRealValue("GET_AMC_B_DRAIN_V"); }
679 
684  float amcBDrainCurrent() { return getRealValue("GET_AMC_B_DRAIN_C"); }
685 
690  float amcEGateVoltage() { return getRealValue("GET_AMC_E_GATE_V"); }
691 
696  float amcEDrainVoltage() { return getRealValue("GET_AMC_E_DRAIN_V"); }
697 
702  float amcEDrainCurrent() { return getRealValue("GET_AMC_E_DRAIN_C"); }
703 
708  float amcMultiDVoltage() { return getRealValue("GET_AMC_MULT_D_V"); }
709 
714  float amcMonitor5V() { return getRealValue("GET_AMC_5V_MON"); }
715 
724  float coilCurrent(Mixer::Polarization pol, Mixer::Element sis);
725 
734  float coilVoltage(Mixer::Polarization pol, Mixer::Element sis);
735 
743  float heaterCurrent(Mixer::Polarization pol);
744 
752  float mixerTemperature(Mixer::Polarization pol);
753 
760  void heaterState(Mixer::Polarization pol, bool on);
761 
767  void toggleHeater(Mixer::Polarization pol);
768 
773  float pllLockVoltage() { return getRealValue("GET_PLL_LOCK_V"); }
774 
779  float pllCorrVoltage() { return getRealValue("GET_PLL_CORR_V"); }
780 
785  float pllRefTotalPower() { return getRealValue("GET_PLL_REF_TOTAL_P"); }
786 
791  float pllIfTotalPower() { return getRealValue("GET_PLL_IF_TOTAL_P"); }
792 
797  float pllAssemblyTemperature() { return getRealValue("GET_PLL_ASSEMBLY_T"); }
798 
803  bool LOlockLatch() { return getFlag("GET_LO_LOCK_LATCH"); }
804 
808  void LOclearLatch() { setFlag("SET_CLEAR_LO_LATCH", true); }
809 
814  void setNullPllIntegrator(bool flag) { setFlag("SET_NULL_PLL_INTEGRATOR", flag); }
815 
820  void setPllLoopBandwidth(bool flag) { setFlag("SET_PLL_LOOP_BW", flag); }
821 
826  void setPllSideband(bool lower) { setFlag("SET_SB_LOCK_POL", lower); }
827 
832  void setCoarseTune(unsigned short value) { setWord("SET_YTO_COARSE_TUNE", value); }
833 
843  virtual void tuneLO(double ghz, int harmonic) = 0;
844 
857  virtual void tuneMixer(Mixer::Polarization pol, float bias[2], float Igoal, float power, float maxPower) = 0;
865  void tuneSynthesizer(double WCAfreq, int harmonic, bool upper);
866 
867  public slots:
876  void resetBand();
877 
889  void run();
890 
891  void initialize();
892  void reset();
893  void shutdown();
894 
908  virtual void initBand(bool withDeflux) = 0;
909 
917  virtual void shutdownBand() = 0;
918 
927  virtual void tuneLO(double ghz);
928 
937  virtual void tuneMixer(Mixer::Polarization pol);
938 
944  void tuneSystem(double ghz);
945 
952  virtual void demagnetize(Mixer::Polarization pol, Mixer::Element sis) = 0;
953 
959  virtual void deflux(Mixer::Polarization pol) = 0;
960 
965  void disable();
966 
971  void enable();
972 
981  void demagnetizeMixers(bool p0s1, bool p0s2, bool p1s1, bool p1s2);
982 
989  void defluxMixers(bool p0, bool p1);
990 
994  void setLNADefaults();
995 
1006  void cleanup();
1007 
1020  void updateYIG(int value);
1021 
1026  void changeSynthFreq(double ghz);
1027 
1032  void changeSynthLevel(double dBm);
1033 
1038  void switchSynth(bool flag);
1039 
1049  void IVscan(Mixer::Polarization pol, Mixer::Element sis, double from, double to, int steps, bool withPower);
1050 
1058  void scanMixers(double from, double to, int steps);
1059 
1063  void resetSisVoltages();
1064 
1068  void resetCoilCurrents();
1069 
1073  void resetLNAs();
1074 
1078  void setCoilCurrents();
1079 
1083  void setPaGateVoltages();
1084 
1095  void showCurve(Mixer::Polarization pol, Mixer::Element sis,
1096  QVector<double> x, QVector<double> y, QVector<double> z,
1097  const QString &xlab = QString::fromUtf8("mixer bias [mV]"),
1098  const QString &ylab = QString::fromUtf8("mixer current [µA]"));
1099 
1107  bool pllControl(float *vcorr, float *vlock);
1108 
1114  void cryoControl(bool flag);
1115 
1121  void preparePLL(bool upper);
1122 
1126  void addChannel(Sepia::Channel channel);
1127 
1131  void removeChannel(Sepia::Channel channel);
1132 
1138  float getRealValue(QString name);
1139 
1145  bool getFlag(QString name);
1146 
1152  unsigned short getWord(QString name);
1153 
1154  void updateCryo(float T4K, float T12K, float chanC, float chanD, float p);
1155 
1156  protected:
1162  void setFlag(QString name, bool flag);
1163 
1169  void setRealValue(QString name, float v);
1170 
1176  void setWord(QString name, unsigned short w);
1177 
1178  signals:
1179  void stateChanged(Cartridge::InternalState s);
1180  void tuneStateChanged(Cartridge::TuneState s);
1181 
1188  void demagnetized(Mixer::Polarization pol, Mixer::Element sis, bool ok);
1189 
1195  void defluxed(Mixer::Polarization pol, bool ok);
1196 
1200  void faulted(Sepia::ErrorCode code);
1201 
1209  void pllStatus(bool locked, float Vlock, float Vcorr);
1210 
1220  void updateMonitorItem(const QString &name, DWORD addr, float v, char unit, int gain);
1221 
1226  void percentDone(int percent);
1227 
1232  void statusMessage(const QString &msg);
1233 
1238  void synthConnected(bool flag);
1239 
1240  void mcConnected(bool flag);
1241  void mcEnabled(bool flag);
1242 
1247  void synthSwitched(bool on);
1248 
1253  void synthFreqChanged(double ghz);
1254 
1259  void synthLevelChanged(double dbm);
1260 
1265  void yigChanged(int value);
1266 
1277  void pointReady(Mixer::Polarization pol, Mixer::Element sis,
1278  int i, double mV, double mA, double mW);
1279 
1291  void traceReady(Mixer::Polarization pol, Mixer::Element sis,
1292  QVector<double> x, QVector<double> y, QVector<double> z,
1293  const QString &xlab, const QString &ylab);
1298  void LOtuned(bool ok);
1299 
1304  void LOmodified(bool flag);
1305 
1310  void newCmdLOfrequency(double ghz);
1311 
1316  void newCmdHarmonic(int harmonic);
1317 
1324  void mixerTuned(Mixer::Polarization pol, bool ok);
1325 
1330  void systemTuned(bool ok);
1331 
1339  void newMixerCurrent(Mixer::Polarization pol, Mixer::Element sis, float mA);
1340 
1348  void newCmdMixerBias(Mixer::Polarization pol, Mixer::Element sis, float mV);
1349 
1357  void newMixerBias(Mixer::Polarization pol, Mixer::Element sis, float mV);
1358 
1366  void newMixerPower(Mixer::Polarization pol, Mixer::Element sis, float mW);
1367 
1375  void newCoilCurrent(Mixer::Polarization pol, Mixer::Element sis, float mA);
1376 
1384  void newCmdCoilCurrent(Mixer::Polarization pol, Mixer::Element sis, float mA);
1385 
1394  void newDrainVoltage(Mixer::Polarization pol, Mixer::Element sis, LNA::Stage stage, float V);
1395 
1404  void newCmdDrainVoltage(Mixer::Polarization pol, Mixer::Element sis, LNA::Stage stage, float V);
1405 
1414  void newDrainCurrent(Mixer::Polarization pol, Mixer::Element sis, LNA::Stage stage, float mA);
1415 
1424  void newCmdDrainCurrent(Mixer::Polarization pol, Mixer::Element sis, LNA::Stage stage, float mA);
1425 
1434  void newGateVoltage(Mixer::Polarization pol, Mixer::Element sis, LNA::Stage stage, float V);
1435 
1442  void newCmdPaDrainVoltage(Mixer::Polarization pol, float V);
1443 
1447  void stabilize(double T);
1448 
1449  private slots:
1450  void timerEvent(QTimerEvent *event);
1451  void mcError(DWORD status);
1452  void getBandSettings();
1453  void synthConnected();
1454  void synthDisconnected();
1455  void setTuneState(TuneState s);
1456 
1457  private:
1458  void healthCheck();
1459  void getMonitoring(int i);
1460  void getHouseKeeping();
1461 
1462  bool needLOTuning();
1463  void storeTuning();
1464 
1465  int myTimerId;
1466  QFileSystemWatcher *watcher;
1467 
1468  const QString bandname;
1469  Sepia::Channel m_band;
1470  InternalState m_state;
1471  TuneState t_state;
1472 
1473  IniFileReader sr;
1474  QSettings settings;
1475 
1476  QStringList monitorChannels;
1477 
1478  MCunit *mc;
1479  Synthesizer *anritsu;
1480  PowerMeter *pm;
1481  bool m_usepm;
1482 
1483  double _synthGHz;
1484  double _synthdBm;
1485  bool _synthOn;
1486 
1487  float offV[2][2];
1488  float offC[2][2];
1489 
1490  float drainV[2][2][3];
1491  float drainC[2][2][3];
1492 
1493  float coilC[2][2];
1494  float gateV[2];
1495 
1496  double m_T4Kloop;
1497  double m_dbm;
1498 
1499  float m_pol0T;
1500  float m_pol1T;
1501  float m_T4K;
1502  float m_chanA;
1503  float m_chanB;
1504  float m_chanC;
1505  float m_chanD;
1506  float m_mbar;
1507 
1508  protected:
1509  QMutex canbus;
1510  QMutex synthesizer;
1511  QMutex tuning;
1512 
1513  int lastYIG;
1514  int _harmonic;
1515  double _ghz;
1516  double m_range[2];
1517  double m_wca;
1518  double m_yig;
1519  double f_yiglo;
1520  double f_yighi;
1521  int lastcoarse;
1522 
1523  bool _isModified;
1524  bool _isLocked;
1525  bool _isTuned[2];
1526  bool _isCold;
1527 
1528  Tuning actTuning;
1529  Tuning cmdTuning;
1530 
1531  int s_steps;
1532  double s_range[2];
1533 
1534  QVector<double> t_mV[2][2];
1535  QVector<double> t_uA[2][2];
1536  QVector<double> t_mW[2][2];
1537 
1538  protected slots:
1539  void setState(InternalState s);
1540 };
1541 
1542 Q_DECLARE_METATYPE(DWORD)
1543 Q_DECLARE_METATYPE(QVector<double>)
1544 
1545 #endif // CARTRIDGE_H
void setAmcBGateVoltage(float V)
Set the AMC-B gate voltage.
Definition: cartridge.h:635
A class to control the power meter.
Definition: powermeter.h:19
float amcMultiDVoltage()
Get the current AMC-MULT_D voltage.
Definition: cartridge.h:708
Stage
An enumeration for the stages of a low noise amplifier.
Definition: constants.h:35
float pllIfTotalPower()
Get the PLL IF total power.
Definition: cartridge.h:791
double upperLimit() const
Return the upper limit of the LO tuning range in GHz.
Definition: cartridge.h:345
void setPllLoopBandwidth(bool flag)
Set/clear PLL loop bandwidth.
Definition: cartridge.h:820
void setPllSideband(bool lower)
Set PLL sideband.
Definition: cartridge.h:826
float biasOffset(int pol, int sis) const
Return the bias offset.
Definition: cartridge.h:354
Virtual class to run a mixer operations in parallel.
Definition: cartridge.h:62
A class representing a LO/mixer tuning.
Definition: tuning.h:16
A header file for commonly used constants.
double lowerLimit() const
Return the lower limit of the LO tuning range in GHz.
Definition: cartridge.h:339
float currentOffset(int pol, int sis) const
Return the current offset.
Definition: cartridge.h:363
A class for taking an IV curve.
Definition: cartridge.h:171
double synthFreq() const
Get the current synthesizer frequency.
Definition: cartridge.h:422
void setNullPllIntegrator(bool flag)
Set/clear null PLL integrator.
Definition: cartridge.h:814
Polarization
An enumeration for the two polarizations.
Definition: constants.h:9
virtual void run()=0
Run method needs to be implemented by all derived classes.
float amcADrainVoltage()
Get the current AMC_A drain voltage.
Definition: cartridge.h:660
bool LOlockLatch()
Get the state of the PLL lock latch.
Definition: cartridge.h:803
A class to handle all communication with the M&C unit via CANbus.
Definition: mcunit.h:34
float amcADrainCurrent()
Get the current AMC_A drain current.
Definition: cartridge.h:666
Element
An enumeration for the two mixer elements in each polarization.
Definition: constants.h:17
float pllLockVoltage()
Get the PLL lock voltage.
Definition: cartridge.h:773
void setAmcBDrainVoltage(float V)
Set the AMC-B drain voltage.
Definition: cartridge.h:617
A class to control the Anritsu synthesizer.
Definition: anritsu.h:18
void setAmcADrainVoltage(float V)
Set the AMC-A drain voltage.
Definition: cartridge.h:611
Virtual class to run mixer operations in parallel.
Definition: cartridge.h:94
int getYIG() const
Get the lates YIG setting.
Definition: cartridge.h:415
PolRunnable(Cartridge *parent, Mixer::Polarization pol)
Constructor.
Definition: cartridge.cpp:54
A virtual class representing a cartridge.
Definition: cartridge.h:267
void LOclearLatch()
Clear the PLL lock latch.
Definition: cartridge.h:808
float amcMonitor5V()
Get the AMC 5V monitor signal.
Definition: cartridge.h:714
float amcEDrainVoltage()
Get the current AMC_E drain voltage.
Definition: cartridge.h:696
float amcEDrainCurrent()
Get the current AMC_E drain current.
Definition: cartridge.h:702
float amcAGateVoltage()
Get the current AMC_A gate voltage.
Definition: cartridge.h:654
Layout of the local network.
A class for demagnetizing a mixer element.
Definition: cartridge.h:205
A class representing a LO/mixer tuning.
QVector< double > biasTrace(int pol, int sis) const
Retrieve the results for the mixer bias from the latest IV scan.
Definition: cartridge.h:388
A class to parse Andrey Ermakov&#39;s ini file.
Definition: inireader.h:40
float amcBGateVoltage()
Get the current AMC_B gate voltage.
Definition: cartridge.h:672
void setAmcAGateVoltage(float V)
Set the AMC-A gate voltage.
Definition: cartridge.h:629
void setAmcEDrainVoltage(float V)
Set the AMC-E drain voltage.
Definition: cartridge.h:623
float amcBDrainVoltage()
Get the current AMC_B drain voltage.
Definition: cartridge.h:678
float gateVoltagePreset(int pol) const
Return the default setting of the gate voltage.
Definition: cartridge.h:379
QVector< double > powerTrace(int pol, int sis) const
Retrieve the results for the total power from the latest IV scan.
Definition: cartridge.h:408
double synthLevel() const
Get the current synthesizer level setting.
Definition: cartridge.h:429
A class for setting the coil current.
Definition: cartridge.h:146
Channel
An enumeration for the three SEPIA channels (cartridges).
Definition: constants.h:66
float coilCurrentPreset(int pol, int sis) const
Return the default setting of the coil current.
Definition: cartridge.h:372
float pllAssemblyTemperature()
Get the PLL assembly temperature.
Definition: cartridge.h:797
QVector< double > currentTrace(int pol, int sis) const
Retrieve the results for the mixer current from the latest IV scan.
Definition: cartridge.h:397
QMutex * mutex(Mixer::Polarization pol, Mixer::Element sis)
Return a pointer to the mutex associated with given mixer element.
Definition: cartridge.cpp:24
void setCoarseTune(unsigned short value)
update YIG oscillator setting
Definition: cartridge.h:832
float pllCorrVoltage()
Get the PLL correction voltage.
Definition: cartridge.h:779
float amcEGateVoltage()
Get the current AMC_E gate voltage.
Definition: cartridge.h:690
void setAmcDMultVoltage(float V)
Set the AMC-MULT_D voltage.
Definition: cartridge.h:648
A class for setting the mixer bias.
Definition: cartridge.h:121
float amcBDrainCurrent()
Get the current AMC_B drain current.
Definition: cartridge.h:684
float pllRefTotalPower()
Get the PLL reference total power.
Definition: cartridge.h:785
A class to perform a deflux operation.
Definition: cartridge.h:227
void setAmcEGateVoltage(float V)
Set the AMC-E gate voltage.
Definition: cartridge.h:641