123
Fork of LG by
Diff: DeviceDither.h
- Revision:
- 198:78dd6d14d108
- Parent:
- 197:7a05523bf588
diff -r 7a05523bf588 -r 78dd6d14d108 DeviceDither.h --- a/DeviceDither.h Wed Oct 19 10:55:05 2016 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,224 +0,0 @@ -#ifndef __DEVICE_DITHER_H__ -#define __DEVICE_DITHER_H__ - -//Dither drive pulse typedefs -typedef struct _DeviceDitherPulseSettings { - 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 { - 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 - int32_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 { - int8_t enabled; - int32_t period; //base (fixed) 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 { - int8_t enabled; - int32_t period; //base (fixed) 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 { - DeviceDitherNoiseSettings settings; - DeviceDitherNoiseState state; -} DeviceDitherNoise; - -//Dither cycle typedefs -typedef struct _DeviceDitherCycleSettings { - int8_t enabled; -} DeviceDitherCycleSettings; - -typedef struct _DeviceDitherCycleState { - int8_t enabled; //dither on/off - int8_t pin1; //pin 1 state - int8_t pin2; //pin 2 state -} DeviceDitherCycleState; - -typedef struct _DeviceDitherCycle { - DeviceDitherCycleSettings settings; - DeviceDitherCycleState state; -} 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 { - //int32_t factor[32]; //-1...+1 weight factors in 16.16 format - DeviceDitherPhaseDetectorFilterFunction filter; - DeviceDitherPhaseTransferFunction transfer; -} DeviceDitherPhaseDetectorSettings; - -typedef struct _DeviceDitherPhaseDetectorState { - int32_t sum; //Raw phase accumulator - int32_t raw; //Raw (distorted) phase - int32_t phase; //Restored phase -} DeviceDitherPhaseDetectorState; - -typedef struct _DeviceDitherPhaseDetector { - DeviceDitherPhaseDetectorSettings settings; - 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 - 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; - DeviceDitherFrequencyRegulator frequency; - DeviceDitherAmplitudeRegulator amplitude; -} DeviceDither; - -void InitDitherDefaultSettings(void); -void InitDitherState(void); -void DeviceStartDither(void); - -void ditherCycle(void); -void ditherProcess(void); - -// -//Compatibility functions section -// - -//VB_Fdf s32 double output frequency (Hi) -uint32_t ditherGetRawAmplitudeSetting(void); //VB_Fdf s32 double output frequency (Hi) -#define param_VB_Fdf() ditherGetRawAmplitudeSetting() - -//F_ras int16 code: output frequency, divided by 16 (for transmission); value: output frequency -uint16_t ditherGetRawAmplitudeState(void); -#define var_F_ras() ditherGetRawAmplitudeState() - -//VB_N vbd ttf:dither drive oscillation central frequency divider 7680000/F; value:dither drive central oscillation frequency -uint16_t ditherGetRawDividerSetting(void); -#define param_VB_N() ditherGetRawDividerSetting() - -//VB_Nmax vbd ttf:maximum dither drive oscillation frequency divider 7680000/F; value:minimum dither drive oscillation frequency -uint16_t ditherGetRawDividerMaxSetting(void); -#define param_VB_Nmax() ditherGetRawDividerMaxSetting() - -//VB_Nmin vbd ttf:minimum dither drive oscillation frequency divider 7680000/F; value:maximum dither drive oscillation frequency -uint16_t ditherGetRawDividerMinSetting(void); -#define param_VB_Nmin() ditherGetRawDividerMinSetting() - -//T_Vibro code: dither drive oscillation frequency divider 7680000/F value: dither oscillation period Tva = T_Vibro * 4/Fin, Fin = 16MHz -uint16_t ditherGetRawDividerState(void); -#define var_T_Vibro() ditherGetRawDividerState() - -//T_VB_pll -int16_t ditherGetRawPhaseState(void); -#define var_T_VB_pll() ditherGetRawPhaseState() - -//VB_tau tau pulse width of the dither drive without noise or current pulse width of the dither drive with noise; value=ttf/15360000 in seconds -uint16_t ditherGetRawPulseSetting(void); -#define param_VB_tau() ditherGetRawPulseSetting() - -//VB_Tmax tau maximum pulse width of the dither drive; value=ttf/15360000 in seconds -uint16_t ditherGetRawPulseMaxSetting(void); -#define param_VB_Tmax() ditherGetRawPulseMaxSetting() - -//VB_Tmin tau minimum pulse width of the dither drive; value=ttf/15360000 in seconds -uint16_t ditherGetRawPulseMinSetting(void); -#define param_VB_Tmin() ditherGetRawPulseMinSetting() - -//L_Vibro pulse width of the dither drive without noise or current pulse width of the dither drive with noise; value=ttf/15360000 in seconds -uint16_t ditherGetRawPulseState(void); -#define var_L_Vibro() ditherGetRawPulseState() - -//VBN_Tzd s16 adjusted noise period -//int32_t device.dither.noise.settings.period -uint16_t param_VBN_Tzd(void); - -//VBN_Ran s16 range of the random component of noise -//int32_t device.dither.noise.settings.range -uint16_t param_VBN_Ran(void); - -#endif /* __DEVICE_DITHER_H__ */ \ No newline at end of file