Index: firmware/App/Controllers/LoadCell.c =================================================================== diff -u -rc548570b37339819da825092dd07c7081437f30b -rc48a99d2d1c852adcc986253b6c420a90dab7bfe --- firmware/App/Controllers/LoadCell.c (.../LoadCell.c) (revision c548570b37339819da825092dd07c7081437f30b) +++ firmware/App/Controllers/LoadCell.c (.../LoadCell.c) (revision c48a99d2d1c852adcc986253b6c420a90dab7bfe) @@ -33,9 +33,9 @@ // ********** private data ********** -static OVERRIDE_U32_T measuredLoadCellReadingsRaw[ NUM_OF_LOAD_CELLS ]; ///< Latest measured raw load cell readings. +static U32 measuredLoadCellReadingsRaw[ NUM_OF_LOAD_CELLS ]; ///< Latest measured raw load cell readings. static U32 measuredLoadCellReadingsSum[ NUM_OF_LOAD_CELLS ]; ///< Raw load cell sums for averaging. -static F32 filteredLoadCellWeights[ NUM_OF_LOAD_CELLS ]; ///< Latest filtered load cell weights. +static OVERRIDE_F32_T filteredLoadCellWeights[ NUM_OF_LOAD_CELLS ]; ///< Latest filtered load cell weights. static U32 loadCellDataPublicationTimerCounter = 0; ///< used to schedule load cell data publication to CAN bus. // ********** private function prototypes ********** @@ -54,14 +54,14 @@ for ( i = 0; i < NUM_OF_LOAD_CELLS; i++ ) { - measuredLoadCellReadingsRaw[ i ].data = 0; - measuredLoadCellReadingsRaw[ i ].ovData = 0; - measuredLoadCellReadingsRaw[ i ].ovInitData = 0; - measuredLoadCellReadingsRaw[ i ].override = OVERRIDE_RESET; + filteredLoadCellWeights[ i ].data = 0.0; + filteredLoadCellWeights[ i ].ovData = 0.0; + filteredLoadCellWeights[ i ].ovInitData = 0.0; + filteredLoadCellWeights[ i ].override = OVERRIDE_RESET; measuredLoadCellReadingsSum[ i ] = 0; - filteredLoadCellWeights[ i ] = 0.0; + measuredLoadCellReadingsRaw[ i ] = 0.0; } } @@ -76,27 +76,28 @@ void execLoadCell(void) { // get latest raw load cell readings - measuredLoadCellReadingsRaw[ LOAD_CELL_A1 ].data = getFPGALoadCellA1(); - measuredLoadCellReadingsRaw[ LOAD_CELL_A2 ].data = getFPGALoadCellA2(); - measuredLoadCellReadingsRaw[ LOAD_CELL_B1 ].data = getFPGALoadCellB1(); - measuredLoadCellReadingsRaw[ LOAD_CELL_B2 ].data = getFPGALoadCellB2(); + measuredLoadCellReadingsRaw[ LOAD_CELL_A1 ] = getFPGALoadCellA1(); + measuredLoadCellReadingsRaw[ LOAD_CELL_A2 ] = getFPGALoadCellA2(); + measuredLoadCellReadingsRaw[ LOAD_CELL_B1 ] = getFPGALoadCellB1(); + measuredLoadCellReadingsRaw[ LOAD_CELL_B2 ] = getFPGALoadCellB2(); // update sums for load cell average calculations - measuredLoadCellReadingsSum[ LOAD_CELL_A1 ] += getMeasuredRawLoadCellReading( LOAD_CELL_A1 ); - measuredLoadCellReadingsSum[ LOAD_CELL_A2 ] += getMeasuredRawLoadCellReading( LOAD_CELL_A2 ); - measuredLoadCellReadingsSum[ LOAD_CELL_B1 ] += getMeasuredRawLoadCellReading( LOAD_CELL_B1 ); - measuredLoadCellReadingsSum[ LOAD_CELL_B2 ] += getMeasuredRawLoadCellReading( LOAD_CELL_B2 ); + measuredLoadCellReadingsSum[ LOAD_CELL_A1 ] += measuredLoadCellReadingsRaw[ LOAD_CELL_A1 ]; + measuredLoadCellReadingsSum[ LOAD_CELL_A2 ] += measuredLoadCellReadingsRaw[ LOAD_CELL_A2 ]; + measuredLoadCellReadingsSum[ LOAD_CELL_B1 ] += measuredLoadCellReadingsRaw[ LOAD_CELL_B1 ]; + measuredLoadCellReadingsSum[ LOAD_CELL_B2 ] += measuredLoadCellReadingsRaw[ LOAD_CELL_B2 ]; + // broadcast load cell data if we are at scheduled interval. if ( ++loadCellDataPublicationTimerCounter == LOAD_CELL_REPORT_PERIOD ) { loadCellDataPublicationTimerCounter = 0; // calculate load cell average weights - filteredLoadCellWeights[ LOAD_CELL_A1 ] = (F32)(measuredLoadCellReadingsSum[ LOAD_CELL_A1 ]) * ADC2GRAM; // division for averaging folded into ADC2GRAM - filteredLoadCellWeights[ LOAD_CELL_A2 ] = (F32)(measuredLoadCellReadingsSum[ LOAD_CELL_A2 ]) * ADC2GRAM; - filteredLoadCellWeights[ LOAD_CELL_B1 ] = (F32)(measuredLoadCellReadingsSum[ LOAD_CELL_B1 ]) * ADC2GRAM; - filteredLoadCellWeights[ LOAD_CELL_B2 ] = (F32)(measuredLoadCellReadingsSum[ LOAD_CELL_B2 ]) * ADC2GRAM; + filteredLoadCellWeights[ LOAD_CELL_A1 ].data = (F32)(measuredLoadCellReadingsSum[ LOAD_CELL_A1 ]) * ADC2GRAM; // division for averaging folded into ADC2GRAM + filteredLoadCellWeights[ LOAD_CELL_A2 ].data = (F32)(measuredLoadCellReadingsSum[ LOAD_CELL_A2 ]) * ADC2GRAM; + filteredLoadCellWeights[ LOAD_CELL_B1 ].data = (F32)(measuredLoadCellReadingsSum[ LOAD_CELL_B1 ]) * ADC2GRAM; + filteredLoadCellWeights[ LOAD_CELL_B2 ].data = (F32)(measuredLoadCellReadingsSum[ LOAD_CELL_B2 ]) * ADC2GRAM; // broadcast load cell data - broadcastLoadCellData( filteredLoadCellWeights[ LOAD_CELL_A1 ], filteredLoadCellWeights[ LOAD_CELL_A2 ], - filteredLoadCellWeights[ LOAD_CELL_B1 ], filteredLoadCellWeights[ LOAD_CELL_B2 ] ); + broadcastLoadCellData( getLoadCellFilteredWeight( LOAD_CELL_A1 ), getLoadCellFilteredWeight( LOAD_CELL_A2 ), + getLoadCellFilteredWeight( LOAD_CELL_B1 ), getLoadCellFilteredWeight( LOAD_CELL_B2 ) ); // reset sums for next averaging measuredLoadCellReadingsSum[ LOAD_CELL_A1 ] = 0; measuredLoadCellReadingsSum[ LOAD_CELL_A2 ] = 0; @@ -107,27 +108,27 @@ /************************************************************************* * @brief - * The getMeasuredRawLoadCellReading function gets the measured raw load cell \n - * reading for a given load cell ID. + * The getLoadCellFilteredWeight function gets the measured filtered load cell \n + * weight for a given load cell ID. * @details - * Inputs : measuredLoadCellReadingsRaw + * Inputs : filteredLoadCellWeights[] * Outputs : none - * @param loadCellID : ID of load cell to get raw reading for. - * @return the measured raw load cell reading for the given load cell ID. + * @param loadCellID : ID of load cell to get filtered weight for. + * @return the filtered load cell weight for the given load cell ID. *************************************************************************/ -U32 getMeasuredRawLoadCellReading( U32 loadCellID ) +U32 getLoadCellFilteredWeight( U32 loadCellID ) { U32 result = 0; if ( loadCellID < NUM_OF_LOAD_CELLS ) { - if ( OVERRIDE_KEY == measuredLoadCellReadingsRaw[ loadCellID ].override ) + if ( OVERRIDE_KEY == filteredLoadCellWeights[ loadCellID ].override ) { - result = measuredLoadCellReadingsRaw[ loadCellID ].ovData; + result = filteredLoadCellWeights[ loadCellID ].ovData; } else { - result = measuredLoadCellReadingsRaw[ loadCellID ].data; + result = filteredLoadCellWeights[ loadCellID ].data; } } else @@ -138,33 +139,7 @@ return result; } -/************************************************************************* - * @brief - * The getLoadCellFilteredWeight function gets the measured filtered load cell \n - * weight for a given load cell ID. - * @details - * Inputs : Load_cell_a1_ave[] - * Outputs : none - * @param loadCellID : ID of load cell to get filtered weight for. - * @return the measured filtered load cell weight for the given load cell ID. - *************************************************************************/ -F32 getLoadCellFilteredWeight( LOAD_CELL_ID_T loadCellID ) -{ - F32 result = 0; - if ( loadCellID < NUM_OF_LOAD_CELLS ) - { - result = filteredLoadCellWeights[ loadCellID ]; - } - else - { - activateAlarmNoData( ALARM_ID_SOFTWARE_FAULT ); - } - - return result; -} - - /************************************************************************* * TEST SUPPORT FUNCTIONS *************************************************************************/ @@ -176,20 +151,20 @@ * load cell A1. * @details * Inputs : none - * Outputs : measuredLoadCellReadingsRaw[] - * @param value : override measured load cell reading + * Outputs : filteredLoadCellWeights[] + * @param value : override filtered load cell weight * @param loadCellID : ID of the load cell to override. * @return TRUE if override successful, FALSE if not *************************************************************************/ -BOOL testSetLoadCellOverride( U32 value, U32 loadCellID ) +BOOL testSetLoadCellOverride( F32 value, U32 loadCellID ) { BOOL result = FALSE; if ( TRUE == isTestingActivated() ) { result = TRUE; - measuredLoadCellReadingsRaw[ loadCellID ].ovData = value; - measuredLoadCellReadingsRaw[ loadCellID ].override = OVERRIDE_KEY; + filteredLoadCellWeights[ loadCellID ].ovData = value; + filteredLoadCellWeights[ loadCellID ].override = OVERRIDE_KEY; } return result; @@ -201,7 +176,7 @@ * load cell A1. * @details * Inputs : none - * Outputs : measuredLoadCellReadingsRaw[] + * Outputs : filteredLoadCellWeights[] * @param loadCellID : ID of the load cell to override. * @return TRUE if reset successful, FALSE if not *************************************************************************/ @@ -212,8 +187,8 @@ if ( TRUE == isTestingActivated() ) { result = TRUE; - measuredLoadCellReadingsRaw[ loadCellID ].override = OVERRIDE_RESET; - measuredLoadCellReadingsRaw[ loadCellID ].ovData = measuredLoadCellReadingsRaw[ loadCellID ].ovInitData; + filteredLoadCellWeights[ loadCellID ].override = OVERRIDE_RESET; + filteredLoadCellWeights[ loadCellID ].ovData = filteredLoadCellWeights[ loadCellID ].ovInitData; } return result;