123

Dependencies:   mbed

Fork of LG by igor Apu

Committer:
Diletant
Date:
Sun Jun 19 03:54:35 2016 +0000
Revision:
173:7f938afb0447
Parent:
167:bedc0a9d559a
Child:
177:672ef279c8e0
Device&... update. Not final!!!

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 173:7f938afb0447 6 int32_t width; //start pulse width - 0...1 in 16.16 format
Diletant 173:7f938afb0447 7 int32_t min; //min pulse width - 0...1 in 16.16 format
Diletant 173:7f938afb0447 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 173:7f938afb0447 12 int32_t width; //pulse width - 0...1 in 16.16 format
Diletant 173:7f938afb0447 13 int32_t min; //min pulse width - 0...1 in 16.16 format
Diletant 173:7f938afb0447 14 int32_t max; //max pulse width - 0...1 in 16.16 format
Diletant 173:7f938afb0447 15 int32_t rise; //rising edge position in 10 mks resolution ticks
Diletant 173:7f938afb0447 16 int32_t fall; //falling edge position in 10 mks resolution ticks
Diletant 161:efd949e8d536 17 uint32_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 173:7f938afb0447 28 int32_t period; //base (constant) part of noise period - 0...100 measurement cycles
Diletant 173:7f938afb0447 29 int32_t range; //variable (random) part of noise period - 0...50 measurement cycles
Diletant 173:7f938afb0447 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 173:7f938afb0447 35 int32_t period; //base (constant) part of noise state update period - 0...100 measurement cycles
Diletant 173:7f938afb0447 36 int32_t range; //variable (random) part of noise state update period - 0...50 measurement cycles
Diletant 173:7f938afb0447 37 int32_t amplitude; //pulse width variation amplitude
Diletant 173:7f938afb0447 38 int32_t counter; //noise state update counter - 0 ... (period + range - 1) in measurement cycles
Diletant 173:7f938afb0447 39 int32_t trigger; //noise state update trigger - 0 ... (period + range - 1) in measurement cycles
Diletant 173:7f938afb0447 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 173:7f938afb0447 54 int8_t enabled; //dither on/off
Diletant 173:7f938afb0447 55 int8_t pin1; //pin 1 state
Diletant 173:7f938afb0447 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 173:7f938afb0447 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 173:7f938afb0447 70 uint32_t points; //Number of actual control points (up to 16)
Diletant 173:7f938afb0447 71 int32_t raw[16]; //Raw phase (distorted) - -1...+1 in signed 16.16 fixed point format
Diletant 173:7f938afb0447 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 173:7f938afb0447 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 173:7f938afb0447 83 int32_t sum; //Raw phase accumulator
Diletant 173:7f938afb0447 84 int32_t raw; //Raw (distorted) phase
Diletant 173:7f938afb0447 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 173:7f938afb0447 102 int32_t max; //signed 16.16 format maximum oscillation frequency. TODO: max(temperature)
Diletant 173:7f938afb0447 103 int32_t min; //signed 16.16 format minimum oscillation frequency. TODO: min(temperature)
Diletant 173:7f938afb0447 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 173:7f938afb0447 110 int32_t max; //maximum oscillation frequency - Hz in signed 16.16 format
Diletant 173:7f938afb0447 111 int32_t min; //minimum oscillation frequency - Hz in signed 16.16 format
Diletant 173:7f938afb0447 112 int32_t frequency; //oscillation frequency - Hz in signed 16.16 format
Diletant 173:7f938afb0447 113 int32_t scale; //regulator scale factor - Hz in signed 16.16 format
Diletant 173:7f938afb0447 114 int32_t error; //regulator error - Hz in signed 16.16 format
Diletant 173:7f938afb0447 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 173:7f938afb0447 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 173:7f938afb0447 132 int32_t reference; //signed 16.16 format reference information signal carrier frequency
Diletant 173:7f938afb0447 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 173:7f938afb0447 139 int32_t reference; //0...200 (kHz) signed 16.16 format reference information signal carrier frequency
Diletant 173:7f938afb0447 140 int32_t scale; //regulator scale factor in signed 16.16 format
Diletant 173:7f938afb0447 141 int32_t frequency; //carrier frequency in signed 16.16 format
Diletant 173:7f938afb0447 142 int32_t error; //signed 16.16 format regulator error
Diletant 173:7f938afb0447 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 149:abbf7663d27d 168 #endif /* __DEVICE_DITHER_H__ */