123
Fork of LG by
DeviceCounters.h@197:7a05523bf588, 2016-10-19 (annotated)
- 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?
User | Revision | Line number | New contents of line |
---|---|---|---|
Diletant | 156:e68ee0bcdcda | 1 | #ifndef __DEVICE_COUNTERS_H__ |
Diletant | 156:e68ee0bcdcda | 2 | #define __DEVICE_COUNTERS_H__ |
Diletant | 156:e68ee0bcdcda | 3 | |
Diletant | 174:0f86eedd511c | 4 | //Dither latched counters typedefs |
Diletant | 174:0f86eedd511c | 5 | typedef struct _DeviceCountersDitherLatchedSettings { |
Diletant | 174:0f86eedd511c | 6 | } DeviceCountersDitherLatchedSettings; |
Diletant | 174:0f86eedd511c | 7 | |
Diletant | 177:672ef279c8e0 | 8 | //Updates 32 times each measurement cycle |
Diletant | 174:0f86eedd511c | 9 | typedef struct _DeviceCountersDitherLatchedState { |
Diletant | 174:0f86eedd511c | 10 | int32_t delta[32]; //Cyclic buffer of QEI counts with (32 * oscillation frequency) update frequency |
Diletant | 177:672ef279c8e0 | 11 | int32_t rate; //Sum of last 32 deltas from delta[] - angle accumulated for 1 vibro cycle till now - angular rate |
Diletant | 177:672ef279c8e0 | 12 | int32_t angle; //Angle accumulated between user angle requests, or between periodic answers |
Diletant | 177:672ef279c8e0 | 13 | int32_t amplitude; //Positive deltas minus negative deltas from last 32 deltas - dither amplitude - "output frequency" |
Diletant | 174:0f86eedd511c | 14 | int32_t displacement; //Sum of last 16 deltas minus sum of previous 16 deltas from delta buffer - displacement |
Diletant | 177:672ef279c8e0 | 15 | //int32_t amp; //Positive displacements minus negative displacements from last 32 displacements - dither "amplitude" |
Diletant | 174:0f86eedd511c | 16 | } DeviceCountersDitherLatchedState; |
Diletant | 174:0f86eedd511c | 17 | |
Diletant | 174:0f86eedd511c | 18 | typedef struct _DeviceCountersDitherLatched { |
Diletant | 174:0f86eedd511c | 19 | DeviceCountersDitherLatchedSettings settings; |
Diletant | 174:0f86eedd511c | 20 | DeviceCountersDitherLatchedState state; |
Diletant | 174:0f86eedd511c | 21 | } DeviceCountersDitherLatched; |
Diletant | 174:0f86eedd511c | 22 | |
Diletant | 177:672ef279c8e0 | 23 | //Reconstructed (virtual) meander latched counters typedefs |
Diletant | 174:0f86eedd511c | 24 | typedef struct _DeviceCountersMeanderLatchedSettings { |
Diletant | 174:0f86eedd511c | 25 | } DeviceCountersMeanderLatchedSettings; |
Diletant | 174:0f86eedd511c | 26 | |
Diletant | 177:672ef279c8e0 | 27 | //Updates once each measurement cycle |
Diletant | 174:0f86eedd511c | 28 | typedef struct _DeviceCountersMeanderLatchedState { |
Diletant | 174:0f86eedd511c | 29 | int32_t a; //Positive counts |
Diletant | 174:0f86eedd511c | 30 | int32_t b; //Negative counts |
Diletant | 177:672ef279c8e0 | 31 | int32_t c; //Positive counts of previous cycle |
Diletant | 177:672ef279c8e0 | 32 | int32_t rate[2]; //Angle accumulated for full vibro cycle - angular rate: a - b + (a - c)/2 |
Diletant | 177:672ef279c8e0 | 33 | int32_t angle[2]; //Accumulated angle: angle[0] += a - b; angle[1] += a - c; angle = angle[0] - angle[1]/2 |
Diletant | 177:672ef279c8e0 | 34 | int32_t amplitude; //Dither amplitude (output frequency): amplitude = a + b; |
Diletant | 174:0f86eedd511c | 35 | } DeviceCountersMeanderLatchedState; |
Diletant | 174:0f86eedd511c | 36 | |
Diletant | 174:0f86eedd511c | 37 | typedef struct _DeviceCountersMeanderLatched { |
Diletant | 174:0f86eedd511c | 38 | DeviceCountersMeanderLatchedSettings settings; |
Diletant | 174:0f86eedd511c | 39 | DeviceCountersMeanderLatchedState state; |
Diletant | 174:0f86eedd511c | 40 | } DeviceCountersMeanderLatched; |
Diletant | 174:0f86eedd511c | 41 | |
Diletant | 174:0f86eedd511c | 42 | //Virtual zero sensor latched counters typedefs |
Diletant | 174:0f86eedd511c | 43 | typedef struct _DeviceCountersZeroLatchedSettings { |
Diletant | 174:0f86eedd511c | 44 | } DeviceCountersZeroLatchedSettings; |
Diletant | 174:0f86eedd511c | 45 | |
Diletant | 174:0f86eedd511c | 46 | typedef struct _DeviceCountersZeroLatchedState { |
Diletant | 174:0f86eedd511c | 47 | int32_t a; //Positive counts |
Diletant | 174:0f86eedd511c | 48 | int32_t b; //Negative counts |
Diletant | 174:0f86eedd511c | 49 | } DeviceCountersZeroLatchedState; |
Diletant | 174:0f86eedd511c | 50 | |
Diletant | 174:0f86eedd511c | 51 | typedef struct _DeviceCountersZeroLatched { |
Diletant | 174:0f86eedd511c | 52 | DeviceCountersZeroLatchedSettings settings; |
Diletant | 174:0f86eedd511c | 53 | DeviceCountersZeroLatchedState state; |
Diletant | 174:0f86eedd511c | 54 | } DeviceCountersZeroLatched; |
Diletant | 174:0f86eedd511c | 55 | |
Diletant | 177:672ef279c8e0 | 56 | //External latch typedefs |
Diletant | 177:672ef279c8e0 | 57 | typedef struct _DeviceCountersExternalLatchSettings { |
Diletant | 177:672ef279c8e0 | 58 | uint16_t enabled;//Latch mode 0/1 - internal/external |
Diletant | 177:672ef279c8e0 | 59 | uint16_t signal; //External latch signal 0/1 - RS422/Wire |
Diletant | 177:672ef279c8e0 | 60 | uint16_t format; //Angle format: 0/1/2 - (Delta_PS 16.0)/(Delta_BINS 14.18)/(Delta_SF ?.?) |
Diletant | 177:672ef279c8e0 | 61 | uint16_t reset; //Reset mode 0/1 - keep/reset device.counters.dither.state.angle on latch |
Diletant | 177:672ef279c8e0 | 62 | } DeviceCountersExternalLatchSettings; |
Diletant | 177:672ef279c8e0 | 63 | |
Diletant | 177:672ef279c8e0 | 64 | typedef struct _DeviceCountersExternalLatchState { |
Diletant | 177:672ef279c8e0 | 65 | uint16_t enabled;//Latch mode 0/1 - internal/external |
Diletant | 177:672ef279c8e0 | 66 | uint16_t signal; //External latch signal 0/1 - RS422/Wire |
Diletant | 177:672ef279c8e0 | 67 | uint16_t format; //Angle format: 0/1/2 - (Delta_PS 16.0)/(Delta_BINS 14.18)/(Delta_SF ?.?) |
Diletant | 177:672ef279c8e0 | 68 | uint16_t reset; //Reset mode 0/1 - keep/reset device.counters.dither.state.angle on latch |
Diletant | 177:672ef279c8e0 | 69 | uint16_t clock; //Interpolator ratio |
Diletant | 177:672ef279c8e0 | 70 | uint32_t angle; //Latched angle = device.counters.dither.state.angle + clock/period * device.counters.dither.state.delta[device.measurement.counter] |
Diletant | 177:672ef279c8e0 | 71 | } DeviceCountersExternalLatchState; |
Diletant | 177:672ef279c8e0 | 72 | |
Diletant | 177:672ef279c8e0 | 73 | typedef struct _DeviceCountersExternalLatch { |
Diletant | 177:672ef279c8e0 | 74 | DeviceCountersExternalLatchSettings settings; |
Diletant | 177:672ef279c8e0 | 75 | DeviceCountersExternalLatchState state; |
Diletant | 177:672ef279c8e0 | 76 | } DeviceCountersExternalLatch; |
Diletant | 177:672ef279c8e0 | 77 | |
Diletant | 177:672ef279c8e0 | 78 | //Maintenance rate output typedefs |
Diletant | 177:672ef279c8e0 | 79 | typedef struct _DeviceCountersRateSettings { |
Diletant | 177:672ef279c8e0 | 80 | uint16_t source; //0/1 - output meander/dither latched counters in rate commands |
Diletant | 177:672ef279c8e0 | 81 | } DeviceCountersRateSettings; |
Diletant | 177:672ef279c8e0 | 82 | |
Diletant | 177:672ef279c8e0 | 83 | typedef struct _DeviceCountersRateState { |
Diletant | 177:672ef279c8e0 | 84 | uint16_t source; //0/1 - output meander/dither latched counters in rate commands |
Diletant | 177:672ef279c8e0 | 85 | } DeviceCountersRateState; |
Diletant | 177:672ef279c8e0 | 86 | |
Diletant | 177:672ef279c8e0 | 87 | typedef struct _DeviceCountersRate { |
Diletant | 177:672ef279c8e0 | 88 | DeviceCountersRateSettings settings; |
Diletant | 177:672ef279c8e0 | 89 | DeviceCountersRateState state; |
Diletant | 177:672ef279c8e0 | 90 | } DeviceCountersRate; |
Diletant | 177:672ef279c8e0 | 91 | |
Diletant | 174:0f86eedd511c | 92 | //Counters typedefs |
Diletant | 174:0f86eedd511c | 93 | typedef struct _DeviceCounters { |
Diletant | 177:672ef279c8e0 | 94 | DeviceCountersDitherLatched dither; //Counters latched by dither (measurement) cycle |
Diletant | 177:672ef279c8e0 | 95 | DeviceCountersMeanderLatched meander; //Counters latched by restored meander (angular velocity reverse latched) |
Diletant | 177:672ef279c8e0 | 96 | DeviceCountersZeroLatched zero; //Counters latched by virtual zero position sensor |
Diletant | 177:672ef279c8e0 | 97 | DeviceCountersExternalLatch latch; //External latch mode variables |
Diletant | 177:672ef279c8e0 | 98 | DeviceCountersRate rate; //Rate mode variables |
Diletant | 174:0f86eedd511c | 99 | } DeviceCounters; |
Diletant | 174:0f86eedd511c | 100 | |
Diletant | 167:bedc0a9d559a | 101 | void InitCountersDefaultSettings(void); |
Diletant | 167:bedc0a9d559a | 102 | void InitCountersState(void); |
Diletant | 167:bedc0a9d559a | 103 | void DeviceStartCounters(void); |
Diletant | 167:bedc0a9d559a | 104 | |
Diletant | 173:7f938afb0447 | 105 | void countersProcess(void); |
Diletant | 156:e68ee0bcdcda | 106 | |
Diletant | 182:2bd8ec44998f | 107 | //Compatibility functions section |
Diletant | 183:c7a9c309086c | 108 | //Cnt_Dif |
Diletant | 183:c7a9c309086c | 109 | int16_t var_Cnt_Dif(void); |
Diletant | 183:c7a9c309086c | 110 | //PSdiff |
Diletant | 182:2bd8ec44998f | 111 | int16_t var_PSdiff(void); |
Diletant | 182:2bd8ec44998f | 112 | int16_t var_Device_Mode(void); |
Diletant | 183:c7a9c309086c | 113 | //void set_var_Device_Mode(int16_t); |
Diletant | 182:2bd8ec44998f | 114 | |
Diletant | 156:e68ee0bcdcda | 115 | #endif /* __DEVICE_COUNTERS_H__ */ |