123

Dependencies:   mbed

Fork of LG by igor Apu

Committer:
Diletant
Date:
Sun Jul 31 06:19:02 2016 +0000
Revision:
183:c7a9c309086c
Parent:
177:672ef279c8e0
Device&... update. More AskGld&Techno functionality.NotFinal!!!

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Diletant 161:efd949e8d536 1 #include "Device.h"
Diletant 161:efd949e8d536 2
Diletant 161:efd949e8d536 3 extern Device device;
Diletant 161:efd949e8d536 4
Diletant 167:bedc0a9d559a 5 void InitISACSOutputDefaultSettings(void){
Diletant 177:672ef279c8e0 6 device.isacs.regulator.settings.start.enabled = 1;
Diletant 177:672ef279c8e0 7 device.isacs.regulator.settings.regular.enabled = 1;
Diletant 177:672ef279c8e0 8 device.isacs.regulator.settings.reset.enabled = 1;
Diletant 177:672ef279c8e0 9
Diletant 177:672ef279c8e0 10 device.isacs.regulator.settings.transfer.points = 16;
Diletant 177:672ef279c8e0 11 device.isacs.regulator.settings.transfer.error[0] = -0x20000; //-2.0V
Diletant 177:672ef279c8e0 12 device.isacs.regulator.settings.transfer.correction[0] = 0x10000; //1.0
Diletant 177:672ef279c8e0 13 device.isacs.regulator.settings.transfer.error[1] = -0x1bbbb; //-1.7333333333333334V
Diletant 177:672ef279c8e0 14 device.isacs.regulator.settings.transfer.correction[1] = 0xb473; //0.7048888888888889
Diletant 177:672ef279c8e0 15 device.isacs.regulator.settings.transfer.error[2] = -0x17777; //-1.4666666666666668V
Diletant 177:672ef279c8e0 16 device.isacs.regulator.settings.transfer.correction[2] = 0x7aa7; //0.47911111111111115
Diletant 177:672ef279c8e0 17 device.isacs.regulator.settings.transfer.error[3] = -0x13333; //-1.2V
Diletant 177:672ef279c8e0 18 device.isacs.regulator.settings.transfer.correction[3] = 0x4fdf; //0.31199999999999994
Diletant 177:672ef279c8e0 19 device.isacs.regulator.settings.transfer.error[4] = -0xeeee; //-0.9333333333333333V
Diletant 177:672ef279c8e0 20 device.isacs.regulator.settings.transfer.correction[4] = 0x3161; //0.1928888888888889
Diletant 177:672ef279c8e0 21 device.isacs.regulator.settings.transfer.error[5] = -0xaaaa; //-0.6666666666666667V
Diletant 177:672ef279c8e0 22 device.isacs.regulator.settings.transfer.correction[5] = 0x1c71; //0.11111111111111113
Diletant 177:672ef279c8e0 23 device.isacs.regulator.settings.transfer.error[6] = -0x6666; //-0.3999999999999999V
Diletant 177:672ef279c8e0 24 device.isacs.regulator.settings.transfer.correction[6] = 0xe56; //0.05599999999999999
Diletant 177:672ef279c8e0 25 device.isacs.regulator.settings.transfer.error[7] = -0x2222; //-0.1333333333333333V
Diletant 177:672ef279c8e0 26 device.isacs.regulator.settings.transfer.correction[7] = 0x452; //0.016888888888888884
Diletant 177:672ef279c8e0 27 device.isacs.regulator.settings.transfer.error[8] = 0x2222; //0.1333333333333333V
Diletant 177:672ef279c8e0 28 device.isacs.regulator.settings.transfer.correction[8] = -0x452; //-0.016888888888888884
Diletant 177:672ef279c8e0 29 device.isacs.regulator.settings.transfer.error[9] = 0x6666; //0.3999999999999999V
Diletant 177:672ef279c8e0 30 device.isacs.regulator.settings.transfer.correction[9] = -0xe56; //-0.05599999999999999
Diletant 177:672ef279c8e0 31 device.isacs.regulator.settings.transfer.error[10] = 0xaaaa; //0.6666666666666665V
Diletant 177:672ef279c8e0 32 device.isacs.regulator.settings.transfer.correction[10] = -0x1c71; //-0.11111111111111108
Diletant 177:672ef279c8e0 33 device.isacs.regulator.settings.transfer.error[11] = 0xeeee; //0.9333333333333331V
Diletant 177:672ef279c8e0 34 device.isacs.regulator.settings.transfer.correction[11] = -0x3161; //-0.1928888888888888
Diletant 177:672ef279c8e0 35 device.isacs.regulator.settings.transfer.error[12] = 0x13333; //1.2000000000000002V
Diletant 177:672ef279c8e0 36 device.isacs.regulator.settings.transfer.correction[12] = -0x4fdf; //-0.31200000000000006
Diletant 177:672ef279c8e0 37 device.isacs.regulator.settings.transfer.error[13] = 0x17777; //1.4666666666666668V
Diletant 177:672ef279c8e0 38 device.isacs.regulator.settings.transfer.correction[13] = -0x7aa7; //-0.47911111111111115
Diletant 177:672ef279c8e0 39 device.isacs.regulator.settings.transfer.error[14] = 0x1bbbb; //1.7333333333333334V
Diletant 177:672ef279c8e0 40 device.isacs.regulator.settings.transfer.correction[14] = -0xb473; //-0.7048888888888889
Diletant 177:672ef279c8e0 41 device.isacs.regulator.settings.transfer.error[15] = 0x20000; //2.0V
Diletant 177:672ef279c8e0 42 device.isacs.regulator.settings.transfer.correction[15] = -0x10000; //-1.0
Diletant 177:672ef279c8e0 43
Diletant 167:bedc0a9d559a 44 device.isacs.output.settings.transfer.points = 2;
Diletant 166:c3c0b8a90d81 45 //Control point 1.5 volt - low output limit
Diletant 167:bedc0a9d559a 46 device.isacs.output.settings.transfer.voltage[0] = 0x00017fff;
Diletant 167:bedc0a9d559a 47 device.isacs.output.settings.transfer.code[0] = 800;
Diletant 166:c3c0b8a90d81 48 //Control point 12.5 volt - high output limit
Diletant 167:bedc0a9d559a 49 device.isacs.output.settings.transfer.voltage[1] = 0x000c7fff;
Diletant 167:bedc0a9d559a 50 device.isacs.output.settings.transfer.code[1] = 2048;
Diletant 167:bedc0a9d559a 51 device.isacs.output.settings.start.voltage = 0x000c7fff; //+12.5V start
Diletant 167:bedc0a9d559a 52 device.isacs.output.settings.reset.voltage = 0x00077fff; //+7.5V if regulator disabled at reset time
Diletant 183:c7a9c309086c 53 device.isacs.output.state.min = 0x00077fff; //+7.5V
Diletant 183:c7a9c309086c 54 device.isacs.output.state.max = 0x000c7fff; //+12.5V
Diletant 161:efd949e8d536 55 }
Diletant 161:efd949e8d536 56
Diletant 167:bedc0a9d559a 57 void InitISACSOutputState(void){
Diletant 161:efd949e8d536 58 }
Diletant 161:efd949e8d536 59
Diletant 167:bedc0a9d559a 60 void DeviceStartISACSOutput(void){
Diletant 167:bedc0a9d559a 61 }
Diletant 167:bedc0a9d559a 62
Diletant 167:bedc0a9d559a 63 void InitISACSRegulatorDefaultSettings(void){
Diletant 161:efd949e8d536 64 //Startup settings
Diletant 166:c3c0b8a90d81 65 device.isacs.regulator.settings.start.enabled = 1;
Diletant 161:efd949e8d536 66 device.isacs.regulator.settings.start.reference = 0x00020000; //Reference voltage 2V in 16.16 signed fixed point format
Diletant 161:efd949e8d536 67 device.isacs.regulator.settings.start.scale = 1; //Scale factor
Diletant 161:efd949e8d536 68 //Regular operation settings
Diletant 166:c3c0b8a90d81 69 device.isacs.regulator.settings.regular.enabled = 1;
Diletant 161:efd949e8d536 70 device.isacs.regulator.settings.regular.reference = 0x00020000; //Reference voltage 2V in 16.16 signed fixed point format
Diletant 161:efd949e8d536 71 device.isacs.regulator.settings.regular.scale = 1; //Scale factor
Diletant 161:efd949e8d536 72 //Reset operation settings
Diletant 166:c3c0b8a90d81 73 device.isacs.regulator.settings.reset.enabled = 1;
Diletant 161:efd949e8d536 74 device.isacs.regulator.settings.reset.reference = 0x00020000; //Reference voltage 2V in 16.16 signed fixed point format
Diletant 161:efd949e8d536 75 device.isacs.regulator.settings.reset.scale = 1; //Scale factor
Diletant 161:efd949e8d536 76 }
Diletant 161:efd949e8d536 77
Diletant 167:bedc0a9d559a 78 void InitISACSRegulatorState(void){
Diletant 166:c3c0b8a90d81 79 device.isacs.regulator.state.enabled = device.isacs.regulator.settings.start.enabled;
Diletant 161:efd949e8d536 80 device.isacs.regulator.state.reference = device.isacs.regulator.settings.start.reference;
Diletant 161:efd949e8d536 81 device.isacs.regulator.state.scale = device.isacs.regulator.settings.start.scale;
Diletant 177:672ef279c8e0 82 device.isacs.regulator.state.error = 0;
Diletant 177:672ef279c8e0 83 device.isacs.regulator.state.correction = 0;
Diletant 161:efd949e8d536 84 }
Diletant 161:efd949e8d536 85
Diletant 167:bedc0a9d559a 86 void DeviceStartISACSRegulator(void){
Diletant 167:bedc0a9d559a 87 }
Diletant 167:bedc0a9d559a 88
Diletant 167:bedc0a9d559a 89 void InitISACSDefaultSettings(void){
Diletant 167:bedc0a9d559a 90 InitISACSPotentiometersDefaultSettings();
Diletant 167:bedc0a9d559a 91 InitISACSRegulatorDefaultSettings();
Diletant 167:bedc0a9d559a 92 InitISACSOutputDefaultSettings();
Diletant 161:efd949e8d536 93 }
Diletant 161:efd949e8d536 94
Diletant 167:bedc0a9d559a 95 void InitISACSState(void){
Diletant 167:bedc0a9d559a 96 InitISACSPotentiometersState();
Diletant 167:bedc0a9d559a 97 InitISACSRegulatorState();
Diletant 167:bedc0a9d559a 98 InitISACSOutputState();
Diletant 161:efd949e8d536 99 }
Diletant 161:efd949e8d536 100
Diletant 167:bedc0a9d559a 101 void DeviceStartISACS(void){
Diletant 167:bedc0a9d559a 102 DeviceStartISACSPotentiometers();
Diletant 167:bedc0a9d559a 103 DeviceStartISACSRegulator();
Diletant 167:bedc0a9d559a 104 DeviceStartISACSOutput();
Diletant 161:efd949e8d536 105 }
Diletant 161:efd949e8d536 106
Diletant 166:c3c0b8a90d81 107 /*
Diletant 166:c3c0b8a90d81 108 //Count leading zeroes
Diletant 166:c3c0b8a90d81 109 static uint8_t clz(uint32_t x) {
Diletant 166:c3c0b8a90d81 110 uint8_t result = 0;
Diletant 166:c3c0b8a90d81 111 if (x == 0) return 32;
Diletant 166:c3c0b8a90d81 112 while (!(x & 0xF0000000)) { result += 4; x <<= 4; }
Diletant 166:c3c0b8a90d81 113 while (!(x & 0x80000000)) { result += 1; x <<= 1; }
Diletant 166:c3c0b8a90d81 114 return result;
Diletant 166:c3c0b8a90d81 115 }
Diletant 166:c3c0b8a90d81 116 //Count trailing zeroes
Diletant 166:c3c0b8a90d81 117 static uint8_t ctz(uint32_t x) {
Diletant 166:c3c0b8a90d81 118 uint8_t result = 0;
Diletant 166:c3c0b8a90d81 119 if (x == 0) return 32;
Diletant 166:c3c0b8a90d81 120 while (!(x & 0xF0000000)) { result += 4; x <<= 4; }
Diletant 166:c3c0b8a90d81 121 while (!(x & 0x80000000)) { result += 1; x <<= 1; }
Diletant 166:c3c0b8a90d81 122 return result;
Diletant 166:c3c0b8a90d81 123 }
Diletant 166:c3c0b8a90d81 124 */
Diletant 166:c3c0b8a90d81 125
Diletant 166:c3c0b8a90d81 126 int32_t isacsInterpolate(int32_t a,int32_t a1,int32_t a2,int32_t b1,int32_t b2) {
Diletant 166:c3c0b8a90d81 127 int32_t ma, mb;
Diletant 166:c3c0b8a90d81 128 while (1) {
Diletant 166:c3c0b8a90d81 129 if (a1 == a) return b1;
Diletant 166:c3c0b8a90d81 130 if (a2 == a) return b2;
Diletant 166:c3c0b8a90d81 131
Diletant 166:c3c0b8a90d81 132 ma = (a1 + a2) >> 1;
Diletant 166:c3c0b8a90d81 133 mb = (b1 + b2) >> 1;
Diletant 166:c3c0b8a90d81 134
Diletant 166:c3c0b8a90d81 135 if (a < ma) {
Diletant 166:c3c0b8a90d81 136 if (a2 == ma) return mb;
Diletant 166:c3c0b8a90d81 137 if (b1 == mb) return mb;
Diletant 166:c3c0b8a90d81 138 a2 = ma; b2 = mb;
Diletant 166:c3c0b8a90d81 139 } else if (a > ma) {
Diletant 166:c3c0b8a90d81 140 if (a1 == ma) return mb;
Diletant 166:c3c0b8a90d81 141 if (b2 == mb) return mb;
Diletant 166:c3c0b8a90d81 142 a1 = ma; b1 = mb;
Diletant 166:c3c0b8a90d81 143 } else return mb;
Diletant 166:c3c0b8a90d81 144 }
Diletant 166:c3c0b8a90d81 145 }
Diletant 166:c3c0b8a90d81 146
Diletant 177:672ef279c8e0 147 int32_t isacsInput(uint32_t raw) {
Diletant 177:672ef279c8e0 148 int32_t r1, r2;
Diletant 167:bedc0a9d559a 149 for (uint8_t i = 1; i < device.isacs.input.settings.transfer.points; i++) {
Diletant 177:672ef279c8e0 150 r1 = device.isacs.input.settings.transfer.raw[i - 1];
Diletant 177:672ef279c8e0 151 if (raw < r1) {
Diletant 177:672ef279c8e0 152 return device.isacs.input.settings.transfer.V[i - 1];
Diletant 166:c3c0b8a90d81 153 }
Diletant 166:c3c0b8a90d81 154
Diletant 177:672ef279c8e0 155 r2 = device.isacs.input.settings.transfer.raw[i];
Diletant 177:672ef279c8e0 156 if (raw < r2) {
Diletant 177:672ef279c8e0 157 int32_t v1 = device.isacs.input.settings.transfer.V[i - 1];
Diletant 177:672ef279c8e0 158 int32_t v2 = device.isacs.input.settings.transfer.V[i];
Diletant 177:672ef279c8e0 159 return isacsInterpolate(raw, r1, r2, v1, v2);
Diletant 166:c3c0b8a90d81 160 }
Diletant 166:c3c0b8a90d81 161 }
Diletant 177:672ef279c8e0 162 return device.isacs.input.settings.transfer.V[device.isacs.input.settings.transfer.points - 1];
Diletant 177:672ef279c8e0 163 }
Diletant 177:672ef279c8e0 164
Diletant 183:c7a9c309086c 165 int32_t isacsCorrection(int32_t error) {
Diletant 177:672ef279c8e0 166 int32_t e1, e2;
Diletant 177:672ef279c8e0 167 for (uint8_t i = 1; i < device.isacs.regulator.settings.transfer.points; i++) {
Diletant 177:672ef279c8e0 168 e1 = device.isacs.regulator.settings.transfer.error[i - 1];
Diletant 177:672ef279c8e0 169 if (error < e1) {
Diletant 177:672ef279c8e0 170 return device.isacs.regulator.settings.transfer.correction[i - 1];
Diletant 177:672ef279c8e0 171 }
Diletant 177:672ef279c8e0 172
Diletant 177:672ef279c8e0 173 e2 = device.isacs.regulator.settings.transfer.error[i];
Diletant 177:672ef279c8e0 174 if (error < e2) {
Diletant 177:672ef279c8e0 175 int32_t c1 = device.isacs.regulator.settings.transfer.correction[i - 1];
Diletant 177:672ef279c8e0 176 int32_t c2 = device.isacs.regulator.settings.transfer.correction[i];
Diletant 177:672ef279c8e0 177 return isacsInterpolate(error, e1, e2, c1, c2);
Diletant 177:672ef279c8e0 178 }
Diletant 177:672ef279c8e0 179 }
Diletant 177:672ef279c8e0 180 return device.isacs.regulator.settings.transfer.correction[device.isacs.regulator.settings.transfer.points - 1];
Diletant 166:c3c0b8a90d81 181 }
Diletant 166:c3c0b8a90d81 182
Diletant 183:c7a9c309086c 183 uint32_t isacsOutput(int32_t voltage) {
Diletant 166:c3c0b8a90d81 184 int32_t v1, v2;
Diletant 167:bedc0a9d559a 185 for (uint8_t i = 1; i < device.isacs.output.settings.transfer.points; i++) {
Diletant 167:bedc0a9d559a 186 v1 = device.isacs.output.settings.transfer.voltage[i - 1];
Diletant 166:c3c0b8a90d81 187 if (voltage < v1) {
Diletant 167:bedc0a9d559a 188 return device.isacs.output.settings.transfer.code[i - 1];
Diletant 166:c3c0b8a90d81 189 }
Diletant 166:c3c0b8a90d81 190
Diletant 167:bedc0a9d559a 191 v2 = device.isacs.output.settings.transfer.voltage[i];
Diletant 166:c3c0b8a90d81 192 if (voltage < v2) {
Diletant 167:bedc0a9d559a 193 int32_t c1 = device.isacs.output.settings.transfer.code[i - 1];
Diletant 167:bedc0a9d559a 194 int32_t c2 = device.isacs.output.settings.transfer.code[i];
Diletant 166:c3c0b8a90d81 195 return isacsInterpolate(voltage, v1, v2, c1, c2);
Diletant 166:c3c0b8a90d81 196 }
Diletant 166:c3c0b8a90d81 197 }
Diletant 167:bedc0a9d559a 198 return device.isacs.output.settings.transfer.code[device.isacs.output.settings.transfer.points - 1];
Diletant 166:c3c0b8a90d81 199 }
Diletant 166:c3c0b8a90d81 200
Diletant 166:c3c0b8a90d81 201 void isacsProcess(void) {
Diletant 177:672ef279c8e0 202 device.isacs.input.state.sum += device.controller.SSP.in[4];
Diletant 166:c3c0b8a90d81 203 if (device.measurement.counter == 31) {
Diletant 177:672ef279c8e0 204 device.isacs.input.state.raw = device.isacs.input.state.sum >> 5;
Diletant 167:bedc0a9d559a 205 device.isacs.input.state.sum = 0;
Diletant 177:672ef279c8e0 206 device.isacs.input.state.V = isacsInput(device.isacs.input.state.raw);
Diletant 166:c3c0b8a90d81 207
Diletant 166:c3c0b8a90d81 208 if (device.isacs.regulator.state.enabled) {
Diletant 177:672ef279c8e0 209 device.isacs.regulator.state.error = device.isacs.regulator.state.reference - device.isacs.input.state.V;
Diletant 177:672ef279c8e0 210 device.isacs.regulator.state.correction = (device.isacs.regulator.state.scale * isacsCorrection(device.isacs.regulator.state.error)) >> 16;
Diletant 177:672ef279c8e0 211 device.isacs.output.state.voltage += device.isacs.regulator.state.correction;
Diletant 173:7f938afb0447 212 device.controller.SSP.out[0] = isacsOutput(device.isacs.output.state.voltage);
Diletant 166:c3c0b8a90d81 213 }
Diletant 166:c3c0b8a90d81 214 }
Diletant 183:c7a9c309086c 215 }
Diletant 183:c7a9c309086c 216
Diletant 183:c7a9c309086c 217 int16_t var_HF_reg(void) {
Diletant 183:c7a9c309086c 218 //Value: HFO voltage - V - -13.2V...10.7V
Diletant 183:c7a9c309086c 219 //Internal format: device.isacs.output.state.voltage - device.isacs.output.state.min...device.isacs.output.state.max [V] in 16.16 format
Diletant 183:c7a9c309086c 220 //Output format: -8192 * (V + 1.3) / 3 - dimensionless units in 16.0 format
Diletant 183:c7a9c309086c 221
Diletant 183:c7a9c309086c 222 //Voltage: V + 1.3 = (device.isacs.output.state.voltage + 0x00014ccd) / 65536
Diletant 183:c7a9c309086c 223 //Output: -8192 * (V + 1.3) / 3 = -(device.isacs.output.state.voltage + 0x00014ccd) / 24
Diletant 183:c7a9c309086c 224
Diletant 183:c7a9c309086c 225 int32_t V = -(device.isacs.output.state.voltage + 0x00014ccd) / 24;
Diletant 183:c7a9c309086c 226 if (V > 32767) V = 32767;
Diletant 183:c7a9c309086c 227 if (V < -32768) V = -32768;
Diletant 183:c7a9c309086c 228
Diletant 183:c7a9c309086c 229 return (int16_t)V;
Diletant 183:c7a9c309086c 230 }
Diletant 183:c7a9c309086c 231
Diletant 183:c7a9c309086c 232 int16_t var_HF_dif(void) {
Diletant 183:c7a9c309086c 233 //Value: HFO regulator input signal error - [V]
Diletant 183:c7a9c309086c 234 //Internal format: device.isacs.regulator.state.error - [V] in 16.16 format
Diletant 183:c7a9c309086c 235 //Output format: (V / 2.0) * 15000 - dimensionless units in 16.0 format
Diletant 183:c7a9c309086c 236
Diletant 183:c7a9c309086c 237 //Voltage: V = device.isacs.regulator.state.error / 65536
Diletant 183:c7a9c309086c 238 //Output: (V / 2.0) * 15000 = device.isacs.regulator.state.error * 1875 / 16384
Diletant 183:c7a9c309086c 239
Diletant 183:c7a9c309086c 240 int32_t V = device.isacs.regulator.state.error * 1875 / 16384;
Diletant 183:c7a9c309086c 241 if (V > 32767) V = 32767;
Diletant 183:c7a9c309086c 242 if (V < 0) V = 0;
Diletant 183:c7a9c309086c 243
Diletant 183:c7a9c309086c 244 return (int16_t)V;
Diletant 183:c7a9c309086c 245 }
Diletant 183:c7a9c309086c 246
Diletant 183:c7a9c309086c 247 uint16_t param_HF_ref(void) {
Diletant 183:c7a9c309086c 248 //Value: HFO regulator input signal reference voltage - V - 2V
Diletant 183:c7a9c309086c 249 //Internal format: device.isacs.regulator.state.reference - [V] in 16.16 format
Diletant 183:c7a9c309086c 250 //Output format: (V / 2.0) * 15000 - dimensionless units in 16.0 format
Diletant 183:c7a9c309086c 251
Diletant 183:c7a9c309086c 252 //Voltage: V = device.isacs.regulator.state.reference / 65536
Diletant 183:c7a9c309086c 253 //Output: V = device.isacs.regulator.state.reference * 1875 / 16384
Diletant 183:c7a9c309086c 254
Diletant 183:c7a9c309086c 255 //TODO: state/settings
Diletant 183:c7a9c309086c 256
Diletant 183:c7a9c309086c 257 int32_t V = device.isacs.regulator.state.reference * 1875 / 16384;
Diletant 183:c7a9c309086c 258 if (V > 32767) V = 32767;
Diletant 183:c7a9c309086c 259 if (V < 0) V = 0;
Diletant 183:c7a9c309086c 260
Diletant 183:c7a9c309086c 261 return (uint16_t)V;
Diletant 183:c7a9c309086c 262 }
Diletant 183:c7a9c309086c 263
Diletant 183:c7a9c309086c 264 //HF_scl s16 HFO gain factor
Diletant 183:c7a9c309086c 265 uint16_t param_HF_scl(void) {
Diletant 183:c7a9c309086c 266 //Value: ISACS output regulator scale - S - -13.2V...10.7V
Diletant 183:c7a9c309086c 267 //Internal format: device.isacs.regulator.state.scale - dimensionless units in 16.16 format
Diletant 183:c7a9c309086c 268 //Output format: S / 65536 - dimensionless units in 16.0 format
Diletant 183:c7a9c309086c 269
Diletant 183:c7a9c309086c 270 int32_t scl = device.isacs.regulator.state.scale / 65536;
Diletant 183:c7a9c309086c 271 if (scl > 32767) scl = 32767;
Diletant 183:c7a9c309086c 272 if (scl < 0) scl = 0;
Diletant 183:c7a9c309086c 273
Diletant 183:c7a9c309086c 274 return (uint16_t)scl;
Diletant 183:c7a9c309086c 275 }
Diletant 183:c7a9c309086c 276
Diletant 183:c7a9c309086c 277 uint16_t param_HF_min(void) {
Diletant 183:c7a9c309086c 278 //Value: HFO maximum voltage - V - -13.2V...10.7V
Diletant 183:c7a9c309086c 279 //Internal format: device.isacs.output.state.max - [V] in 16.16 format
Diletant 183:c7a9c309086c 280 //Output format: -8192 * (V + 1.3) / 3 - dimensionless units in 16.0 format
Diletant 183:c7a9c309086c 281
Diletant 183:c7a9c309086c 282 //Voltage: V + 1.3 = (device.isacs.output.state.max + 0x00014ccd) / 65536
Diletant 183:c7a9c309086c 283 //Output: -8192 * (V + 1.3) / 3 = -(device.isacs.output.state.max + 0x00014ccd) / 24
Diletant 183:c7a9c309086c 284
Diletant 183:c7a9c309086c 285 //TODO: state/settings
Diletant 183:c7a9c309086c 286
Diletant 183:c7a9c309086c 287 int32_t V = -(device.isacs.output.state.max + 0x00014ccd) / 24;
Diletant 183:c7a9c309086c 288 if (V > 32767) V = 32767;
Diletant 183:c7a9c309086c 289 if (V < -32768) V = -32768;
Diletant 183:c7a9c309086c 290
Diletant 183:c7a9c309086c 291 return (uint16_t)V;
Diletant 183:c7a9c309086c 292 }
Diletant 183:c7a9c309086c 293
Diletant 183:c7a9c309086c 294 uint16_t param_HF_max(void) {
Diletant 183:c7a9c309086c 295 //Value: HFO minimum voltage - V - -13.2V...10.7V
Diletant 183:c7a9c309086c 296 //Internal format: device.isacs.output.state.min - [V] in 16.16 format
Diletant 183:c7a9c309086c 297 //Output format: -8192 * (V + 1.3) / 3 - dimensionless units in 16.0 format
Diletant 183:c7a9c309086c 298
Diletant 183:c7a9c309086c 299 //Voltage: V + 1.3 = (device.isacs.output.state.min + 0x00014ccd) / 65536
Diletant 183:c7a9c309086c 300 //Output: -8192 * (V + 1.3) / 3 = -(device.isacs.output.state.min + 0x00014ccd) / 24
Diletant 183:c7a9c309086c 301
Diletant 183:c7a9c309086c 302 //TODO: state/settings
Diletant 183:c7a9c309086c 303
Diletant 183:c7a9c309086c 304 int32_t V = -(device.isacs.output.state.min + 0x00014ccd) / 24;
Diletant 183:c7a9c309086c 305 if (V > 32767) V = 32767;
Diletant 183:c7a9c309086c 306 if (V < -32768) V = -32768;
Diletant 183:c7a9c309086c 307
Diletant 183:c7a9c309086c 308 return (uint16_t)V;
Diletant 161:efd949e8d536 309 }