123
Fork of LG by
Diff: DeviceISACS.c
- Revision:
- 161:efd949e8d536
- Child:
- 166:c3c0b8a90d81
diff -r 6170df6f5a5c -r efd949e8d536 DeviceISACS.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DeviceISACS.c Sun May 15 19:12:12 2016 +0000 @@ -0,0 +1,92 @@ +#include "Device.h" + +extern Device device; + +void InitISACSOutputWithDefaults(void){ + device.isacs.output.settings.points = 2; + //Control point 1.5 volt + device.isacs.output.settings.voltage[0] = 0x00017fff; + device.isacs.output.settings.code[0] = 800; + //Control point 12.5 volt + device.isacs.output.settings.voltage[1] = 0x000c7fff; + device.isacs.output.settings.code[1] = 2048; +} + +void InitISACSOutput(void){ + device.isacs.output.state.voltage = 0x000c7fff; + isacsOutputCode(); +} + +void InitISACSRegulatorWithDefaults(void){ + device.isacs.regulator.settings.enabled = 1; + //Startup settings + device.isacs.regulator.settings.start.reference = 0x00020000; //Reference voltage 2V in 16.16 signed fixed point format + device.isacs.regulator.settings.start.scale = 1; //Scale factor + //Regular operation settings + device.isacs.regulator.settings.regular.reference = 0x00020000; //Reference voltage 2V in 16.16 signed fixed point format + device.isacs.regulator.settings.regular.scale = 1; //Scale factor + //Reset operation settings + device.isacs.regulator.settings.reset.reference = 0x00020000; //Reference voltage 2V in 16.16 signed fixed point format + device.isacs.regulator.settings.reset.scale = 1; //Scale factor + //Amplifier settings + //device.isacs.amplifier.settings.reference = 0x00040000; //Reference voltage 4V in 16.16 signed fixed point format + //device.isacs.amplifier.settings.gain = 1; //Scale factor +} + +void InitISACSRegulator(void){ + device.isacs.regulator.state.enabled = device.isacs.regulator.settings.enabled; + device.isacs.regulator.state.reference = device.isacs.regulator.settings.start.reference; + device.isacs.regulator.state.scale = device.isacs.regulator.settings.start.scale; +} + +void InitISACSWithDefaults(void){ + InitISACSOutputWithDefaults(); + InitISACSRegulatorWithDefaults(); + InitISACSPotentiometersWithDefaults(); +} + +void InitISACS(void){ + InitISACSOutput(); + InitISACSRegulator(); + InitISACSPotentiometers(); +} + +void StartISACS(void){ +} + +void isacsOutputCode(void) { + uint32_t v1, v2; + for (uint8_t i = 1; i < device.isacs.output.settings.points; i++) { + v1 = device.isacs.output.settings.voltage[i - 1]; + if (device.isacs.output.state.voltage < v1) { + device.isacs.output.state.code = device.isacs.output.settings.code[i - 1]; + device.isacs.output.state.voltage = v1; + return; + } + + v2 = device.isacs.output.settings.voltage[i]; + if (device.isacs.output.state.voltage < v2) { + //max(c2 - c1) = 4096 + //max(v - v1) = 25V = 0x00190000; + //max((c2 - c1) * (v - v1)) = 0x190000000 + //0x190000000 >> 2 = 0x64000000 < 0x80000000: ok + uint32_t dv = (device.isacs.output.state.voltage - v1); + uint32_t dvi = (v2 - v1); + uint32_t c1 = device.isacs.output.settings.code[i - 1]; + uint32_t c2 = device.isacs.output.settings.code[i]; + uint32_t dc = c2 - c1; + uint32_t m = 1; + if (device.dac.settings.resolution > 16) { + dv >>= 7; dc >>= 7; dvi >>= 7; m <<= 7;//For 24 bit: (21 - 7) + (24 - 7) - (21 - 7) + 7 = 24 + } else if (device.dac.settings.resolution > 12) { + dv >>= 3; dc >>= 3; dvi >>= 3; m <<= 3;//For 16 bit: (21 - 3) + (16 - 3) - (21 - 3) + 3 = 16 + } else { + dv >>= 1; dc >>= 1; dvi >>= 1; m <<= 1;//For 12 bit: (21 - 1) + (12 - 1) - (21 - 1) + 1 = 12 + } + device.isacs.output.state.code = c1 + dv * dc / dvi * m; + return; + } + } + device.isacs.output.state.code = device.isacs.output.settings.code[device.isacs.output.settings.points - 1]; + device.isacs.output.state.voltage = device.isacs.output.settings.voltage[device.isacs.output.settings.points - 1]; +} \ No newline at end of file