123

Dependencies:   mbed

Fork of LG by igor Apu

DeviceCounters.h

Committer:
Diletant
Date:
2016-07-03
Revision:
177:672ef279c8e0
Parent:
174:0f86eedd511c
Child:
182:2bd8ec44998f

File content as of revision 177:672ef279c8e0:

#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);

#endif  /* __DEVICE_COUNTERS_H__ */