123

Dependencies:   mbed

Fork of LG by igor Apu

Revision:
173:7f938afb0447
Parent:
167:bedc0a9d559a
Child:
177:672ef279c8e0
--- a/DeviceDither.h	Fri Jun 17 13:54:50 2016 +0000
+++ b/DeviceDither.h	Sun Jun 19 03:54:35 2016 +0000
@@ -3,13 +3,17 @@
 
 //Dither drive pulse typedefs
 typedef struct _DeviceDitherPulseSettings {
-  uint32_t rise;    //rising edge position in 10 mks resolution ticks
-  uint32_t fall;    //falling edge position in 10 mks resolution ticks
+  int32_t width;    //start pulse width - 0...1 in 16.16 format
+  int32_t min;      //min pulse width - 0...1 in 16.16 format
+  int32_t max;      //max pulse width - 0...1 in 16.16 format
 } DeviceDitherPulseSettings;
 
 typedef struct _DeviceDitherPulseState {
-  uint32_t rise;    //rising edge position in 10 mks resolution ticks
-  uint32_t fall;    //falling edge position in 10 mks resolution ticks
+  int32_t width;    //pulse width - 0...1 in 16.16 format
+  int32_t min;      //min pulse width - 0...1 in 16.16 format
+  int32_t max;      //max pulse width - 0...1 in 16.16 format
+  int32_t rise;     //rising edge position in 10 mks resolution ticks
+  int32_t fall;     //falling edge position in 10 mks resolution ticks
   uint32_t counter; //10 mks resolution counter, zeroed at each dither half period
 } DeviceDitherPulseState;
 
@@ -20,14 +24,20 @@
 
 //Dither noise typedefs
 typedef struct _DeviceDitherNoiseSettings {
-  uint8_t enabled;
-  uint32_t period;  //noise period in mks
-  uint32_t range;   //noise range (format?)
-  uint32_t phase;   //adjusted noise constant (format?)
+  int8_t enabled;
+  int32_t period;      //base (constant) part of noise period - 0...100 measurement cycles
+  int32_t range;       //variable (random) part of noise period - 0...50 measurement cycles
+  int32_t amplitude;   //pulse width variation amplitude
 } DeviceDitherNoiseSettings;
 
 typedef struct _DeviceDitherNoiseState {
-  uint8_t enabled;
+  int8_t enabled;
+  int32_t period;      //base (constant) part of noise state update period - 0...100 measurement cycles
+  int32_t range;       //variable (random) part of noise state update period - 0...50 measurement cycles
+  int32_t amplitude;   //pulse width variation amplitude
+  int32_t counter;     //noise state update counter - 0 ... (period + range - 1) in measurement cycles
+  int32_t trigger;     //noise state update trigger - 0 ... (period + range - 1) in measurement cycles
+  int32_t disturbance; //pulse width disturbance - -1...1 (-100...100% of maximum pulse width) in 16.16 format
 } DeviceDitherNoiseState;
 
 typedef struct _DeviceDitherNoise {
@@ -35,53 +45,15 @@
   DeviceDitherNoiseState state;
 } DeviceDitherNoise;
 
-//Dither oscillation frequency regulator typedefs
-typedef struct _DeviceDitherOscillationFrequencyRegulatorSettings {
-  uint8_t enabled;
-  uint32_t reference; //signed 16.16 format reference oscillation frequency
-  uint32_t scale;     //signed 16.16 format regulator scale factor
-} DeviceDitherOscillationFrequencyRegulatorSettings;
-
-typedef struct _DeviceDitherOscillationFrequencyRegulatorState {
-  uint8_t enabled;
-  uint32_t reference; //signed 16.16 format reference oscillation frequency
-  uint32_t scale;     //signed 16.16 format regulator scale factor
-  uint32_t error;     //signed 16.16 format regulator error
-} DeviceDitherOscillationFrequencyRegulatorState;
-
-typedef struct _DeviceDitherOscillationFrequencyRegulator {
-  DeviceDitherOscillationFrequencyRegulatorSettings settings;
-  DeviceDitherOscillationFrequencyRegulatorState state;
-} DeviceDitherOscillationFrequencyRegulator;
-
-//Dither information signal carrier frequency regulator typedefs
-typedef struct _DeviceDitherCarrierFrequencyRegulatorSettings {
-  uint8_t enabled;
-  uint32_t reference; //signed 16.16 format reference information signal carrier frequency
-  uint32_t scale;     //signed 16.16 format regulator scale factor
-} DeviceDitherCarrierFrequencyRegulatorSettings;
-
-typedef struct _DeviceDitherCarrierFrequencyRegulatorState {
-  uint8_t enabled;
-  uint32_t reference; //signed 16.16 format reference information signal carrier frequency
-  uint32_t scale;     //signed 16.16 format regulator scale factor
-  uint32_t error;     //signed 16.16 format regulator error
-} DeviceDitherCarrierFrequencyRegulatorState;
-
-typedef struct _DeviceDitherCarrierFrequencyRegulator {
-  DeviceDitherOscillationFrequencyRegulatorSettings settings;
-  DeviceDitherOscillationFrequencyRegulatorState state;
-} DeviceDitherCarrierFrequencyRegulator;
-
 //Dither cycle typedefs
 typedef struct _DeviceDitherCycleSettings {
-  uint8_t enabled;
+  int8_t enabled;
 } DeviceDitherCycleSettings;
 
 typedef struct _DeviceDitherCycleState {
-  uint8_t enabled;  //dither on/off
-  uint8_t pin1;     //pin 1 state
-  uint8_t pin2;     //pin 2 state
+  int8_t enabled;  //dither on/off
+  int8_t pin1;     //pin 1 state
+  int8_t pin2;     //pin 2 state
 } DeviceDitherCycleState;
 
 typedef struct _DeviceDitherCycle {
@@ -90,14 +62,27 @@
 } DeviceDitherCycle;
 
 //Dither phase detector typedefs
+typedef struct _DeviceDitherPhaseDetectorFilterFunction {
+  int32_t factor[32]; //-1...+1 weight factors in 16.16 format
+} DeviceDitherPhaseDetectorFilterFunction;
+
+typedef struct _DeviceDitherPhaseTransferFunction {
+  uint32_t points;   //Number of actual control points (up to 16)
+  int32_t raw[16]; //Raw phase (distorted) - -1...+1 in signed 16.16 fixed point format
+  int32_t restored[16];  //Restored phase - -1...+1 in 16.16 fixed point format
+} DeviceDitherPhaseTransferFunction;
+
 //error = sum(weight[i + offset] * device.counters.state.delta[i])
 typedef struct _DeviceDitherPhaseDetectorSettings {
-  int16_t weight[32]; //0...255 weight factors
-  uint8_t offset;     //0...31 start position
+  //int32_t factor[32]; //-1...+1 weight factors in 16.16 format
+  DeviceDitherPhaseDetectorFilterFunction filter;
+  DeviceDitherPhaseTransferFunction transfer;
 } DeviceDitherPhaseDetectorSettings;
 
 typedef struct _DeviceDitherPhaseDetectorState {
-  int32_t error;
+  int32_t sum;   //Raw phase accumulator
+  int32_t raw;   //Raw (distorted) phase
+  int32_t phase; //Restored phase
 } DeviceDitherPhaseDetectorState;
 
 typedef struct _DeviceDitherPhaseDetector {
@@ -105,23 +90,79 @@
   DeviceDitherPhaseDetectorState state;
 } DeviceDitherPhaseDetector;
 
+//Dither oscillation frequency regulator typedefs
+typedef struct _DeviceDitherFrequencyRegulatorTransferSettings {
+  int32_t points;         //actual control points 1...16 set
+  int32_t error[16];      //regulator error - 0..150 Hz, signed 16.16 format
+  int32_t correction[16]; //regulator oscillation frequency correction - -1...1 (-100%...100%), 16.16 format
+} DeviceDitherFrequencyRegulatorTransferSettings;
+
+typedef struct _DeviceDitherFrequencyRegulatorSettings {
+  int8_t enabled;
+  int32_t max;     //signed 16.16 format maximum oscillation frequency. TODO: max(temperature)
+  int32_t min;     //signed 16.16 format minimum oscillation frequency. TODO: min(temperature)
+  int32_t scale;   //signed 16.16 format regulator scale factor. TODO: correction(phase)
+  DeviceDitherFrequencyRegulatorTransferSettings transfer;
+} DeviceDitherFrequencyRegulatorSettings;
+
+typedef struct _DeviceDitherFrequencyRegulatorState {
+  int8_t enabled;
+  int32_t max;        //maximum oscillation frequency - Hz in signed 16.16 format
+  int32_t min;        //minimum oscillation frequency - Hz in signed 16.16 format
+  int32_t frequency;  //oscillation frequency - Hz in signed 16.16 format
+  int32_t scale;      //regulator scale factor - Hz in signed 16.16 format
+  int32_t error;      //regulator error - Hz in signed 16.16 format
+  int32_t correction; //regulator correction - Hz in signed 16.16 format
+} DeviceDitherFrequencyRegulatorState;
+
+typedef struct _DeviceDitherFrequencyRegulator {
+  DeviceDitherFrequencyRegulatorSettings settings;
+  DeviceDitherFrequencyRegulatorState state;
+} DeviceDitherFrequencyRegulator;
+
+//Dither information signal carrier frequency regulator typedefs
+typedef struct _DeviceDitherAmplitudeRegulatorTransferSettings {
+  int32_t points;        //actual control points 1...16 set
+  int32_t error[16];      //regulator error - 0..200 kHz, signed 16.16 format
+  int32_t correction[16]; //regulator pulse width correction - -1...1 (-100%...100%), 16.16 format
+} DeviceDitherAmplitudeRegulatorTransferSettings;
+
+typedef struct _DeviceDitherAmplitudeRegulatorSettings {
+  int8_t enabled;
+  int32_t reference;     //signed 16.16 format reference information signal carrier frequency
+  int32_t scale;         //signed 16.16 format regulator scale factor
+  DeviceDitherAmplitudeRegulatorTransferSettings transfer;
+} DeviceDitherAmplitudeRegulatorSettings;
+
+typedef struct _DeviceDitherAmplitudeRegulatorState {
+  int8_t enabled;
+  int32_t reference;     //0...200 (kHz) signed 16.16 format reference information signal carrier frequency
+  int32_t scale;         //regulator scale factor in signed 16.16 format
+  int32_t frequency;     //carrier frequency in signed 16.16 format
+  int32_t error;         //signed 16.16 format regulator error
+  int32_t correction;    //regulator pulse width correction - -1...1 in signed 16.16 format
+} DeviceDitherAmplitudeRegulatorState;
+
+typedef struct _DeviceDitherAmplitudeRegulator {
+  DeviceDitherAmplitudeRegulatorSettings settings;
+  DeviceDitherAmplitudeRegulatorState state;
+} DeviceDitherAmplitudeRegulator;
+
 //Dither drive typedefs
 typedef struct _DeviceDither {
   DeviceDitherPulse pulse;
   DeviceDitherNoise noise;
   DeviceDitherCycle cycle;
   DeviceDitherPhaseDetector detector;
-  DeviceDitherOscillationFrequencyRegulator oscillation;
-  DeviceDitherCarrierFrequencyRegulator carrier;
+  DeviceDitherFrequencyRegulator frequency;
+  DeviceDitherAmplitudeRegulator amplitude;
 } DeviceDither;
 
 void InitDitherDefaultSettings(void);
 void InitDitherState(void);
 void DeviceStartDither(void);
 
-void DeviceStartDither(void);
-void DeviceDitherDoCycle(void);
-
-void DeviceDitherDetectPhase(void);
+void ditherCycle(void);
+void ditherProcess(void);
 
 #endif  /* __DEVICE_DITHER_H__ */
\ No newline at end of file