Index: firmware/App/Controllers/AirTrap.c =================================================================== diff -u -r56d02fbdb137d2665a629dd7162c44d397b6545e -rf2e5da3b659f99aaa0eec9174a472529cf11b95a --- firmware/App/Controllers/AirTrap.c (.../AirTrap.c) (revision 56d02fbdb137d2665a629dd7162c44d397b6545e) +++ firmware/App/Controllers/AirTrap.c (.../AirTrap.c) (revision f2e5da3b659f99aaa0eec9174a472529cf11b95a) @@ -51,10 +51,12 @@ /// Air pump on delay after fill adjustment static const U32 AIR_PUMP_ON_DELAY_ADJUST_AFTER_FILL = ( AIR_PUMP_ON_DELAY_TIME_MS - ( 1 * MS_PER_SECOND ) ); -#define AIR_PUMP_MOTOR_FILL_PWM 150 ///< Power level setting (PWM) for H12 air pump to fill (raise level) the air trap. -#define AIR_PUMP_MOTOR_LOWER_PWM 250 ///< Power level setting (PWM) for H12 air pump to lower the level of the air trap. +#define AIR_PUMP_MOTOR_FILL_PWM 58.8f ///< Power level setting (PWM) in percentage for H12 air pump to fill (raise level) the air trap. +#define AIR_PUMP_MOTOR_LOWER_PWM 23.5f ///< Power level setting (PWM) in percentage for H12 air pump to lower the level of the air trap. #define AIR_PUMP_MOTOR_MIN_PWM_OVERRIDE 60 ///< Air pump motor minimum PWM to override. -#define AIR_PUMP_MOTOR_MAX_PWM_OVERRIDE 255 ///< Air pump motor maximum PWM to override. +#define AIR_PUMP_MOTOR_MAX_PWM_OVERRIDE 250 ///< Air pump motor maximum PWM to override. +#define AIR_PUMP_MOTOR_MAX_PWM 255 ///< Air pump motor maximum PWM. +#define AIR_PUMP_MOTOR_PWM_HUNDRED_PCT 100.0f ///< Percentage calculation constant /// from air pump manufacturer's data for pump current draw based on pump speed and venous pressure mmHg, /// the currently set air pump duty cycle (raw PWM) = 0.0005x^2 + 0.2313x + 63.667, where x is H14 venous pressure in mmHg before air pump lower event #define QUADRATIC_COEFFICIENT 0.005F ///< X2 quadratic coefficient @@ -79,8 +81,8 @@ static U32 airTrapDataPublicationTimerCounter; ///< Used to schedule air trap data publication to CAN bus. static OVERRIDE_U32_T airTrapDataPublishInterval; ///< Interval (in ms) at which to publish air trap data to CAN bus. -static OVERRIDE_U32_T airTrapAirPumpRaisePowerLevel; ///< Air pump power level to use when raising the air trap blood level. -static OVERRIDE_U32_T airTrapAirPumpLowerPowerLevel; ///< Air pump power level to use when lowering the air trap blood level. +static OVERRIDE_F32_T airTrapAirPumpRaisePowerLevel; ///< Air pump power level to use when raising the air trap blood level. +static OVERRIDE_F32_T airTrapAirPumpLowerPowerLevel; ///< Air pump power level to use when lowering the air trap blood level. static BOOL pendingStartAirTrapController; ///< Flag indicates an air trap controller start request is pending. static BOOL pendingStopAirTrapController; ///< Flag indicates an air trap controller stop request is pending. @@ -99,8 +101,8 @@ static AIR_TRAP_STATE_T handleAirTrapClosedState( void ); static AIR_TRAP_STATE_T handleAirTrapRaiseLevelState( void ); static AIR_TRAP_STATE_T handleAirTrapLowerlevelState( void ); -static U08 getAirPumpRaisePowerLevel( void ); -static U08 getAirPumpLowerPowerLevel( void ); +static F32 getAirPumpRaisePowerLevel( void ); +static F32 getAirPumpLowerPowerLevel( void ); static void publishAirTrapData( void ); /*********************************************************************//** @@ -335,7 +337,7 @@ /*********************************************************************//** * @brief - * The getCalculatedAirPumpDutyCycle function get the Air Pump calculated raw dutycycle based on H14 pressure + * The getCalculatedAirPumpDutyCycle function get the Air Pump calculated percentage duty cycle based on H14 pressure * @details \b Inputs: H14 venous pressure * @details \b Outputs: none * @return dutyCyclePct @@ -345,6 +347,7 @@ F32 h14Pressure = getFilteredVenousPressure(); // the currently set P12 duty cycle (raw PWM) must be 0.0005x^2 + 0.2313x + 63.667, where x = H14 venous pressure in mmHg before air pump lower event F32 dutyCycle = ( ( QUADRATIC_COEFFICIENT * ( h14Pressure * h14Pressure ) ) - ( LINEAR_COEFFICIENT * ( h14Pressure ) ) ) + CONSTANT_TERM; + dutyCycle = ( dutyCycle / AIR_PUMP_MOTOR_MAX_PWM ) * AIR_PUMP_MOTOR_PWM_HUNDRED_PCT; return dutyCycle; } @@ -506,9 +509,9 @@ * @details \b Outputs: none * @return air pump power level for raising air trap blood level *************************************************************************/ -static U08 getAirPumpRaisePowerLevel( void ) +static F32 getAirPumpRaisePowerLevel( void ) { - U08 result = getU08OverrideValue( &airTrapAirPumpRaisePowerLevel ); + F32 result = getF32OverrideValue( &airTrapAirPumpRaisePowerLevel ); return result; } @@ -521,9 +524,9 @@ * @details \b Outputs: none * @return air pump power level for lowering air trap blood level *************************************************************************/ -static U08 getAirPumpLowerPowerLevel( void ) +static F32 getAirPumpLowerPowerLevel( void ) { - U08 result = getU08OverrideValue( &airTrapAirPumpLowerPowerLevel ); + F32 result = getF32OverrideValue( &airTrapAirPumpLowerPowerLevel ); return result; } @@ -626,7 +629,7 @@ *************************************************************************/ BOOL testAirPumpPowerRaiseOverride( MESSAGE_T *message ) { - BOOL result = u32Override( message, &airTrapAirPumpRaisePowerLevel, AIR_PUMP_MOTOR_OFF, AIR_PUMP_MOTOR_MAX_PWM_OVERRIDE ); + BOOL result = f32Override( message, &airTrapAirPumpRaisePowerLevel ); return result; } @@ -643,7 +646,7 @@ *************************************************************************/ BOOL testAirPumpPowerLowerOverride( MESSAGE_T *message ) { - BOOL result = u32Override( message, &airTrapAirPumpLowerPowerLevel, AIR_PUMP_MOTOR_OFF, AIR_PUMP_MOTOR_MAX_PWM_OVERRIDE ); + BOOL result = f32Override( message, &airTrapAirPumpLowerPowerLevel ); return result; }