123

Dependencies:   mbed

Fork of LG by igor Apu

Committer:
Kovalev_D
Date:
Wed Oct 19 10:55:05 2016 +0000
Revision:
197:7a05523bf588
Parent:
183:c7a9c309086c
modul

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Diletant 149:abbf7663d27d 1 #ifndef __DEVICE_DITHER_H__
Diletant 149:abbf7663d27d 2 #define __DEVICE_DITHER_H__
Diletant 149:abbf7663d27d 3
Diletant 161:efd949e8d536 4 //Dither drive pulse typedefs
Diletant 161:efd949e8d536 5 typedef struct _DeviceDitherPulseSettings {
Diletant 177:672ef279c8e0 6 int32_t width; //start pulse width - 0...1 in 16.16 format
Diletant 177:672ef279c8e0 7 int32_t min; //min pulse width - 0...1 in 16.16 format
Diletant 177:672ef279c8e0 8 int32_t max; //max pulse width - 0...1 in 16.16 format
Diletant 161:efd949e8d536 9 } DeviceDitherPulseSettings;
Diletant 149:abbf7663d27d 10
Diletant 161:efd949e8d536 11 typedef struct _DeviceDitherPulseState {
Diletant 177:672ef279c8e0 12 int32_t width; //pulse width - 0...1 in 16.16 format
Diletant 177:672ef279c8e0 13 int32_t min; //min pulse width - 0...1 in 16.16 format
Diletant 177:672ef279c8e0 14 int32_t max; //max pulse width - 0...1 in 16.16 format
Diletant 177:672ef279c8e0 15 int32_t rise; //rising edge position in 10 mks resolution ticks
Diletant 177:672ef279c8e0 16 int32_t fall; //falling edge position in 10 mks resolution ticks
Diletant 183:c7a9c309086c 17 int32_t counter; //10 mks resolution counter, zeroed at each dither half period
Diletant 161:efd949e8d536 18 } DeviceDitherPulseState;
Diletant 161:efd949e8d536 19
Diletant 161:efd949e8d536 20 typedef struct _DeviceDitherPulse {
Diletant 161:efd949e8d536 21 DeviceDitherPulseSettings settings;
Diletant 161:efd949e8d536 22 DeviceDitherPulseState state;
Diletant 161:efd949e8d536 23 } DeviceDitherPulse;
Diletant 161:efd949e8d536 24
Diletant 161:efd949e8d536 25 //Dither noise typedefs
Diletant 161:efd949e8d536 26 typedef struct _DeviceDitherNoiseSettings {
Diletant 173:7f938afb0447 27 int8_t enabled;
Diletant 183:c7a9c309086c 28 int32_t period; //base (fixed) part of noise period - 0...100 measurement cycles
Diletant 177:672ef279c8e0 29 int32_t range; //variable (random) part of noise period - 0...50 measurement cycles
Diletant 177:672ef279c8e0 30 int32_t amplitude; //pulse width variation amplitude
Diletant 161:efd949e8d536 31 } DeviceDitherNoiseSettings;
Diletant 161:efd949e8d536 32
Diletant 161:efd949e8d536 33 typedef struct _DeviceDitherNoiseState {
Diletant 173:7f938afb0447 34 int8_t enabled;
Diletant 183:c7a9c309086c 35 int32_t period; //base (fixed) part of noise state update period - 0...100 measurement cycles
Diletant 177:672ef279c8e0 36 int32_t range; //variable (random) part of noise state update period - 0...50 measurement cycles
Diletant 177:672ef279c8e0 37 int32_t amplitude; //pulse width variation amplitude
Diletant 177:672ef279c8e0 38 int32_t counter; //noise state update counter - 0 ... (period + range - 1) in measurement cycles
Diletant 177:672ef279c8e0 39 int32_t trigger; //noise state update trigger - 0 ... (period + range - 1) in measurement cycles
Diletant 177:672ef279c8e0 40 int32_t disturbance; //pulse width disturbance - -1...1 (-100...100% of maximum pulse width) in 16.16 format
Diletant 161:efd949e8d536 41 } DeviceDitherNoiseState;
Diletant 161:efd949e8d536 42
Diletant 161:efd949e8d536 43 typedef struct _DeviceDitherNoise {
Diletant 161:efd949e8d536 44 DeviceDitherNoiseSettings settings;
Diletant 161:efd949e8d536 45 DeviceDitherNoiseState state;
Diletant 161:efd949e8d536 46 } DeviceDitherNoise;
Diletant 161:efd949e8d536 47
Diletant 161:efd949e8d536 48 //Dither cycle typedefs
Diletant 161:efd949e8d536 49 typedef struct _DeviceDitherCycleSettings {
Diletant 173:7f938afb0447 50 int8_t enabled;
Diletant 161:efd949e8d536 51 } DeviceDitherCycleSettings;
Diletant 161:efd949e8d536 52
Diletant 161:efd949e8d536 53 typedef struct _DeviceDitherCycleState {
Diletant 177:672ef279c8e0 54 int8_t enabled; //dither on/off
Diletant 177:672ef279c8e0 55 int8_t pin1; //pin 1 state
Diletant 177:672ef279c8e0 56 int8_t pin2; //pin 2 state
Diletant 161:efd949e8d536 57 } DeviceDitherCycleState;
Diletant 161:efd949e8d536 58
Diletant 161:efd949e8d536 59 typedef struct _DeviceDitherCycle {
Diletant 161:efd949e8d536 60 DeviceDitherCycleSettings settings;
Diletant 161:efd949e8d536 61 DeviceDitherCycleState state;
Diletant 161:efd949e8d536 62 } DeviceDitherCycle;
Diletant 149:abbf7663d27d 63
Diletant 161:efd949e8d536 64 //Dither phase detector typedefs
Diletant 173:7f938afb0447 65 typedef struct _DeviceDitherPhaseDetectorFilterFunction {
Diletant 177:672ef279c8e0 66 int32_t factor[32]; //-1...+1 weight factors in 16.16 format
Diletant 173:7f938afb0447 67 } DeviceDitherPhaseDetectorFilterFunction;
Diletant 173:7f938afb0447 68
Diletant 173:7f938afb0447 69 typedef struct _DeviceDitherPhaseTransferFunction {
Diletant 177:672ef279c8e0 70 uint32_t points; //Number of actual control points (up to 16)
Diletant 177:672ef279c8e0 71 int32_t raw[16]; //Raw phase (distorted) - -1...+1 in signed 16.16 fixed point format
Diletant 177:672ef279c8e0 72 int32_t restored[16]; //Restored phase - -1...+1 in 16.16 fixed point format
Diletant 173:7f938afb0447 73 } DeviceDitherPhaseTransferFunction;
Diletant 173:7f938afb0447 74
Diletant 161:efd949e8d536 75 //error = sum(weight[i + offset] * device.counters.state.delta[i])
Diletant 161:efd949e8d536 76 typedef struct _DeviceDitherPhaseDetectorSettings {
Diletant 177:672ef279c8e0 77 //int32_t factor[32]; //-1...+1 weight factors in 16.16 format
Diletant 173:7f938afb0447 78 DeviceDitherPhaseDetectorFilterFunction filter;
Diletant 173:7f938afb0447 79 DeviceDitherPhaseTransferFunction transfer;
Diletant 161:efd949e8d536 80 } DeviceDitherPhaseDetectorSettings;
Diletant 161:efd949e8d536 81
Diletant 161:efd949e8d536 82 typedef struct _DeviceDitherPhaseDetectorState {
Diletant 177:672ef279c8e0 83 int32_t sum; //Raw phase accumulator
Diletant 177:672ef279c8e0 84 int32_t raw; //Raw (distorted) phase
Diletant 177:672ef279c8e0 85 int32_t phase; //Restored phase
Diletant 161:efd949e8d536 86 } DeviceDitherPhaseDetectorState;
Diletant 161:efd949e8d536 87
Diletant 161:efd949e8d536 88 typedef struct _DeviceDitherPhaseDetector {
Diletant 161:efd949e8d536 89 DeviceDitherPhaseDetectorSettings settings;
Diletant 161:efd949e8d536 90 DeviceDitherPhaseDetectorState state;
Diletant 161:efd949e8d536 91 } DeviceDitherPhaseDetector;
Diletant 161:efd949e8d536 92
Diletant 173:7f938afb0447 93 //Dither oscillation frequency regulator typedefs
Diletant 173:7f938afb0447 94 typedef struct _DeviceDitherFrequencyRegulatorTransferSettings {
Diletant 173:7f938afb0447 95 int32_t points; //actual control points 1...16 set
Diletant 173:7f938afb0447 96 int32_t error[16]; //regulator error - 0..150 Hz, signed 16.16 format
Diletant 173:7f938afb0447 97 int32_t correction[16]; //regulator oscillation frequency correction - -1...1 (-100%...100%), 16.16 format
Diletant 173:7f938afb0447 98 } DeviceDitherFrequencyRegulatorTransferSettings;
Diletant 173:7f938afb0447 99
Diletant 173:7f938afb0447 100 typedef struct _DeviceDitherFrequencyRegulatorSettings {
Diletant 173:7f938afb0447 101 int8_t enabled;
Diletant 177:672ef279c8e0 102 int32_t max; //signed 16.16 format maximum oscillation frequency. TODO: max(temperature)
Diletant 177:672ef279c8e0 103 int32_t min; //signed 16.16 format minimum oscillation frequency. TODO: min(temperature)
Diletant 177:672ef279c8e0 104 int32_t scale; //signed 16.16 format regulator scale factor. TODO: correction(phase)
Diletant 173:7f938afb0447 105 DeviceDitherFrequencyRegulatorTransferSettings transfer;
Diletant 173:7f938afb0447 106 } DeviceDitherFrequencyRegulatorSettings;
Diletant 173:7f938afb0447 107
Diletant 173:7f938afb0447 108 typedef struct _DeviceDitherFrequencyRegulatorState {
Diletant 173:7f938afb0447 109 int8_t enabled;
Diletant 177:672ef279c8e0 110 int32_t max; //maximum oscillation frequency - Hz in signed 16.16 format
Diletant 177:672ef279c8e0 111 int32_t min; //minimum oscillation frequency - Hz in signed 16.16 format
Diletant 177:672ef279c8e0 112 int32_t frequency; //oscillation frequency - Hz in signed 16.16 format
Diletant 182:2bd8ec44998f 113 int32_t scale; //regulator scale factor - in signed 16.16 format
Diletant 177:672ef279c8e0 114 int32_t error; //regulator error - Hz in signed 16.16 format
Diletant 177:672ef279c8e0 115 int32_t correction; //regulator correction - Hz in signed 16.16 format
Diletant 173:7f938afb0447 116 } DeviceDitherFrequencyRegulatorState;
Diletant 173:7f938afb0447 117
Diletant 173:7f938afb0447 118 typedef struct _DeviceDitherFrequencyRegulator {
Diletant 173:7f938afb0447 119 DeviceDitherFrequencyRegulatorSettings settings;
Diletant 173:7f938afb0447 120 DeviceDitherFrequencyRegulatorState state;
Diletant 173:7f938afb0447 121 } DeviceDitherFrequencyRegulator;
Diletant 173:7f938afb0447 122
Diletant 173:7f938afb0447 123 //Dither information signal carrier frequency regulator typedefs
Diletant 173:7f938afb0447 124 typedef struct _DeviceDitherAmplitudeRegulatorTransferSettings {
Diletant 177:672ef279c8e0 125 int32_t points; //actual control points 1...16 set
Diletant 173:7f938afb0447 126 int32_t error[16]; //regulator error - 0..200 kHz, signed 16.16 format
Diletant 173:7f938afb0447 127 int32_t correction[16]; //regulator pulse width correction - -1...1 (-100%...100%), 16.16 format
Diletant 173:7f938afb0447 128 } DeviceDitherAmplitudeRegulatorTransferSettings;
Diletant 173:7f938afb0447 129
Diletant 173:7f938afb0447 130 typedef struct _DeviceDitherAmplitudeRegulatorSettings {
Diletant 173:7f938afb0447 131 int8_t enabled;
Diletant 177:672ef279c8e0 132 int32_t reference; //signed 16.16 format reference information signal carrier frequency
Diletant 177:672ef279c8e0 133 int32_t scale; //signed 16.16 format regulator scale factor
Diletant 173:7f938afb0447 134 DeviceDitherAmplitudeRegulatorTransferSettings transfer;
Diletant 173:7f938afb0447 135 } DeviceDitherAmplitudeRegulatorSettings;
Diletant 173:7f938afb0447 136
Diletant 173:7f938afb0447 137 typedef struct _DeviceDitherAmplitudeRegulatorState {
Diletant 173:7f938afb0447 138 int8_t enabled;
Diletant 177:672ef279c8e0 139 int32_t reference; //0...200 (kHz) signed 16.16 format reference information signal carrier frequency
Diletant 177:672ef279c8e0 140 int32_t scale; //regulator scale factor in signed 16.16 format
Diletant 177:672ef279c8e0 141 int32_t frequency; //carrier frequency in signed 16.16 format
Diletant 177:672ef279c8e0 142 int32_t error; //signed 16.16 format regulator error
Diletant 177:672ef279c8e0 143 int32_t correction; //regulator pulse width correction - -1...1 in signed 16.16 format
Diletant 173:7f938afb0447 144 } DeviceDitherAmplitudeRegulatorState;
Diletant 173:7f938afb0447 145
Diletant 173:7f938afb0447 146 typedef struct _DeviceDitherAmplitudeRegulator {
Diletant 173:7f938afb0447 147 DeviceDitherAmplitudeRegulatorSettings settings;
Diletant 173:7f938afb0447 148 DeviceDitherAmplitudeRegulatorState state;
Diletant 173:7f938afb0447 149 } DeviceDitherAmplitudeRegulator;
Diletant 173:7f938afb0447 150
Diletant 161:efd949e8d536 151 //Dither drive typedefs
Diletant 149:abbf7663d27d 152 typedef struct _DeviceDither {
Diletant 161:efd949e8d536 153 DeviceDitherPulse pulse;
Diletant 161:efd949e8d536 154 DeviceDitherNoise noise;
Diletant 161:efd949e8d536 155 DeviceDitherCycle cycle;
Diletant 161:efd949e8d536 156 DeviceDitherPhaseDetector detector;
Diletant 173:7f938afb0447 157 DeviceDitherFrequencyRegulator frequency;
Diletant 173:7f938afb0447 158 DeviceDitherAmplitudeRegulator amplitude;
Diletant 149:abbf7663d27d 159 } DeviceDither;
Diletant 149:abbf7663d27d 160
Diletant 167:bedc0a9d559a 161 void InitDitherDefaultSettings(void);
Diletant 167:bedc0a9d559a 162 void InitDitherState(void);
Diletant 167:bedc0a9d559a 163 void DeviceStartDither(void);
Diletant 167:bedc0a9d559a 164
Diletant 173:7f938afb0447 165 void ditherCycle(void);
Diletant 173:7f938afb0447 166 void ditherProcess(void);
Diletant 149:abbf7663d27d 167
Diletant 182:2bd8ec44998f 168 //
Diletant 182:2bd8ec44998f 169 //Compatibility functions section
Diletant 182:2bd8ec44998f 170 //
Diletant 182:2bd8ec44998f 171
Diletant 182:2bd8ec44998f 172 //VB_Fdf s32 double output frequency (Hi)
Diletant 182:2bd8ec44998f 173 uint32_t ditherGetRawAmplitudeSetting(void); //VB_Fdf s32 double output frequency (Hi)
Diletant 182:2bd8ec44998f 174 #define param_VB_Fdf() ditherGetRawAmplitudeSetting()
Diletant 182:2bd8ec44998f 175
Diletant 182:2bd8ec44998f 176 //F_ras int16 code: output frequency, divided by 16 (for transmission); value: output frequency
Diletant 182:2bd8ec44998f 177 uint16_t ditherGetRawAmplitudeState(void);
Diletant 182:2bd8ec44998f 178 #define var_F_ras() ditherGetRawAmplitudeState()
Diletant 182:2bd8ec44998f 179
Diletant 182:2bd8ec44998f 180 //VB_N vbd ttf:dither drive oscillation central frequency divider 7680000/F; value:dither drive central oscillation frequency
Diletant 182:2bd8ec44998f 181 uint16_t ditherGetRawDividerSetting(void);
Diletant 182:2bd8ec44998f 182 #define param_VB_N() ditherGetRawDividerSetting()
Diletant 182:2bd8ec44998f 183
Diletant 182:2bd8ec44998f 184 //VB_Nmax vbd ttf:maximum dither drive oscillation frequency divider 7680000/F; value:minimum dither drive oscillation frequency
Diletant 182:2bd8ec44998f 185 uint16_t ditherGetRawDividerMaxSetting(void);
Diletant 182:2bd8ec44998f 186 #define param_VB_Nmax() ditherGetRawDividerMaxSetting()
Diletant 182:2bd8ec44998f 187
Diletant 182:2bd8ec44998f 188 //VB_Nmin vbd ttf:minimum dither drive oscillation frequency divider 7680000/F; value:maximum dither drive oscillation frequency
Diletant 182:2bd8ec44998f 189 uint16_t ditherGetRawDividerMinSetting(void);
Diletant 182:2bd8ec44998f 190 #define param_VB_Nmin() ditherGetRawDividerMinSetting()
Diletant 182:2bd8ec44998f 191
Diletant 182:2bd8ec44998f 192 //T_Vibro code: dither drive oscillation frequency divider 7680000/F value: dither oscillation period Tva = T_Vibro * 4/Fin, Fin = 16MHz
Diletant 182:2bd8ec44998f 193 uint16_t ditherGetRawDividerState(void);
Diletant 182:2bd8ec44998f 194 #define var_T_Vibro() ditherGetRawDividerState()
Diletant 182:2bd8ec44998f 195
Diletant 182:2bd8ec44998f 196 //T_VB_pll
Diletant 182:2bd8ec44998f 197 int16_t ditherGetRawPhaseState(void);
Diletant 182:2bd8ec44998f 198 #define var_T_VB_pll() ditherGetRawPhaseState()
Diletant 182:2bd8ec44998f 199
Diletant 182:2bd8ec44998f 200 //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
Diletant 182:2bd8ec44998f 201 uint16_t ditherGetRawPulseSetting(void);
Diletant 182:2bd8ec44998f 202 #define param_VB_tau() ditherGetRawPulseSetting()
Diletant 182:2bd8ec44998f 203
Diletant 182:2bd8ec44998f 204 //VB_Tmax tau maximum pulse width of the dither drive; value=ttf/15360000 in seconds
Diletant 182:2bd8ec44998f 205 uint16_t ditherGetRawPulseMaxSetting(void);
Diletant 182:2bd8ec44998f 206 #define param_VB_Tmax() ditherGetRawPulseMaxSetting()
Diletant 182:2bd8ec44998f 207
Diletant 182:2bd8ec44998f 208 //VB_Tmin tau minimum pulse width of the dither drive; value=ttf/15360000 in seconds
Diletant 182:2bd8ec44998f 209 uint16_t ditherGetRawPulseMinSetting(void);
Diletant 182:2bd8ec44998f 210 #define param_VB_Tmin() ditherGetRawPulseMinSetting()
Diletant 182:2bd8ec44998f 211
Diletant 182:2bd8ec44998f 212 //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
Diletant 182:2bd8ec44998f 213 uint16_t ditherGetRawPulseState(void);
Diletant 182:2bd8ec44998f 214 #define var_L_Vibro() ditherGetRawPulseState()
Diletant 182:2bd8ec44998f 215
Diletant 183:c7a9c309086c 216 //VBN_Tzd s16 adjusted noise period
Diletant 183:c7a9c309086c 217 //int32_t device.dither.noise.settings.period
Diletant 183:c7a9c309086c 218 uint16_t param_VBN_Tzd(void);
Diletant 183:c7a9c309086c 219
Diletant 183:c7a9c309086c 220 //VBN_Ran s16 range of the random component of noise
Diletant 183:c7a9c309086c 221 //int32_t device.dither.noise.settings.range
Diletant 183:c7a9c309086c 222 uint16_t param_VBN_Ran(void);
Diletant 183:c7a9c309086c 223
Diletant 149:abbf7663d27d 224 #endif /* __DEVICE_DITHER_H__ */