123

Dependencies:   mbed

Fork of LG by igor Apu

Revision:
161:efd949e8d536
Parent:
156:e68ee0bcdcda
Child:
167:bedc0a9d559a
diff -r 6170df6f5a5c -r efd949e8d536 DeviceDither.h
--- a/DeviceDither.h	Fri May 13 14:04:22 2016 +0000
+++ b/DeviceDither.h	Sun May 15 19:12:12 2016 +0000
@@ -1,29 +1,125 @@
 #ifndef __DEVICE_DITHER_H__
 #define __DEVICE_DITHER_H__
 
-typedef struct _DeviceDitherSettings {
-  uint32_t rise;
-  uint32_t fall;
-  uint8_t enabled;  //dither on/off
-} DeviceDitherSettings;
+//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
+} DeviceDitherPulseSettings;
 
-typedef struct _DeviceDitherState {
-  uint32_t counter; //10 mks resolution counter, zeroed at each dither half period
+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
+  uint32_t counter; //10 mks resolution counter, zeroed at each dither half period
+} DeviceDitherPulseState;
+
+typedef struct _DeviceDitherPulse {
+  DeviceDitherPulseSettings settings;
+  DeviceDitherPulseState state;
+} DeviceDitherPulse;
+
+//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?)
+} DeviceDitherNoiseSettings;
+
+typedef struct _DeviceDitherNoiseState {
+  uint8_t enabled;
+} DeviceDitherNoiseState;
+
+typedef struct _DeviceDitherNoise {
+  DeviceDitherNoiseSettings settings;
+  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;
+} DeviceDitherCycleSettings;
+
+typedef struct _DeviceDitherCycleState {
   uint8_t enabled;  //dither on/off
   uint8_t pin1;     //pin 1 state
   uint8_t pin2;     //pin 2 state
-} DeviceDitherState;
+} DeviceDitherCycleState;
+
+typedef struct _DeviceDitherCycle {
+  DeviceDitherCycleSettings settings;
+  DeviceDitherCycleState state;
+} DeviceDitherCycle;
 
+//Dither phase detector typedefs
+//error = sum(weight[i + offset] * device.counters.state.delta[i])
+typedef struct _DeviceDitherPhaseDetectorSettings {
+  uint8_t weight[32]; //0...255 weight factors
+  uint8_t offset;     //0...31 start position
+} DeviceDitherPhaseDetectorSettings;
+
+typedef struct _DeviceDitherPhaseDetectorState {
+  int32_t error;
+} DeviceDitherPhaseDetectorState;
+
+typedef struct _DeviceDitherPhaseDetector {
+  DeviceDitherPhaseDetectorSettings settings;
+  DeviceDitherPhaseDetectorState state;
+} DeviceDitherPhaseDetector;
+
+//Dither drive typedefs
 typedef struct _DeviceDither {
-  DeviceDitherSettings settings;
-  DeviceDitherState state;
+  DeviceDitherPulse pulse;
+  DeviceDitherNoise noise;
+  DeviceDitherCycle cycle;
+  DeviceDitherPhaseDetector detector;
+  DeviceDitherOscillationFrequencyRegulator oscillation;
+  DeviceDitherCarrierFrequencyRegulator carrier;
 } DeviceDither;
 
 void InitDitherWithDefaults(void);
 void InitDither(void);
 void DeviceStartDither(void);
-void DeviceDitherCycle(void);
+void DeviceDitherDoCycle(void);
+
+void DeviceDitherDetectPhase(void);
 
 #endif  /* __DEVICE_DITHER_H__ */
\ No newline at end of file