Index: Accel.c =================================================================== diff -u -r0326224a3f615dc96b30c49e14a275493392d1fd -rdc42849f88021151de2006199e17fddd7a7a6678 --- Accel.c (.../Accel.c) (revision 0326224a3f615dc96b30c49e14a275493392d1fd) +++ Accel.c (.../Accel.c) (revision dc42849f88021151de2006199e17fddd7a7a6678) @@ -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) @@ -85,7 +85,10 @@ 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 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 // ********** private function prototypes ********** @@ -124,6 +127,9 @@ accelMaxs[ axis ].ovInitData = 0.0; accelMaxs[ axis ].override = OVERRIDE_RESET; } + + tiltErrorDetected = FALSE; + shockErrorDetected = FALSE; } /*********************************************************************//** @@ -478,16 +484,26 @@ // 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; + tiltErrorDetected = FALSE; #ifdef _DG_ clearAlarmCondition( ALARM_ID_DG_EXCESSIVE_TILT ); #else @@ -533,14 +549,24 @@ // 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