Index: firmware/App/Controllers/SensorProcess.c =================================================================== diff -u -r6d2d8f0267c57135554e5a1acaca9aef37f27949 -ra24665c05496241e5ba9a73e0b1831a85dfbc3c9 --- firmware/App/Controllers/SensorProcess.c (.../SensorProcess.c) (revision 6d2d8f0267c57135554e5a1acaca9aef37f27949) +++ firmware/App/Controllers/SensorProcess.c (.../SensorProcess.c) (revision a24665c05496241e5ba9a73e0b1831a85dfbc3c9) @@ -13,9 +13,12 @@ * @brief Processing sensor data. * **************************************************************************/ + +#include "SensorProcess.h" +#include "Common.h" +#include "SystemCommMessages.h" +#include "FPGA.h" -#include "gio.h" - /**@}*/ /*********************************************************************//** @@ -28,4 +31,44 @@ *************************************************************************/ void execSensorProcess() { +#ifdef DEBUG_ENABLED + char debugStr[ 256 ]; +#endif + static U32 Counter = 0; + static U32 Load_cell_a1 = 0; + static U32 Load_cell_a2 = 0; + static U32 Load_cell_b1 = 0; + static U32 Load_cell_b2 = 0; + F32 load_cell_a1_f; + F32 load_cell_a2_f; + F32 load_cell_b1_f; + F32 load_cell_b2_f; + BOOL result; + + Load_cell_a1 += getFPGALoadCellA1(); // No overflow since ADC output is 24 bits. + Load_cell_a2 += getFPGALoadCellA2(); + Load_cell_b1 += getFPGALoadCellB1(); + Load_cell_b2 += getFPGALoadCellB2(); + + Counter++; + if (Counter == LOAD_CELL_REPORT_PERIOD) + { + Counter = 0; + + load_cell_a1_f = (F32)(Load_cell_a1)*ADC2GRAM; // division for averaging folded into ADC2GRAM + load_cell_a2_f = (F32)(Load_cell_a2)*ADC2GRAM; + load_cell_b1_f = (F32)(Load_cell_b1)*ADC2GRAM; + load_cell_b2_f = (F32)(Load_cell_b2)*ADC2GRAM; + result = broadcastLoadCellData( load_cell_a1_f, load_cell_a2_f, load_cell_b1_f, load_cell_b2_f ); +#ifdef DEBUG_ENABLED + if (result == FALSE) + sprintf( debugStr, "Adding load cell data to CAN buffer failed" ); +#else + (void)result; +#endif + Load_cell_a1 = 0; + Load_cell_a2 = 0; + Load_cell_b1 = 0; + Load_cell_b2 = 0; + } } Index: firmware/App/Controllers/SensorProcess.h =================================================================== diff -u -r6d2d8f0267c57135554e5a1acaca9aef37f27949 -ra24665c05496241e5ba9a73e0b1831a85dfbc3c9 --- firmware/App/Controllers/SensorProcess.h (.../SensorProcess.h) (revision 6d2d8f0267c57135554e5a1acaca9aef37f27949) +++ firmware/App/Controllers/SensorProcess.h (.../SensorProcess.h) (revision a24665c05496241e5ba9a73e0b1831a85dfbc3c9) @@ -18,9 +18,10 @@ #define APP_CONTROLLERS_SENSORPROCESS_H_ +#define LOAD_CELL_REPORT_PERIOD 10 // Send a load cell value CAN message to HD every multiple of taskPriority periods (10ms) +#define ADC2GRAM 0.0894/LOAD_CELL_REPORT_PERIOD // division for averaging is folded into this value - #endif /* APP_CONTROLLERS_SENSORPROCESS_H_ */ Index: firmware/App/Services/FPGA.c =================================================================== diff -u -r6d2d8f0267c57135554e5a1acaca9aef37f27949 -ra24665c05496241e5ba9a73e0b1831a85dfbc3c9 --- firmware/App/Services/FPGA.c (.../FPGA.c) (revision 6d2d8f0267c57135554e5a1acaca9aef37f27949) +++ firmware/App/Services/FPGA.c (.../FPGA.c) (revision a24665c05496241e5ba9a73e0b1831a85dfbc3c9) @@ -931,7 +931,7 @@ * @param none * @return last load cell A 1 reading *************************************************************************/ -F32 getFPGALoadCellA1( void ) +U32 getFPGALoadCellA1( void ) { return fpgaSensorReadings.LCA1; } @@ -945,7 +945,7 @@ * @param none * @return last load cell A 2 reading *************************************************************************/ -F32 getFPGALoadCellA2( void ) +U32 getFPGALoadCellA2( void ) { return fpgaSensorReadings.LCA2; } @@ -959,7 +959,7 @@ * @param none * @return last load cell B 1 reading *************************************************************************/ -F32 getFPGALoadCellB1( void ) +U32 getFPGALoadCellB1( void ) { return fpgaSensorReadings.LCB1; } @@ -973,40 +973,13 @@ * @param none * @return last load cell B 2 reading *************************************************************************/ -F32 getFPGALoadCellB2( void ) +U32 getFPGALoadCellB2( void ) { return fpgaSensorReadings.LCB2; } -/************************************************************************* - * @brief getFPGABloodFlow - * The getFPGABloodFlow function gets the latest blood flow reading. - * @details - * Inputs : fpgaSensorReadings - * Outputs : none - * @param none - * @return last blood flow reading - *************************************************************************/ -F32 getFPGABloodFlow( void ) -{ - return fpgaSensorReadings.bloodFlowLast; -} /************************************************************************* - * @brief getFPGADialysateFlow - * The getFPGADialysateFlow function gets the latest dialysate flow reading. - * @details - * Inputs : fpgaSensorReadings - * Outputs : none - * @param none - * @return last dialysate flow reading - *************************************************************************/ -F32 getFPGADialysateFlow( void ) -{ - return fpgaSensorReadings.dialysateFlowLast; -} - -/************************************************************************* * @brief getFPGABloodPumpOcclusion * The getFPGABloodPumpOcclusion function gets the latest blood occlusion reading. * @details Index: firmware/App/Services/FPGA.h =================================================================== diff -u -rf068446fdb7889d320ddb6ffbd58f347ce0501e7 -ra24665c05496241e5ba9a73e0b1831a85dfbc3c9 --- firmware/App/Services/FPGA.h (.../FPGA.h) (revision f068446fdb7889d320ddb6ffbd58f347ce0501e7) +++ firmware/App/Services/FPGA.h (.../FPGA.h) (revision a24665c05496241e5ba9a73e0b1831a85dfbc3c9) @@ -34,6 +34,10 @@ U16 getFPGAStatus( void ); void setFPGAControl( U16 ctrl ); +U32 getFPGALoadCellA1( void ); +U32 getFPGALoadCellA2( void ); +U32 getFPGALoadCellB1( void ); +U32 getFPGALoadCellB2( void ); F32 getFPGABloodFlow( void ); F32 getFPGADialysateFlow( void ); U16 getFPGAArterialPressure( void ); Index: firmware/App/Services/SystemCommMessages.h =================================================================== diff -u -r4d27576bdd7843178d9b69ffff3584ee01ec24fe -ra24665c05496241e5ba9a73e0b1831a85dfbc3c9 --- firmware/App/Services/SystemCommMessages.h (.../SystemCommMessages.h) (revision 4d27576bdd7843178d9b69ffff3584ee01ec24fe) +++ firmware/App/Services/SystemCommMessages.h (.../SystemCommMessages.h) (revision a24665c05496241e5ba9a73e0b1831a85dfbc3c9) @@ -71,6 +71,9 @@ // MSG_ID_RTC_EPOCH BOOL broadcastRTCEpoch( U32 epoch ); // TODO - probably don't want DG to broadcast these +// MSG_ID_LOAD_CELL_READINGS +BOOL broadcastLoadCellData( F32 loadCellA1, F32 loadCellA2, F32 loadCellB1, F32 loadCellB2 ); + #ifdef CAN_TEST // MSG_ID_DG_CAN_TEST_1_LARGE_FREQ void broadcastCANTest1LargeFrequentMessage();