123
Fork of LG by
DeviceCounters.h
- Committer:
- Diletant
- Date:
- 2016-07-10
- Revision:
- 182:2bd8ec44998f
- Parent:
- 177:672ef279c8e0
- Child:
- 183:c7a9c309086c
File content as of revision 182:2bd8ec44998f:
#ifndef __DEVICE_COUNTERS_H__ #define __DEVICE_COUNTERS_H__ //Dither latched counters typedefs typedef struct _DeviceCountersDitherLatchedSettings { } DeviceCountersDitherLatchedSettings; //Updates 32 times each measurement cycle typedef struct _DeviceCountersDitherLatchedState { int32_t delta[32]; //Cyclic buffer of QEI counts with (32 * oscillation frequency) update frequency int32_t rate; //Sum of last 32 deltas from delta[] - angle accumulated for 1 vibro cycle till now - angular rate int32_t angle; //Angle accumulated between user angle requests, or between periodic answers int32_t amplitude; //Positive deltas minus negative deltas from last 32 deltas - dither amplitude - "output frequency" int32_t displacement; //Sum of last 16 deltas minus sum of previous 16 deltas from delta buffer - displacement //int32_t amp; //Positive displacements minus negative displacements from last 32 displacements - dither "amplitude" } DeviceCountersDitherLatchedState; typedef struct _DeviceCountersDitherLatched { DeviceCountersDitherLatchedSettings settings; DeviceCountersDitherLatchedState state; } DeviceCountersDitherLatched; //Reconstructed (virtual) meander latched counters typedefs typedef struct _DeviceCountersMeanderLatchedSettings { } DeviceCountersMeanderLatchedSettings; //Updates once each measurement cycle typedef struct _DeviceCountersMeanderLatchedState { int32_t a; //Positive counts int32_t b; //Negative counts int32_t c; //Positive counts of previous cycle int32_t rate[2]; //Angle accumulated for full vibro cycle - angular rate: a - b + (a - c)/2 int32_t angle[2]; //Accumulated angle: angle[0] += a - b; angle[1] += a - c; angle = angle[0] - angle[1]/2 int32_t amplitude; //Dither amplitude (output frequency): amplitude = a + b; } DeviceCountersMeanderLatchedState; typedef struct _DeviceCountersMeanderLatched { DeviceCountersMeanderLatchedSettings settings; DeviceCountersMeanderLatchedState state; } DeviceCountersMeanderLatched; //Virtual zero sensor latched counters typedefs typedef struct _DeviceCountersZeroLatchedSettings { } DeviceCountersZeroLatchedSettings; typedef struct _DeviceCountersZeroLatchedState { int32_t a; //Positive counts int32_t b; //Negative counts } DeviceCountersZeroLatchedState; typedef struct _DeviceCountersZeroLatched { DeviceCountersZeroLatchedSettings settings; DeviceCountersZeroLatchedState state; } DeviceCountersZeroLatched; //External latch typedefs typedef struct _DeviceCountersExternalLatchSettings { uint16_t enabled;//Latch mode 0/1 - internal/external uint16_t signal; //External latch signal 0/1 - RS422/Wire uint16_t format; //Angle format: 0/1/2 - (Delta_PS 16.0)/(Delta_BINS 14.18)/(Delta_SF ?.?) uint16_t reset; //Reset mode 0/1 - keep/reset device.counters.dither.state.angle on latch } DeviceCountersExternalLatchSettings; typedef struct _DeviceCountersExternalLatchState { uint16_t enabled;//Latch mode 0/1 - internal/external uint16_t signal; //External latch signal 0/1 - RS422/Wire uint16_t format; //Angle format: 0/1/2 - (Delta_PS 16.0)/(Delta_BINS 14.18)/(Delta_SF ?.?) uint16_t reset; //Reset mode 0/1 - keep/reset device.counters.dither.state.angle on latch uint16_t clock; //Interpolator ratio uint32_t angle; //Latched angle = device.counters.dither.state.angle + clock/period * device.counters.dither.state.delta[device.measurement.counter] } DeviceCountersExternalLatchState; typedef struct _DeviceCountersExternalLatch { DeviceCountersExternalLatchSettings settings; DeviceCountersExternalLatchState state; } DeviceCountersExternalLatch; //Maintenance rate output typedefs typedef struct _DeviceCountersRateSettings { uint16_t source; //0/1 - output meander/dither latched counters in rate commands } DeviceCountersRateSettings; typedef struct _DeviceCountersRateState { uint16_t source; //0/1 - output meander/dither latched counters in rate commands } DeviceCountersRateState; typedef struct _DeviceCountersRate { DeviceCountersRateSettings settings; DeviceCountersRateState state; } DeviceCountersRate; //Counters typedefs typedef struct _DeviceCounters { DeviceCountersDitherLatched dither; //Counters latched by dither (measurement) cycle DeviceCountersMeanderLatched meander; //Counters latched by restored meander (angular velocity reverse latched) DeviceCountersZeroLatched zero; //Counters latched by virtual zero position sensor DeviceCountersExternalLatch latch; //External latch mode variables DeviceCountersRate rate; //Rate mode variables } DeviceCounters; void InitCountersDefaultSettings(void); void InitCountersState(void); void DeviceStartCounters(void); void countersProcess(void); //Compatibility functions section int16_t countersGetRateAngle(void); int16_t var_PSdiff(void); int16_t var_Device_Mode(void); #endif /* __DEVICE_COUNTERS_H__ */