Index: firmware/App/Controllers/LoadCell.c =================================================================== diff -u -r97e0100921ccad633b39b509a93a7237e4d80446 -r22f1a58ac8e419353ec004b04e7c765c1d59df2b --- firmware/App/Controllers/LoadCell.c (.../LoadCell.c) (revision 97e0100921ccad633b39b509a93a7237e4d80446) +++ firmware/App/Controllers/LoadCell.c (.../LoadCell.c) (revision 22f1a58ac8e419353ec004b04e7c765c1d59df2b) @@ -34,17 +34,19 @@ // TODO check the maximum weight on the load cells in tare. There was 1500 grams limit // but it has been removed. Check the load cells data sheet. -#define LOAD_CELL_REPORT_PERIOD (100 / TASK_PRIORITY_INTERVAL) ///< Broadcast load cell values message every 100 ms. +#define LOAD_CELL_REPORT_PERIOD (100 / TASK_PRIORITY_INTERVAL) ///< Broadcast load cell values message every 100 ms. /// Conversion factor from ADC counts to grams. -static const F32 ADC2GRAM = (0.0894 * 1.1338); -#define LOAD_CELL_FILTER_ALPHA 0.05 ///< Alpha factor for the alpha filter used on load cell readings. +static const F32 ADC2GRAM = (0.0894 * 1.1338); +#define LOAD_CELL_FILTER_ALPHA 0.05 ///< Alpha factor for the alpha filter used on load cell readings. -#define SIZE_OF_SMALL_LOAD_CELL_AVG 100 ///< Small load cell moving average has 100 raw samples @ 10ms intervals (1-second). -#define SIZE_OF_LARGE_LOAD_CELL_AVG 40 ///< Large load cell moving average has 40 samples from small filter @ 100ms intervals (4-second). +#define SIZE_OF_SMALL_LOAD_CELL_AVG 100 ///< Small load cell moving average has 100 raw samples @ 10ms intervals (1-second). +#define SIZE_OF_LARGE_LOAD_CELL_AVG 40 ///< Large load cell moving average has 40 samples from small filter @ 100ms intervals (4-second). -#define LOAD_CELL_ADC_ERROR_PERSISTENCE 500 ///< Alarm persistence period (in ms) for load cell ADC errors. -#define EMPTY_RESERVOIR_WEIGHT_GRAMS 1600 ///< Reservoirs empty weight in grams. -#define MAX_ALLOWED_EXTRA_WEIGHT_BEFORE_TARE_GRAMS 300 ///< Max allowed extra weight before tare in grams. +#define LOAD_CELL_ADC_ERROR_PERSISTENCE 500 ///< Alarm persistence period (in ms) for load cell ADC errors. +#define LOAD_CELL_MIN_ALLOWED_WEIGHT_GRAMS 1600 ///< Load cell minimum allowed weight in grams. +#define LOAD_CELL_MAX_ALLOWED_WEIGHT_GRAMS 4500 ///< Load cell maximum allowed weight in grams. +#define MAX_ALLOWED_EXTRA_WEIGHT_BEFORE_TARE_GRAMS 300 ///< Max allowed extra weight before tare in grams. +#define LOAD_CELL_WEIGHT_OUT_RANGE_PERSISTENT_PERIOD_MS (5 * MS_PER_SECOND) ///< Load cell weight out of range persistent period in milliseconds. /// Load cell data structure. typedef struct @@ -79,6 +81,7 @@ static U32 getLoadCellDataPublishInterval( void ); static BOOL processCalibrationData( void ); +static void monitorLoadCellsWeightOutOfRange( void ); /*********************************************************************//** * @brief @@ -87,7 +90,7 @@ * @details Outputs: LoadCell module initialized. * @return none *************************************************************************/ -void initLoadCell( void ) + void initLoadCell( void ) { U32 cell; U32 i; @@ -126,18 +129,11 @@ loadcells[ i ].loadCellVelocity_g_min = 0.0; } - for ( cell = CAL_DATA_LOAD_CELL_A1; cell < NUM_OF_CAL_DATA_LOAD_CELLS; cell++ ) - { - // Reset the calibration variables - loadCellsCalRecord.loadCells[ cell ].fourthOrderCoeff = 0.0; - loadCellsCalRecord.loadCells[ cell ].thirdOrderCoeff = 0.0; - loadCellsCalRecord.loadCells[ cell ].secondOrderCoeff = 0.0; - loadCellsCalRecord.loadCells[ cell ].gain = 1.0; - loadCellsCalRecord.loadCells[ cell ].offset = 0.0; - } - // Initialize persistent alarm(s) initPersistentAlarm( ALARM_ID_DG_LOAD_CELL_ADC_ERROR, 0, LOAD_CELL_ADC_ERROR_PERSISTENCE ); + + initPersistentAlarm( ALARM_ID_DG_LOAD_CELL_WEIGHT_OUT_OF_RANGE, LOAD_CELL_WEIGHT_OUT_RANGE_PERSISTENT_PERIOD_MS, + LOAD_CELL_WEIGHT_OUT_RANGE_PERSISTENT_PERIOD_MS ); } /*********************************************************************//** @@ -244,6 +240,9 @@ loadCellDataPublicationTimerCounter = 0; } + + // Monitor the weight of the load cells + monitorLoadCellsWeightOutOfRange(); } /*********************************************************************//** @@ -292,7 +291,7 @@ { // For the first tare, the weight of the reservoir should be considered // The current weight of the load cell should not be greater than the weight of the reservoir + the extra weight - F32 deltaWeight = fabs( weight - EMPTY_RESERVOIR_WEIGHT_GRAMS ); + F32 deltaWeight = fabs( weight - LOAD_CELL_MIN_ALLOWED_WEIGHT_GRAMS ); isWeightOutOfRange = ( deltaWeight > MAX_ALLOWED_EXTRA_WEIGHT_BEFORE_TARE_GRAMS ? TRUE : FALSE ); } else @@ -493,7 +492,34 @@ return status; } +/*********************************************************************//** + * @brief + * The monitorLoadCellsWeightOutOfRange function monitors the weight of the + * load cells and if they are not in range, it raises an alarm. + * @details Inputs: loadcells + * @details Outputs: none + * @return none + *************************************************************************/ +static void monitorLoadCellsWeightOutOfRange( void ) +{ + LOAD_CELL_ID_T loadCell; + BOOL isWeightOutOfRange; + F32 weight; + for ( loadCell = LOAD_CELL_RESERVOIR_1_PRIMARY; loadCell < NUM_OF_LOAD_CELLS; loadCell++ ) + { + // The load cells must have been tared before checking for the weight range + if ( loadcells[ loadCell ].autoCalOffset != 0 ) + { + weight = getLoadCellSmallFilteredWeight( loadCell ); + isWeightOutOfRange = ( weight < LOAD_CELL_MIN_ALLOWED_WEIGHT_GRAMS ) || ( weight > LOAD_CELL_MAX_ALLOWED_WEIGHT_GRAMS ); + + checkPersistentAlarm( ALARM_ID_DG_LOAD_CELL_WEIGHT_OUT_OF_RANGE, isWeightOutOfRange, weight, LOAD_CELL_MAX_ALLOWED_WEIGHT_GRAMS ); + } + } +} + + /************************************************************************* * TEST SUPPORT FUNCTIONS *************************************************************************/