123
Fork of LG by
DeviceDither.h
- Committer:
- Diletant
- Date:
- 2016-07-03
- Revision:
- 177:672ef279c8e0
- Parent:
- 173:7f938afb0447
- Child:
- 182:2bd8ec44998f
File content as of revision 177:672ef279c8e0:
#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 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 { 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 { 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 { 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 - 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; DeviceDitherFrequencyRegulator frequency; DeviceDitherAmplitudeRegulator amplitude; } DeviceDither; void InitDitherDefaultSettings(void); void InitDitherState(void); void DeviceStartDither(void); void ditherCycle(void); void ditherProcess(void); #endif /* __DEVICE_DITHER_H__ */