123

Dependencies:   mbed

Fork of LG by igor Apu

Revision:
177:672ef279c8e0
Parent:
174:0f86eedd511c
Child:
182:2bd8ec44998f
--- a/DeviceCounters.h	Thu Jun 30 09:04:22 2016 +0000
+++ b/DeviceCounters.h	Sun Jul 03 13:40:48 2016 +0000
@@ -5,13 +5,14 @@
 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 angle;        //Sum of last 32 deltas from delta buffer - angle accumulated for 1 vibro cycle till now
+  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 amplitude;    //Sum of positive displacements minus negative displacements from last 32 displacements - dither "amplitude"
-  int32_t frequency;    //Sum of positive deltas minus negative deltas from last 32 deltas - dither "output frequency"
-  int32_t accumulator;  //Angle accumulated between user read requests, or between periodic answers
+  //int32_t amp;        //Positive displacements minus negative displacements from last 32 displacements - dither "amplitude"
 } DeviceCountersDitherLatchedState;
 
 typedef struct _DeviceCountersDitherLatched {
@@ -19,13 +20,18 @@
   DeviceCountersDitherLatchedState state;
 } DeviceCountersDitherLatched;
 
-//Reconstructed meander latched counters typedefs
+//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 {
@@ -47,32 +53,51 @@
   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
+  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;
 
-/*
-typedef struct _DeviceCountersSettings {
-} DeviceCountersSettings;
-
-typedef struct _DeviceCountersState {
-  int32_t delta[32];    //Cyclic buffer of QEI counts with (32 * oscillation frequency) update frequency
-  int32_t angle;        //Sum of last 32 deltas from delta buffer - angle accumulated for 1 vibro cycle till now
-  int32_t displacement; //Sum of last 16 deltas minus sum of previous 16 deltas from delta buffer - displacement
-  int32_t amplitude;    //Sum of positive displacements minus negative displacements from last 32 displacements - dither "amplitude"
-  int32_t frequency;    //Sum of positive deltas minus negative deltas from last 32 deltas - dither "output frequency"
-  int32_t accumulator;  //Angle accumulated between user read requests, or between periodic answers
-} DeviceCountersState;
-
-typedef struct _DeviceCounters {
-  DeviceCountersSettings settings;
-  DeviceCountersState state;
-} DeviceCounters;
-*/
-
 void InitCountersDefaultSettings(void);
 void InitCountersState(void);
 void DeviceStartCounters(void);