Index: firmware/App/Controllers/Fans.c =================================================================== diff -u -r44222e803e04d057ab793ce6b72902b8bfe9b7d0 -rcc8b9ddb9905161ddb0dc2af6bfbf863408669c8 --- firmware/App/Controllers/Fans.c (.../Fans.c) (revision 44222e803e04d057ab793ce6b72902b8bfe9b7d0) +++ firmware/App/Controllers/Fans.c (.../Fans.c) (revision cc8b9ddb9905161ddb0dc2af6bfbf863408669c8) @@ -67,7 +67,7 @@ /// Fans status struct typedef struct { - F32 dutyCycle; ///< Fans duty cycle that was fed to the fans. + OVERRIDE_F32_T dutyCycle; ///< Fans duty cycle that was fed to the fans. F32 targetRPM; ///< Fans target RPM. OVERRIDE_F32_T rpm[ NUM_OF_FANS_NAMES ]; ///< Fan's current tachometers reading in RPM. } FAN_STATUS_T; @@ -128,7 +128,10 @@ // Initialize the fans for ( fan = FAN_INLET_1; fan < NUM_OF_FANS_NAMES; fan++ ) { - fansStatus.dutyCycle = 0.0; + fansStatus.dutyCycle.data = 0.0; + fansStatus.dutyCycle.ovData = 0.0; + fansStatus.dutyCycle.ovInitData = 0.0; + fansStatus.dutyCycle.override = OVERRIDE_RESET; fansStatus.targetRPM = 0.0; fansStatus.rpm[ fan ].data = 0.0; fansStatus.rpm[ fan ].ovData = 0.0; @@ -266,8 +269,9 @@ { FANS_EXEC_STATES_T state = FANS_EXEC_STATE_RUN_STATE; - // Check if it is time to check for the control - if ( ++fansControlCounter > FANS_CONTROL_INTERVAL ) + // Check if it is time to check for the control and the duty cycle override is in the reset mode so the duty cycle + // is not overridden + if ( ( ++fansControlCounter > FANS_CONTROL_INTERVAL ) && ( OVERRIDE_RESET == fansStatus.dutyCycle.override ) ) { // Get the maximum temperature among all the thermistors and temperature sensors to run fan from the hottest temperature F32 temperature = getMaximumTemperature(); @@ -287,44 +291,50 @@ // If the fans calculated duty cycle is greater than the previous calculated duty cycle, we are ramping up // otherwise, we are ramping down - if ( dutyCycle >= fansStatus.dutyCycle ) + if ( dutyCycle >= fansStatus.dutyCycle.data ) { // If the delta duty cycle from the previous duty cycle is greater than the max allowed ramp up duty cycle, // otherwise, only add the delta duty cycle - if ( ( dutyCycle - fansStatus.dutyCycle ) >= FANS_MAX_ALLOWED_RAMP_UP_DELTA_DUTY_CYCLE ) + if ( ( dutyCycle - fansStatus.dutyCycle.data ) >= FANS_MAX_ALLOWED_RAMP_UP_DELTA_DUTY_CYCLE ) { - fansStatus.dutyCycle += FANS_MAX_ALLOWED_RAMP_UP_DELTA_DUTY_CYCLE; + fansStatus.dutyCycle.data += FANS_MAX_ALLOWED_RAMP_UP_DELTA_DUTY_CYCLE; } else { - fansStatus.dutyCycle = dutyCycle; + fansStatus.dutyCycle.data = dutyCycle; } } else { // If the delta duty cycle from the previous duty cycle is greater than the max allowed ramp down duty cycle, // otherwise, only add the delta duty cycle - if ( ( fansStatus.dutyCycle - dutyCycle ) >= FANS_MAX_ALLOWED_RAMP_DOWN_DELTA_DUTY_CYCLE ) + if ( ( fansStatus.dutyCycle.data - dutyCycle ) >= FANS_MAX_ALLOWED_RAMP_DOWN_DELTA_DUTY_CYCLE ) { // If we are ramping down, set the target duty cycle to max allowed ramp down duty cycle - fansStatus.dutyCycle -= FANS_MAX_ALLOWED_RAMP_DOWN_DELTA_DUTY_CYCLE; + fansStatus.dutyCycle.data -= FANS_MAX_ALLOWED_RAMP_DOWN_DELTA_DUTY_CYCLE; } else { - fansStatus.dutyCycle = dutyCycle; + fansStatus.dutyCycle.data = dutyCycle; } } // Calculate the target RPM for the the duty cycle - fansStatus.targetRPM = fansStatus.dutyCycle * FANS_MAX_ALLOWED_RPM; + fansStatus.targetRPM = fansStatus.dutyCycle.data * FANS_MAX_ALLOWED_RPM; // Set the PWM to inlet and outlet fans - setInletFansDutyCycle( fansStatus.dutyCycle ); - setOutletFansDutyCycle( fansStatus.dutyCycle ); + setInletFansDutyCycle( fansStatus.dutyCycle.data ); + setOutletFansDutyCycle( fansStatus.dutyCycle.data ); // Reset the counter fansControlCounter = 0; } + else if ( OVERRIDE_KEY == fansStatus.dutyCycle.override ) + { + // Set the PWM to inlet and outlet fans + setInletFansDutyCycle( fansStatus.dutyCycle.ovData ); + setOutletFansDutyCycle( fansStatus.dutyCycle.ovData ); + } return state; } @@ -449,7 +459,8 @@ // The RPM is expected to be 5500 @ 100% duty cycle // The nominal RPM = duty cycle * 5500 / 1.0 // The RPM tolerance is -25% to +50% of the nominal RPM - F32 fansNominalRPM = fansStatus.dutyCycle * FANS_MAX_ALLOWED_RPM; + F32 dutyCycle = ( OVERRIDE_RESET == fansStatus.dutyCycle.override ? fansStatus.dutyCycle.data : fansStatus.dutyCycle.ovData ); + F32 fansNominalRPM = dutyCycle * FANS_MAX_ALLOWED_RPM; F32 fansMinAllowedRPM = fansNominalRPM - ( fansNominalRPM * FANS_MIN_RPM_OUT_OF_RANGE_TOL ); F32 fansMaxAllowedRPM = fansNominalRPM + ( fansNominalRPM * FANS_MAX_RPM_OUT_OF_RANGE_TOL ); @@ -518,7 +529,7 @@ { FANS_DATA_T fansData; - fansData.dutyCycle = fansStatus.dutyCycle * FRACTION_TO_PERCENT_FACTOR; + fansData.dutyCycle = ( OVERRIDE_RESET == fansStatus.dutyCycle.override ? fansStatus.dutyCycle.data : fansStatus.dutyCycle.ovData ) * FRACTION_TO_PERCENT_FACTOR; fansData.targetFansRPM = fansStatus.targetRPM; fansData.fanInlet1RPM = getMeasuredFanRPM( FAN_INLET_1 ); fansData.fanInlet2RPM = getMeasuredFanRPM( FAN_INLET_2 ); @@ -687,4 +698,53 @@ return result; } +/*********************************************************************//** + * @brief + * The testSetFansDutyCycleOverride function overrides fans duty cycle + * @details Inputs: none + * @details Outputs: fansStatus + * @param value the duty cycle value to be overridden + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testSetFansDutyCycleOverride( F32 value ) +{ + BOOL result = FALSE; + + if ( TRUE == isTestingActivated() ) + { + if( ( value >= FANS_MIN_DUTY_CYCLE ) && ( value <= FANS_MAX_DUTY_CYCLE ) ) + { + fansStatus.dutyCycle.ovData = value; + fansStatus.dutyCycle.override = OVERRIDE_KEY; + + result = TRUE; + } + } + + return result; +} + +/*********************************************************************//** + * @brief + * The testResetFansDutyCycleOverride function resets the fans duty cycle + * override + * @details Inputs: none + * @details Outputs: fansStatus + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testResetFansDutyCycleOverride( void ) +{ + BOOL result = FALSE; + + if ( TRUE == isTestingActivated() ) + { + fansStatus.dutyCycle.override = OVERRIDE_RESET; + fansStatus.dutyCycle.ovData = 0.0; + + result = TRUE; + } + + return result; +} + /**@}*/