Index: firmware/App/Controllers/LoadCell.c =================================================================== diff -u -re9f4774b8c6c4b5d064bca8076e084dd9b72da76 -re6453f6070bec116e1f1e3a553eb2c6a7aac1f9d --- firmware/App/Controllers/LoadCell.c (.../LoadCell.c) (revision e9f4774b8c6c4b5d064bca8076e084dd9b72da76) +++ firmware/App/Controllers/LoadCell.c (.../LoadCell.c) (revision e6453f6070bec116e1f1e3a553eb2c6a7aac1f9d) @@ -164,8 +164,8 @@ *************************************************************************/ void execLoadCell( void ) { - LOAD_CELL_ID_T ii; - LOAD_CELL_ID_T alarmID; + LOAD_CELL_ID_T sensorId; + LOAD_CELL_ID_T sensorInAlarm = LOAD_CELL_RESERVOIR_1_PRIMARY; U32 a1 = getFPGALoadCellA1(); U32 a2 = getFPGALoadCellA2(); U32 b1 = getFPGALoadCellB1(); @@ -212,58 +212,58 @@ } // Rolling average of last 100 raw samples in small filter - for ( ii = LOAD_CELL_RESERVOIR_1_PRIMARY; ii < NUM_OF_LOAD_CELLS; ++ii ) + for ( sensorId = LOAD_CELL_RESERVOIR_1_PRIMARY; sensorId < NUM_OF_LOAD_CELLS; ++sensorId ) { - F32 loadCell = (F32)loadcells[ ii ].rawReading * ADC2GRAM; + F32 loadCell = (F32)loadcells[ sensorId ].rawReading * ADC2GRAM; // Apply the calibration factors to the data. // load_cell_weight = fourth_order_coeff * (load_cell^4) + third_order_coeff * (load_cell^3) + second_order_coeff * (load_cell^2) + gain * load_cell + offset - loadcells[ ii ].weight.data = pow( loadCell, 4 ) * loadCellsCalRecord.loadCells[ (CAL_DATA_DG_LOAD_CELLS_T)ii ].fourthOrderCoeff + - pow( loadCell, 3 ) * loadCellsCalRecord.loadCells[ (CAL_DATA_DG_LOAD_CELLS_T)ii ].thirdOrderCoeff + - pow( loadCell, 2 ) * loadCellsCalRecord.loadCells[ (CAL_DATA_DG_LOAD_CELLS_T)ii ].secondOrderCoeff + - loadCell * loadCellsCalRecord.loadCells[ (CAL_DATA_DG_LOAD_CELLS_T)ii ].gain + - loadCellsCalRecord.loadCells[ (CAL_DATA_DG_LOAD_CELLS_T)ii ].offset; + loadcells[ sensorId ].weight.data = pow( loadCell, 4 ) * loadCellsCalRecord.loadCells[ (CAL_DATA_DG_LOAD_CELLS_T)sensorId ].fourthOrderCoeff + + pow( loadCell, 3 ) * loadCellsCalRecord.loadCells[ (CAL_DATA_DG_LOAD_CELLS_T)sensorId ].thirdOrderCoeff + + pow( loadCell, 2 ) * loadCellsCalRecord.loadCells[ (CAL_DATA_DG_LOAD_CELLS_T)sensorId ].secondOrderCoeff + + loadCell * loadCellsCalRecord.loadCells[ (CAL_DATA_DG_LOAD_CELLS_T)sensorId ].gain + + loadCellsCalRecord.loadCells[ (CAL_DATA_DG_LOAD_CELLS_T)sensorId ].offset; // Monitor the load cells weight // Since there is a single alarm value for all 4 load cells the persistence check must be // executed if ANY of the load cell values are out of range. Only when all of the load // cells are in range should the persistence for the alarm be cleared. - weight = getLoadCellWeight( ( LOAD_CELL_ID_T) ii ); + weight = getLoadCellWeight( ( LOAD_CELL_ID_T) sensorId ); if ( ( weight < LOAD_CELL_MIN_ALLOWED_WEIGHT_GRAMS ) || ( weight > LOAD_CELL_MAX_ALLOWED_WEIGHT_GRAMS ) ) { isLoadCellOutOfRange = TRUE; - alarmID = ii; + sensorInAlarm = sensorId; alarmLoadCell = weight; } - loadcells[ ii ].loadCellVelocity_g_min = ( getLoadCellWeight( (LOAD_CELL_ID_T)ii ) - - loadcells[ ii ].smallFilterReadings[ smallReadingsIdx ] ) * (F32)SEC_PER_MIN; + loadcells[ sensorId ].loadCellVelocity_g_min = ( getLoadCellWeight( (LOAD_CELL_ID_T)sensorId ) - + loadcells[ sensorId ].smallFilterReadings[ smallReadingsIdx ] ) * (F32)SEC_PER_MIN; // Update small filter with new weight sample - loadcells[ ii ].smallFilterTotal -= loadcells[ ii ].smallFilterReadings[ smallReadingsIdx ]; - loadcells[ ii ].smallFilterReadings[ smallReadingsIdx ] = getLoadCellWeight( (LOAD_CELL_ID_T)ii ); - loadcells[ ii ].smallFilterTotal += getLoadCellWeight( (LOAD_CELL_ID_T)ii ); + loadcells[ sensorId ].smallFilterTotal -= loadcells[ sensorId ].smallFilterReadings[ smallReadingsIdx ]; + loadcells[ sensorId ].smallFilterReadings[ smallReadingsIdx ] = getLoadCellWeight( (LOAD_CELL_ID_T)sensorId ); + loadcells[ sensorId ].smallFilterTotal += getLoadCellWeight( (LOAD_CELL_ID_T)sensorId ); // Calculate the load cell value before applying calibration to it - loadcells[ ii ].smallFilteredWeight.data = (F32)( loadcells[ ii ].smallFilterTotal / (F64)SIZE_OF_SMALL_LOAD_CELL_AVG ); + loadcells[ sensorId ].smallFilteredWeight.data = (F32)( loadcells[ sensorId ].smallFilterTotal / (F64)SIZE_OF_SMALL_LOAD_CELL_AVG ); // Apply the tare offset. NOTE: tare must be applied after checking the weight out of range. - loadcells[ ii ].smallFilteredWeight.data -= loadcells[ ii ].autoCalOffset; + loadcells[ sensorId ].smallFilteredWeight.data -= loadcells[ sensorId ].autoCalOffset; } - checkPersistentAlarm( ALARM_ID_DG_LOAD_CELL_WEIGHT_OUT_OF_RANGE, isLoadCellOutOfRange, alarmID, alarmLoadCell ); + checkPersistentAlarm( ALARM_ID_DG_LOAD_CELL_WEIGHT_OUT_OF_RANGE, isLoadCellOutOfRange, sensorInAlarm, alarmLoadCell ); smallReadingsIdx = INC_WRAP( smallReadingsIdx, 0, SIZE_OF_SMALL_LOAD_CELL_AVG - 1 ); // filter every 100ms if ( ++loadCellFilterTimerCount >= LOAD_CELL_REPORT_PERIOD ) { - for ( ii = LOAD_CELL_RESERVOIR_1_PRIMARY; ii < NUM_OF_LOAD_CELLS; ++ii ) + for ( sensorId = LOAD_CELL_RESERVOIR_1_PRIMARY; sensorId < NUM_OF_LOAD_CELLS; ++sensorId ) { // Update large filter with new small filter weight sample - loadcells[ ii ].largeFilterTotal -= loadcells[ ii ].largeFilterReadings[ largeReadingsIdx ]; - loadcells[ ii ].largeFilterReadings[ largeReadingsIdx ] = getLoadCellSmallFilteredWeight((LOAD_CELL_ID_T) ii); - loadcells[ ii ].largeFilterTotal += getLoadCellSmallFilteredWeight((LOAD_CELL_ID_T) ii); - loadcells[ ii ].largeFilteredWeight = (F32)( loadcells[ ii ].largeFilterTotal / (F64)SIZE_OF_LARGE_LOAD_CELL_AVG ); + loadcells[ sensorId ].largeFilterTotal -= loadcells[ sensorId ].largeFilterReadings[ largeReadingsIdx ]; + loadcells[ sensorId ].largeFilterReadings[ largeReadingsIdx ] = getLoadCellSmallFilteredWeight((LOAD_CELL_ID_T) sensorId); + loadcells[ sensorId ].largeFilterTotal += getLoadCellSmallFilteredWeight((LOAD_CELL_ID_T) sensorId); + loadcells[ sensorId ].largeFilteredWeight = (F32)( loadcells[ sensorId ].largeFilterTotal / (F64)SIZE_OF_LARGE_LOAD_CELL_AVG ); } loadCellFilterTimerCount = 0;