Index: firmware/App/Drivers/FluidPump.c =================================================================== diff -u -r046bc2b62cf942b7e846fa5bff698b94238edf24 -r60693bf21a8a0277eae54cbfcb6cfd68176b079a --- firmware/App/Drivers/FluidPump.c (.../FluidPump.c) (revision 046bc2b62cf942b7e846fa5bff698b94238edf24) +++ firmware/App/Drivers/FluidPump.c (.../FluidPump.c) (revision 60693bf21a8a0277eae54cbfcb6cfd68176b079a) @@ -30,14 +30,17 @@ // ********** private definitions ********** -#define FLUID_PUMP_COUNTS_2_RPM_NUMERATOR 1500000.0F ///< Numerator in counts to RPM conversion. -#define FLUID_PUMP_COUNTS_FOR_STOPPED_PUMP 0xFFFF ///< FPGA will report FFFF counts when pump is stopped. +#define FLUID_PUMP_P12_COUNTS_2_RPM_NUMERATOR 1500000.0F ///< Numerator in counts to RPM conversion. +#define FLUID_PUMP_COUNTS_FOR_STOPPED_PUMP 0xFFFF ///< FPGA will report FFFF counts when pump is stopped. +#define US_IN_SECONDS ( 1 / US_PER_SECOND ) ///< One micro second in relation to 1 second +#define TEN_US_IN_SECONDS ( 10 * US_IN_SECONDS ) ///< 10 micro seconds in relation to 1 second. +#define FLUID_PUMP_P40_COUNTS_2_RPM_NUMERATOR 30 ///< Fixed known value for RPM conversion with P40. /// Payload record structure for fluid pump set PWM request typedef struct { U32 pumpID; ///< Pump ID - U32 pwm; ///< Pump PWM magnitude (0..500). + U32 pwm; ///< Pump PWM magnitude. } FLUID_PUMP_CMD_PAYLOAD_T; // ********** private data ********** @@ -90,7 +93,8 @@ *************************************************************************/ void readFluidPumps( void ) { - U32 tach; + U32 p12Tach; + U16 p40RPMCnts; U32 pump; for ( pump = 0; pump < NUM_OF_PUMPS; pump++ ) @@ -100,22 +104,31 @@ if ( P12_PUMP == pump ) { fluidPumpReadDutyCycle[ pump ].data = getFPGAP12PumpPWM(); - tach = (U32)getFPGAP12PumpTachCount(); + p12Tach = (U32)getFPGAP12PumpTachCount(); + + if ( ( p12Tach != 0 ) && ( p12Tach < FLUID_PUMP_COUNTS_FOR_STOPPED_PUMP ) ) + { + fluidPumpMeasRPM[ pump ].data = FLUID_PUMP_P12_COUNTS_2_RPM_NUMERATOR / (F32)p12Tach; + } + else + { + fluidPumpMeasRPM[ pump ].data = 0.0F; + } } else { fluidPumpReadDutyCycle[ pump ].data = getFPGAP40PumpPWM(); - tach = (U32)getFPGAP40PumpTachCount(); + p40RPMCnts = (U32)getFPGAP40PumpRPMCount(); + if ( ( p40RPMCnts != 0 ) ) + { + fluidPumpMeasRPM[ pump ].data = FLUID_PUMP_P40_COUNTS_2_RPM_NUMERATOR / ((F32)( p40RPMCnts * TEN_US_IN_SECONDS )); + } + else + { + fluidPumpMeasRPM[ pump ].data = 0.0F; + } } - if ( ( tach != 0 ) && ( tach < FLUID_PUMP_COUNTS_FOR_STOPPED_PUMP ) ) - { - fluidPumpMeasRPM[ pump ].data = FLUID_PUMP_COUNTS_2_RPM_NUMERATOR / (F32)tach; - } - else - { - fluidPumpMeasRPM[ pump ].data = 0.0F; - } } } @@ -137,7 +150,7 @@ if ( pumpID < NUM_OF_PUMPS ) { - pwmCnt = convertDutyCyclePctToCnt( dutyCyclePct ); + pwmCnt = convertDutyCyclePctToCnt( pumpID, dutyCyclePct ); result = setFluidPumpPWMDutyCycle(pumpID, pwmCnt); } else @@ -150,13 +163,13 @@ /*********************************************************************//** * @brief - * The setFluidPumpPWMDutyCycle function sets the commanded PWM magnitude (0..500) + * The setFluidPumpPWMDutyCycle function sets the commanded PWM magnitude * for the given fluid pump. * @details \b Alarm: ALARM_ID_RO_SOFTWARE_FAULT if invalid fluid pump ID given. * @details \b Inputs: none * @details \b Outputs: fluidPumpCmdDutyCycle[] * @param pumpID ID of fluid pump to set commanded PWM magnitude for. - * @param pwm Value (0..500) indicating magnitude of PWM duty cycle to set + * @param pwm Value indicating magnitude of PWM duty cycle to set. (0..500) for P12_PUMP (0..5000) for P40. * @return TRUE if duty cycle set successfully, FALSE if not *************************************************************************/ BOOL setFluidPumpPWMDutyCycle( FP_FLUID_PUMP_T pumpID, U16 pwm ) @@ -189,16 +202,17 @@ } } - // constrain given pwm magnitude to valid range - pwm = MIN( pwm, MAX_FLUID_PUMP_PWM_DUTY_CYCLE ); - // set commanded duty cycle for given fluid pump to given pwm magnitude - fluidPumpCmdDutyCycle[ pumpID ] = pwm; + // set commanded duty cycle for given fluid pump to given pwm magnitude. if ( P12_PUMP == pumpID ) { + // constrain given pwm magnitude to valid range + pwm = MIN( pwm, MAX_P12_FLUID_PUMP_PWM_DUTY_CYCLE ); setFPGAP12PumpPWM( pwm ); } else { + // constrain given pwm magnitude to valid range + pwm = MIN( pwm, MAX_P40_FLUID_PUMP_PWM_DUTY_CYCLE ); setFPGAP40PumpPWM( pwm ); } result = TRUE; @@ -213,13 +227,13 @@ /*********************************************************************//** * @brief - * The getFluidPumpPWMDutyCycle function gets the commanded PWM magnitude (0..500) + * The getFluidPumpPWMDutyCycle function gets the commanded PWM magnitude * for the given fluid pump. * @details \b Alarm: ALARM_ID_RO_SOFTWARE_FAULT if invalid fluid pump ID given. * @details \b Inputs: fluidPumpCmdDutyCycle[] * @details \b Outputs: none * @param pumpID ID of fluid pump to get commanded PWM magnitude for. - * @return Value (0..500) indicating magnitude of PWM duty cycle + * @return Value indicating magnitude of PWM duty cycle. (0..500) for P12_PUMP (0..5000) for P40. *************************************************************************/ U16 getFluidPumpPWMDutyCycle( FP_FLUID_PUMP_T pumpID ) { @@ -239,13 +253,13 @@ /*********************************************************************//** * @brief - * The getFluidPumpReadPWMDutyCycle function gets the PWM magnitude (0..500) + * The getFluidPumpReadPWMDutyCycle function gets the PWM magnitude * read back from FPGA for the given fluid pump. * @details \b Alarm: ALARM_ID_RO_SOFTWARE_FAULT if invalid fluid pump ID given. * @details \b Inputs: fluidPumpReadDutyCycle[] * @details \b Outputs: none * @param pumpID ID of fluid pump to get read back PWM magnitude for. - * @return Value (0..500) indicating magnitude of PWM duty cycle + * @return Value indicating magnitude of PWM duty cycle. (0..500) for P12_PUMP (0..5000) for P40. *************************************************************************/ U16 getFluidPumpReadPWMDutyCycle( FP_FLUID_PUMP_T pumpID ) { @@ -296,12 +310,28 @@ * @details Inputs: none * @details Outputs: none * @param dutyCyclePct duty cycle percentage to be converted. - * @return Value (0..500) indicating magnitude of PWM duty cycle. + * @return Value indicating magnitude of PWM duty cycle. (0..500) for P12_PUMP (0..5000) for P40. *************************************************************************/ -U16 convertDutyCyclePctToCnt( F32 dutyCyclePct ) +U16 convertDutyCyclePctToCnt( FP_FLUID_PUMP_T pumpID, F32 dutyCyclePct ) { - U16 pwmCnt = (U16)MAX( (MAX_FLUID_PUMP_PWM_DUTY_CYCLE * dutyCyclePct) , MIN_FLUID_PUMP_PWM_DUTY_CYCLE ); + U16 pwmCnt = 0; + if ( pumpID < NUM_OF_PUMPS ) + { + if ( P12_PUMP == pumpID ) + { + pwmCnt = (U16)MAX( (MAX_P12_FLUID_PUMP_PWM_DUTY_CYCLE * dutyCyclePct) , MIN_FLUID_PUMP_PWM_DUTY_CYCLE ); + } + else + { + pwmCnt = (U16)MAX( (MAX_P40_FLUID_PUMP_PWM_DUTY_CYCLE * dutyCyclePct) , MIN_FLUID_PUMP_PWM_DUTY_CYCLE ); + } + } + else + { + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_FP_SOFTWARE_FAULT, FP_FAULT_ID_INVALID_FLUID_PUMP_ID5, (U32)pumpID ) + } + return pwmCnt; } /*********************************************************************//** @@ -313,10 +343,25 @@ * @param dutyCyclePct duty cycle count to be converted. * @return Value (0..0.99) indicating magnitude of PWM duty cycle as a percentage. *************************************************************************/ -F32 convertDutyCycleCntToPct( U32 dutyCycleCnt ) +F32 convertDutyCycleCntToPct( FP_FLUID_PUMP_T pumpID, U32 dutyCycleCnt ) { - F32 pwmCnt = MAX( ( (F32)dutyCycleCnt / (F32)MAX_FLUID_PUMP_PWM_DUTY_CYCLE ) , (F32)MIN_FLUID_PUMP_PWM_DUTY_CYCLE ); + F32 pwmCnt = 0.0; + if ( pumpID < NUM_OF_PUMPS ) + { + if ( P12_PUMP == pumpID ) + { + pwmCnt = MAX( ( (F32)dutyCycleCnt / (F32)MAX_P12_FLUID_PUMP_PWM_DUTY_CYCLE ) , (F32)MIN_FLUID_PUMP_PWM_DUTY_CYCLE ); + } + else + { + pwmCnt = MAX( ( (F32)dutyCycleCnt / (F32)MAX_P40_FLUID_PUMP_PWM_DUTY_CYCLE ) , (F32)MIN_FLUID_PUMP_PWM_DUTY_CYCLE ); + } + } + else + { + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_FP_SOFTWARE_FAULT, FP_FAULT_ID_INVALID_FLUID_PUMP_ID6, (U32)pumpID ) + } return pwmCnt; } @@ -420,7 +465,7 @@ *************************************************************************/ BOOL testFluidPumpPWMOverride( MESSAGE_T *message ) { - BOOL result = u32ArrayOverride( message, &fluidPumpReadDutyCycle[0], NUM_OF_PUMPS - 1, 0, MAX_FLUID_PUMP_PWM_DUTY_CYCLE ); + BOOL result = u32ArrayOverride( message, &fluidPumpReadDutyCycle[0], NUM_OF_PUMPS - 1, 0, MAX_P40_FLUID_PUMP_PWM_DUTY_CYCLE ); return result; }