Index: Accel.c =================================================================== diff -u -r0326224a3f615dc96b30c49e14a275493392d1fd -r23d1abf85337979b6d547aae1f9f34ce95473fe7 --- Accel.c (.../Accel.c) (revision 0326224a3f615dc96b30c49e14a275493392d1fd) +++ Accel.c (.../Accel.c) (revision 23d1abf85337979b6d547aae1f9f34ce95473fe7) @@ -43,7 +43,7 @@ #define MAX_TILT_ANGLE_TO_CLEAR_ALARM ( 5.0 ) ///< Maximum tilt of system before alarm is cleared /// Maximum time (in task intervals) that a tilt in excess of limit can persist before alarm static const U32 MAX_TILT_PERSISTENCE = ( 1 * MS_PER_SECOND / TASK_PRIORITY_INTERVAL ); -#define MAX_SHOCK_ACCELERATION ( 5.0 ) ///< Maximum shock (acceleration) measured on any axis before alarm +#define MAX_SHOCK_ACCELERATION ( 2.5 ) ///< Maximum shock (acceleration) measured on any axis before alarm #define MAX_SHOCK_TO_CLEAR_ALARM ( 1.0 ) ///< Maximum shock (acceleration) measured on any axis in order to clear alarm #define MAX_TILT_G ( 1.0 ) ///< Maximum tilt (in g) #define MAX_TILT_ANGLE_DEG ( 90.0 ) ///< Maximum tilt angle (in degrees) @@ -84,7 +84,10 @@ static U32 accelReadingsCount = 0; ///< number of samples in flow rolling average buffer static F32 accelAvgVector[ NUM_OF_ACCEL_AXES ]; ///< Filtered accelerometer vector for tilt static F32 accelTilt[ NUM_OF_ACCEL_AXES ]; ///< Axis angles for tilt determination (filtered and converted to degrees) -static U32 accelTiltErrorTimerCounter = 0; ///< used for persistence requirement on tilt error +static U32 accelTiltErrorTimerCounter = 0; ///< used for persistence requirement on tilt error + +static BOOL tiltErrorDetected; ///< Flag indicates a tilt error has been detected and tilt must now come below alarm clear threshold to clear alarm. +static BOOL shockErrorDetected; ///< Flag indicates a shock error has been detected and g-force must now come below alarm clear threshold to clear alarm. static ACCELEROMETER_SELF_TEST_STATE_T accelSelfTestState = ACCELEROMETER_SELF_TEST_STATE_START; ///< current accelerometer self-test state @@ -123,7 +126,10 @@ accelMaxs[ axis ].ovData = 0.0; accelMaxs[ axis ].ovInitData = 0.0; accelMaxs[ axis ].override = OVERRIDE_RESET; - } + } + + tiltErrorDetected = FALSE; + shockErrorDetected = FALSE; } /*********************************************************************//** @@ -477,17 +483,27 @@ { // excessive tilt must persist before triggering alarm if ( ++accelTiltErrorTimerCounter > MAX_TILT_PERSISTENCE ) - { + { + tiltErrorDetected = TRUE; #ifdef _DG_ SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DG_EXCESSIVE_TILT, x, y ) #else SET_ALARM_WITH_2_F32_DATA( ALARM_ID_HD_EXCESSIVE_TILT, x, y ) #endif } + } + else if ( ( TRUE == tiltErrorDetected ) && ( ( fabs( x ) > MAX_TILT_ANGLE_TO_CLEAR_ALARM ) || ( fabs( y ) > MAX_TILT_ANGLE_TO_CLEAR_ALARM ) ) ) + { +#ifdef _DG_ + SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DG_EXCESSIVE_TILT, x, y ) +#else + SET_ALARM_WITH_2_F32_DATA( ALARM_ID_HD_EXCESSIVE_TILT, x, y ) +#endif } else if ( ( fabs( x ) <= MAX_TILT_ANGLE_TO_CLEAR_ALARM ) && ( fabs( y ) <= MAX_TILT_ANGLE_TO_CLEAR_ALARM ) ) { - accelTiltErrorTimerCounter = 0; + accelTiltErrorTimerCounter = 0; + tiltErrorDetected = FALSE; #ifdef _DG_ clearAlarmCondition( ALARM_ID_DG_EXCESSIVE_TILT ); #else @@ -532,15 +548,25 @@ // has system just experienced an excessive shock? if ( maxAll > MAX_SHOCK_ACCELERATION ) - { + { + shockErrorDetected = TRUE; #ifdef _DG_ SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DG_SHOCK, (F32)maxAxis, getMaxAccelAxis( maxAxis ) ) #else SET_ALARM_WITH_2_F32_DATA( ALARM_ID_HD_SHOCK, (F32)maxAxis, getMaxAccelAxis( maxAxis ) ) #endif } + else if ( ( TRUE == shockErrorDetected ) && ( maxAll > MAX_SHOCK_TO_CLEAR_ALARM ) ) + { +#ifdef _DG_ + SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DG_SHOCK, (F32)maxAxis, getMaxAccelAxis( maxAxis ) ) +#else + SET_ALARM_WITH_2_F32_DATA( ALARM_ID_HD_SHOCK, (F32)maxAxis, getMaxAccelAxis( maxAxis ) ) +#endif + } else if ( maxAll <= MAX_SHOCK_TO_CLEAR_ALARM ) { + shockErrorDetected = FALSE; #ifdef _DG_ clearAlarmCondition( ALARM_ID_DG_SHOCK ); #else