Index: firmware/App/Monitors/Level.c =================================================================== diff -u -r3ea4def3a3a69a00fb96b6089dbd097fa80041de -rba5c71eab6b1930bfb044a165d803f5c16c3379a --- firmware/App/Monitors/Level.c (.../Level.c) (revision 3ea4def3a3a69a00fb96b6089dbd097fa80041de) +++ firmware/App/Monitors/Level.c (.../Level.c) (revision ba5c71eab6b1930bfb044a165d803f5c16c3379a) @@ -31,6 +31,10 @@ #define FPGA_LEVEL_LOW 2 ///< Floater low level status #define FPGA_LEVEL_MEDIUM 3 ///< Floater medium level status #define FPGA_LEVEL_HIGH 1 ///< Floater high level status +#define LEVEL_COUNT_LOW 0x637F ///< Level sensor count when fluid level is low or non submerged +#define LEVEL_COUNT_HIGH ( LEVEL_COUNT_LOW / 2 ) ///< Level sensor count when fluid level is high or submerged +#define LOW_LEVEL_COUNT_TOLERANCE ( ( LEVEL_COUNT_LOW / 100 ) * 1 ) ///< Level sensor count 1% tolerance for low level +#define HIGH_LEVEL_COUNT_TOLERANCE ( ( LEVEL_COUNT_HIGH / 100 ) * 1 ) ///< Level sensor count 1% tolerance for high level #define LEVEL_DATA_PUB_INTERVAL ( MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) ///< Interval (ms/task time) at which the level data is published on the CAN bus. #define LEVEL_DEBOUNCE_TIME_MS ( MS_PER_SECOND / 10 ) ///< Level debounce time in milliseconds. #define DATA_PUBLISH_COUNTER_START_COUNT 7 ///< Data publish counter start count. @@ -54,6 +58,7 @@ // ********** private function prototypes ********** static void publishLevelsData( void ); +static BOOL processLevelCount( U16 count ); /*********************************************************************//** * @brief @@ -122,11 +127,11 @@ break; case BICARB_LEVEL: - currentLevelStatus = ( getFPGALevelSensor1() != 0 ? LEVEL_STATE_LOW : LEVEL_STATE_HIGH ); + currentLevelStatus = ( processLevelCount( getFPGALevelSensor1() ) == 0 ? LEVEL_STATE_LOW : LEVEL_STATE_HIGH ); break; case SPENT_DIALYSATE_LEVEL: - currentLevelStatus = ( getFPGALevelSensor2() != 0 ? LEVEL_STATE_LOW : LEVEL_STATE_HIGH ); + currentLevelStatus = ( processLevelCount( getFPGALevelSensor2() ) == 0 ? LEVEL_STATE_LOW : LEVEL_STATE_HIGH ); break; #ifndef _VECTORCAST_ @@ -217,6 +222,38 @@ /*********************************************************************//** * @brief + * The processLevelCount function checks the range of count reported by FPGA + * and determine level based on the count. + * @details \b Inputs: none + * @details \b Outputs: level + * @param count The level count reported by FPGA + * @return level status + *************************************************************************/ +static BOOL processLevelCount( U16 count ) +{ + BOOL level = FALSE; + + // Check the level count with in the low/high level range + if ( ( count < LEVEL_COUNT_LOW + LOW_LEVEL_COUNT_TOLERANCE ) && + ( count > LEVEL_COUNT_LOW - LOW_LEVEL_COUNT_TOLERANCE ) ) + { + level = FALSE; + } + else if ( ( count < LEVEL_COUNT_HIGH + HIGH_LEVEL_COUNT_TOLERANCE ) && + ( count > LEVEL_COUNT_HIGH - HIGH_LEVEL_COUNT_TOLERANCE ) ) + { + level = TRUE; + } + else + { + level = FALSE; + } + + return level; +} + +/*********************************************************************//** + * @brief * The publishLevelsData function broadcasts the level data at the * publication interval. * @details \b Inputs: levelsDataPublicationCounter