Dmitry Kovalev / Mbed 2 deprecated LGfiltr

Dependencies:   mbed

Fork of LGstaandart by Dmitry Kovalev

Revision:
167:bedc0a9d559a
Parent:
166:c3c0b8a90d81
Child:
173:7f938afb0447
--- a/DevicePLCS.h	Sun May 22 18:59:20 2016 +0000
+++ b/DevicePLCS.h	Sun Jun 05 11:03:33 2016 +0000
@@ -3,17 +3,23 @@
 
 //Path length control system sequencer typedefs
 typedef struct _DevicePLCSSequencerSettings {
-  uint8_t enabled;    //Enable sequence generation
-  uint8_t voltage;    //Modulate voltage output
-  uint8_t io;         //Modulate GPIO pin
-  uint32_t sequence[64]; //Generator sequence
+  uint8_t enabled;       //Enable sequence generation
+  uint8_t analog;        //Modulate analog (voltage) output
+  uint8_t logic;         //Modulate logic (GPIO pin) output
+  int32_t amplitude;    //Generator analog output amplitude - volts in 16.16 format
+  int32_t sequence[64]; //Generator sequence - dimensionless units -1...+1 in 16.16 format
+  uint8_t position[2];   //Sequence position
 } DevicePLCSSequencerSettings;
 
 typedef struct _DevicePLCSSequencerState {
-  uint8_t enabled;    //Enable sequence generation
-  uint8_t counter;    //Sequence counter: sequence position = device.measurement.counter + device.measurement.length * device.plcs.sequencer.counter
-  uint8_t voltage;    //Modulate voltage output
-  uint8_t io;         //Modulate GPIO pin
+  uint8_t enabled;       //Enable sequence generation
+  //uint8_t counter;       //Sequence counter: sequence position = device.measurement.counter + device.measurement.length * device.plcs.sequencer.counter
+  uint8_t analog;        //Modulate analog (voltage) output
+  uint8_t logic;         //Modulate logic (GPIO pin) output
+  uint32_t amplitude;    //Generator analog output amplitude - volts in 16.16 format
+  uint8_t position[2];   //Sequence position
+  uint32_t sample[2];    //Sequencer analog output = sequence[]: current/delayed - dimensionless units -1...+1 in 16.16 format
+  uint32_t voltage;      //Sequencer analog output = sequence[] * amplitude - volts in 16.16 format
 } DevicePLCSSequencerState;
 
 typedef struct _DevicePLCSSequencer {
@@ -21,152 +27,177 @@
   DevicePLCSSequencerState state;
 } DevicePLCSSequencer;
 
-//Path length control system input ( = ADC - low pass filter - code - voltage) typedefs
-typedef struct _DevicePLCSInput {
-  int32_t voltage;
-  int32_t sum;
-  int32_t counter;
-  int32_t average;
-} DevicePLCSInput;
+//Path length control system phase feedback typedefs
+typedef struct _DevicePLCSFeedbackTransferFunction {
+  uint32_t points;     //Number of actual control points (up to 16)
+  int32_t raw[16]; //Feedback raw value - volts in 16.16 format
+  int32_t normalized[16];//Feedback normalized value - -1...+1 in 16.16 format
+} DevicePLCSFeedbackTransferFunction;
 
-//Path length control system phase detector typedefs
-typedef struct _DevicePLCSPhaseDetectorSettings {
-  uint8_t enabled;    //Enable phase detector output
+typedef struct _DevicePLCSFeedbackSettings {
+  uint8_t input;      //Take ISACS input as feedback
+  uint8_t output;     //Take ISACS output as feedback
+  DevicePLCSFeedbackTransferFunction transfer;
+} DevicePLCSFeedbackSettings;
+
+typedef struct _DevicePLCSFeedbackState {
   uint8_t input;      //Take ISACS input as feedback
   uint8_t output;     //Take ISACS output as feedback
+  uint32_t voltage;   //Feedback - volts in 16.16 format
+} DevicePLCSFeedbackState;
+
+typedef struct _DevicePLCSFeedback {
+  DevicePLCSFeedbackSettings settings;
+  DevicePLCSFeedbackState state;
+} DevicePLCSFeedback;
+
+//Path length control system reference typedefs
+typedef struct _DevicePLCSReferenceSettings {
+  uint8_t sequencer;  //Take sequencer as reference (and ISACS amplitude/output as feedback)
+  uint8_t delta;      //Take delta as reference (and ISACS amplitude/output delta as feedback)
+} DevicePLCSReferenceSettings;
+
+typedef struct _DevicePLCSReferenceState {
   uint8_t sequencer;  //Take sequencer as reference (and ISACS amplitude/output as feedback)
   uint8_t delta;      //Take delta as reference (and ISACS amplitude/output delta as feedback)
-  uint8_t delay;      //Phase detector sequence delay
-} DevicePLCSPhaseDetectorSettings;
+} DevicePLCSReferenceState;
+
+typedef struct _DevicePLCSReference {
+  DevicePLCSReferenceSettings settings;
+  DevicePLCSReferenceState state;
+} DevicePLCSReference;
+
+//Path length control system detector typedefs
+typedef struct _DevicePLCSDetectorState {
+  int32_t in[2]; //Detector inputs: reference, feedback -1...+1 in 16.16 format
+  int32_t out;   //Detector output: -1...+1 in 16.16 format
+} DevicePLCSDetectorState;
+
+typedef struct _DevicePLCSDetector {
+  DevicePLCSDetectorState state;
+} DevicePLCSDetector;
+
+//Path length control system bias typedefs
+typedef struct _DevicePLCSBiasTransferFunction {
+  uint32_t points;    //Number of actual control points (up to 16)
+  int32_t raw[16];    //Raw bias value - dimensionless units
+  int32_t normalized[16]; //Normalized bias value - -0.5...+0.5 of lambda in 16.16 format
+} DevicePLCSBiasTransferFunction;
+
+typedef struct _DevicePLCSBiasSettings {
+  DevicePLCSBiasTransferFunction transfer;
+} DevicePLCSBiasSettings;
+
+typedef struct _DevicePLCSBiasState {
+  uint32_t raw;       //Raw bias value - -0.5...+0.5 in 16.16 format
+  int32_t sum;
+  int32_t counter;
+  int32_t average;    //Average bias value - -0.5...+0.5 in 16.16 format
+} DevicePLCSBiasState;
+
+typedef struct _DevicePLCSBias {
+  DevicePLCSBiasSettings settings;
+  DevicePLCSBiasState state;
+} DevicePLCSBias;
 
-typedef struct _DevicePLCSPhaseDetectorState {
-  uint8_t enabled;    //Enable phase detector output
-  uint8_t input;      //Take ISACS amplitude as feedback
-  uint8_t output;     //Take ISACS output as feedback
-  uint8_t sequencer;  //Take sequencer as reference (and ISACS amplitude as feedback)
-  uint8_t delta;      //Take PLCS output delta as reference (and ISACS amplitude/output delta as feedback)
-  uint8_t delay;      //Phase detector sequence delay
-  uint32_t phase;     //Phase detector output
-} DevicePLCSPhaseDetectorState;
+//Path length control system regulator typedefs
+typedef struct _DevicePLCSCorrectionTransferFunction {
+  uint32_t points;     //Number of actual control points (up to 16)
+  int32_t error[16];   //Regulator error value - degrees in 16.16 format
+  int32_t correction[16]; //Regulator correction value - volts in 16.16 format
+} DevicePLCSCorrectionTransferFunction;
+
+typedef struct _DevicePLCSRegulatorSettings {
+  uint8_t enabled;
+  uint32_t reference; //signed 16.16 format reference bias
+  //uint32_t scale;     //signed 16.16 format regulator scale factor
+  DevicePLCSCorrectionTransferFunction transfer;
+} DevicePLCSRegulatorSettings;
+
+typedef struct _DevicePLCSRegulatorState {
+  uint8_t enabled;
+  uint32_t reference; //signed 16.16 format reference bias
+  //uint32_t scale;     //signed 16.16 format regulator scale factor
+  uint32_t error;     //signed 16.16 format regulator error
+  uint32_t correction;//signed 16.16 format output correction
+} DevicePLCSRegulatorState;
 
-typedef struct _DevicePLCSPhaseDetector {
-  DevicePLCSPhaseDetectorSettings settings;
-  DevicePLCSPhaseDetectorState state;
-} DevicePLCSPhaseDetector;
+typedef struct _DevicePLCSRegulator {
+  DevicePLCSRegulatorSettings settings;
+  DevicePLCSRegulatorState state;
+} DevicePLCSRegulator;
+
+//Path length control reset typedefs
+typedef struct _DevicePLCSResetTemperatureFunction {
+  uint32_t points;         //Number of actual control points (up to 16)
+  int32_t temperature[16]; //Output reset temperature value - centigrade, 16.16 format
+  int32_t voltage[16];     //Output reset level value - volts, 16.16 format
+  uint32_t duration[16];   //Output reset duration value - seconds, 16.16 format
+} DevicePLCSResetTemperatureFunction;
+
+typedef struct _DevicePLCSResetLevels {
+  int32_t upper; //Upper reset level output voltage
+  int32_t lower; //Lower reset level output voltage
+} DevicePLCSResetLevels;
+
+typedef struct _DevicePLCSResetState {
+  int32_t countdown; //reset countdown - seconds, 16.16 format
+  int32_t voltage;
+} DevicePLCSResetState;
+
+typedef struct _DevicePLCSReset {
+  DevicePLCSResetLevels levels;
+  DevicePLCSResetTemperatureFunction up;
+  DevicePLCSResetTemperatureFunction down;
+  DevicePLCSResetState state;
+} DevicePLCSReset;
 
 //Path length control system output ( = DAC + amplifier + control unit + heater/piezo) typedefs
-typedef struct _DevicePLCSOutputInterpolatorSettings {
+typedef struct _DevicePLCSOutputStart {
+  int32_t voltage;     //Output voltage in signed 16.16 fixed point format
+} DevicePLCSOutputStart;
+
+typedef struct _DevicePLCSOutputTransferFunction {
   uint32_t points;     //Number of actual control points (up to 16)
   int32_t voltage[16]; //Output voltage control points in signed 16.16 fixed point format
   int32_t code[16];    //DAC code control points
-} DevicePLCSOutputInterpolatorSettings;
-
-typedef struct _DevicePLCSOutputInterpolator {
-  DevicePLCSOutputInterpolatorSettings settings;
-} DevicePLCSSOutputInterpolator;
-
-typedef struct _DevicePLCSOutputStartSettings {
-  int32_t voltage;     //Output voltage in signed 16.16 fixed point format
-} DevicePLCSOutputStartSettings;
-
-typedef struct _DevicePLCSOutputStart {
-  DevicePLCSOutputStartSettings settings;
-} DevicePLCSOutputStart;
-
-typedef struct _DevicePLCSOutputResetSettings {
-  int32_t voltage;     //Output voltage in signed 16.16 fixed point format
-} DevicePLCSOutputResetSettings;
-
-typedef struct _DevicePLCSOutputReset {
-  DevicePLCSOutputResetSettings settings;
-} DevicePLCSOutputReset;
+} DevicePLCSOutputTransferFunction;
 
 typedef struct _DevicePLCSOutputSettings {
   uint8_t enabled;     //Enable DAC output
-  //DevicePLCSOutputInterpolatorSettings interpolator;
-  //DevicePLCSOutputConditionSettings start;
-  //DevicePLCSOutputConditionSettings reset;
+  DevicePLCSOutputStart start;
+  DevicePLCSOutputTransferFunction transfer;
 } DevicePLCSOutputSettings;
 
 typedef struct _DevicePLCSOutputState {
   uint8_t enabled;     //Enable DAC output
   uint32_t voltage;    //Voltage output 
+  uint32_t code;       //Code output 
 } DevicePLCSOutputState;
 
 typedef struct _DevicePLCSOutput {
   DevicePLCSOutputSettings settings;
   DevicePLCSOutputState state;
-  DevicePLCSSOutputInterpolator interpolator;
-  DevicePLCSOutputStart start;
-  DevicePLCSOutputReset reset;
 } DevicePLCSOutput;
 
-//Path length control reset typedefs
-typedef struct _DevicePathLengthControlResetDelaySettings {
-  uint32_t center;   //reset delay in mks for normal conditions
-  uint32_t slope;   //signed 16.16 format output voltage reset level correction per correction interval
-} DevicePathLengthControlResetDelaySettings;
-
-typedef struct _DevicePathLengthControlResetLevelSettings {
-  uint32_t center;   //signed 16.16 format output voltage reset level
-  uint32_t slope;   //signed 16.16 format output voltage reset level correction per correction interval
-} DevicePathLengthControlResetLevelSettings;
-
-typedef struct _DevicePathLengthControlResetConditionSettings {
-  DevicePathLengthControlResetDelaySettings delay;
-  DevicePathLengthControlResetLevelSettings level;
-} DevicePathLengthControlResetConditionSettings;
-
-typedef struct _DevicePathLengthControlResetSettings {
-  DevicePathLengthControlResetConditionSettings cooling;
-  DevicePathLengthControlResetConditionSettings heating;
-} DevicePathLengthControlResetSettings;
-
-typedef struct _DevicePathLengthControlResetState {
-  uint32_t delay;   //reset delay in mks
-  uint32_t level;   //signed 16.16 format output voltage reset level
-} DevicePathLengthControlResetState;
-
-typedef struct _DevicePathLengthControlReset {
-  DevicePathLengthControlResetSettings settings;
-  DevicePathLengthControlResetState state;
-} DevicePathLengthControlReset;
-
-//Path length control system regulator typedefs
-typedef struct _DevicePathLengthControlRegulatorSettings {
-  uint8_t enabled;
-  uint32_t reference; //signed 16.16 format reference voltage
-  uint32_t scale;     //signed 16.16 format regulator scale factor
-} DevicePathLengthControlRegulatorSettings;
-
-typedef struct _DevicePathLengthControlRegulatorState {
-  uint8_t enabled;
-  uint32_t reference; //signed 16.16 format reference voltage
-  uint32_t scale;     //signed 16.16 format regulator scale factor
-  uint32_t error;     //signed 16.16 format regulator error
-} DevicePathLengthControlRegulatorState;
-
-typedef struct _DevicePathLengthControlRegulator {
-  DevicePathLengthControlRegulatorSettings settings;
-  DevicePathLengthControlRegulatorState state;
-} DevicePathLengthControlRegulator;
-
 //Path length control system typedefs
 //  Information signal amplitude ADC: device.controller.SSP.ADC[4]
 //  Path length control system DAC: device.controller.SSP.DAC[1]
 typedef struct _DevicePathLengthControlSystem {
   DevicePLCSSequencer sequencer;
-  DevicePLCSInput input;
-  DevicePLCSPhaseDetector detector;
-  DevicePathLengthControlRegulator regulator;
+  DevicePLCSFeedback feedback;
+  DevicePLCSReference reference;
+  DevicePLCSDetector detector;
+  DevicePLCSBias bias;
+  DevicePLCSRegulator regulator;
+  DevicePLCSReset reset;
   DevicePLCSOutput output;
-  DevicePathLengthControlReset reset;
 } DevicePathLengthControlSystem;
 
 //Path length control system functions
-void InitPathLengthControlSystemWithDefaults(void);
-void InitPathLengthControlSystem(void);
-void StartPathLengthControlSystem(void);
+void InitPathLengthControlSystemDefaultSettings(void);
+void InitPathLengthControlSystemState(void);
+void DeviceStartPLCS(void);
 
 void plcsProcess(void);