pflib v3.9.0-rc3-11-g2537d8f
Pretty Fine HGCROC Interaction Library
Loading...
Searching...
No Matches
power_ctl_mezz.h
1#ifndef POWER_CTL_MEZZ_H_INCLUDED
2#define POWER_CTL_MEZZ_H_INCLUDED
3
4#include "ad5593r.h"
5
6namespace pflib {
7
9 static constexpr int POWER_GD = 0;
10 static constexpr int VECON = 1;
11 static constexpr int ISENSE = 2;
12 static constexpr int MARGSEL = 3;
13 static constexpr int MARGTOL = 4;
14 static constexpr int VTUNE0 = 5;
15 static constexpr int VTUNE1 = 6;
16 static constexpr int VTUNE2 = 7;
17
18 public:
19 power_ctl_mezz(const std::string& path, bool keep_settings = false)
20 : regctl_(path, 0x11) {
21 regctl_.setup_gpi(POWER_GD);
22 regctl_.setup_adc(VECON);
23 regctl_.setup_adc(ISENSE);
24 if (!keep_settings) {
25 // default is margining off
26 regctl_.setup_gpi(MARGSEL);
27 // default is 3% margin
28 regctl_.setup_gpi(MARGTOL);
29 // default is 1.2v
30 regctl_.setup_gpo(VTUNE2, 0);
31 regctl_.setup_gpo(VTUNE1, 1);
32 regctl_.setup_gpo(VTUNE0, 1);
33 }
34 }
35
36 private:
37 void vtune(int ibit, int val) {
38 const int pinmap[] = {VTUNE0, VTUNE1, VTUNE2};
39 if (ibit < 0 || ibit > 2) return;
40 int pin = pinmap[ibit];
41 if (val < 0) {
42 regctl_.setup_gpi(pin, false);
43 } else {
44 regctl_.setup_gpo(pin, (val > 0));
45 }
46 }
47
48 public:
49 void set_volts(float voltage) {
50 int ivolts = int((voltage + 0.02) / 50e-3) - (16);
51 const int maptable[15][3] = {
52 {0, 0, 0}, {0, 0, -1}, {0, 0, 1}, {0, -1, 0}, {0, -1, -1},
53 {0, -1, 1}, {0, 1, 0}, {0, 1, -1}, {0, 1, 1}, {-1, 0, 0},
54 {-1, 0, -1}, {-1, 0, 1}, {-1, -1, 0}, {-1, -1, -1}, {-1, -1, 1}};
55 // eventually, we could add margining to tune even more...
56 if (ivolts >= 0 && ivolts < 15) {
57 vtune(0, maptable[ivolts][2]);
58 vtune(1, maptable[ivolts][1]);
59 vtune(2, maptable[ivolts][0]);
60 }
61 }
62
63 float get_setting() {
64 const int pinmap[] = {VTUNE2, VTUNE1, VTUNE0};
65 int index = 0;
66 for (int i = 0; i < 3; i++) {
67 int pin = pinmap[i];
68 index = index * 3;
69 if (regctl_.is_gpo(pin)) {
70 if (regctl_.gpo_get_value(pin)) index = index + 2;
71 } else
72 index = index + 1;
73 }
74 return ((index + 16) * 50e-3);
75 }
76
77 float econ_volts() { return regctl_.adc_volts(VECON); }
78
79 float econ_current_mA() {
80 float deltaV = regctl_.adc_volts(ISENSE) - regctl_.adc_volts(VECON);
81 return deltaV / 50e-3 * 1000;
82 }
83
84 private:
85 AD5593R regctl_;
86};
87
88} // namespace pflib
89
90#endif // POWER_CTL_MEZZ_H_INCLUDED
Partial clone from python code, with just needed functionalities for testing for now.
Definition ad5593r.h:12
Definition power_ctl_mezz.h:8
This version of the fast control code interfaces with the CMS Fast control library which can be contr...
Definition Backend.cxx:3