Index: firmware/App/Controllers/Fans.c =================================================================== diff -u -rec15e94e1e51aceeceedf7398d648a8f4830fada -rfeb93744f73bc0a3d58841bb02bd05c38357f35d --- firmware/App/Controllers/Fans.c (.../Fans.c) (revision ec15e94e1e51aceeceedf7398d648a8f4830fada) +++ firmware/App/Controllers/Fans.c (.../Fans.c) (revision feb93744f73bc0a3d58841bb02bd05c38357f35d) @@ -31,9 +31,10 @@ #define MIN_TARGET_RPM_IN_SELF_TEST 1000 ///< Fans min target RPM that they should be during POST. #define FANS_SELF_TEST_WAIT_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Fans self test wait time for the fans to get to RPM. #define FANS_SELF_TEST_TARGET_PWM 0.5 ///< Fans self test target PWM for testing the fans are running. -#define FANS_MAX_ALLOWED_RPM_OUT_OF_RANGE_COUNT ( ( 3 * MS_PER_SECOND ) / TASK_GENERAL_INTERVAL ) ///< Fans max allowed RPM out of range count. -#define FANS_MAX_ALLOWED_RPM 9000 ///< Fans max allowed RPM value. -#define FANS_MONITOR_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Fans monitor time interval in counts. +#define FANS_MAX_ALLOWED_RPM_OUT_OF_RANGE_INTERVAL ( 3 * MS_PER_SECOND ) ///< Fans max allowed RPM out of range time interval. +#define FANS_MAX_ALLOWED_RPM 5000 ///< Fans max allowed RPM value. +#define FANS_MIN_ALLOWED_RPM 150 ///< Fans max allowed RPM value. +#define FANS_MONITOR_INTERVAL_COUNT ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Fans monitor time interval in counts. /// Fans self test states typedef enum fans_Self_Test @@ -59,13 +60,13 @@ U32 rpm[ NUM_OF_FANS_NAMES ]; ///< Fan's current tachometers reading in RPM } FAN_STATUS_T; -static FAN_STATUS_T fansStatus; ///< Fans status -static SELF_TEST_STATUS_T fansSelfTestResult = SELF_TEST_STATUS_IN_PROGRESS; ///< Fans self test result -static FANS_SELF_TEST_STATES_T fansSelfTestState = FANS_SELF_TEST_START_STATE; ///< Fans self test state -static FANS_EXEC_STATES_T fansExecState = FANS_EXEC_STATE_WAIT_FOR_POST_STATE; ///< Fans exec state -static U32 fansControlCounter = 0; ///< Fans control interval counter -static U32 fansPublishCounter = 0; ///< Fans data publish interval counter -static U32 fansMonitorCounter = 0; ///< Fans monitor interval counter +static FAN_STATUS_T fansStatus; ///< Fans status. +static SELF_TEST_STATUS_T fansSelfTestResult = SELF_TEST_STATUS_IN_PROGRESS; ///< Fans self test result. +static FANS_SELF_TEST_STATES_T fansSelfTestState = FANS_SELF_TEST_START_STATE; ///< Fans self test state. +static FANS_EXEC_STATES_T fansExecState = FANS_EXEC_STATE_WAIT_FOR_POST_STATE; ///< Fans exec state. +static U32 fansControlCounter = 0; ///< Fans control interval counter. +static U32 fansPublishCounter = 0; ///< Fans data publish interval counter. +static U32 fansMonitorCounter = 0; ///< Fans monitor interval counter. /// Temperature to duty cycle conversion slope (duty cycle not in percent) static const F32 SLOPE = ( FANS_MAX_DUTY_CYCLE - FANS_MIN_DUTY_CYCLE ) / ( MAX_ALLOWED_AMBINET_TEMPERATURE - MIN_ALLOWED_AMBIENT_TEMPERATURE ); @@ -111,7 +112,7 @@ // Initialize a persistent alarm for fans RPM out of range initPersistentAlarm( PERSISTENT_ALARM_FANS_RPM_OUT_RANGE, ALARM_ID_DG_FAN_RPM_OUT_OF_RANGE, - TRUE, FANS_MAX_ALLOWED_RPM_OUT_OF_RANGE_COUNT, FANS_MAX_ALLOWED_RPM_OUT_OF_RANGE_COUNT ); + TRUE, FANS_MAX_ALLOWED_RPM_OUT_OF_RANGE_INTERVAL, FANS_MAX_ALLOWED_RPM_OUT_OF_RANGE_INTERVAL ); } /*********************************************************************//** @@ -207,45 +208,19 @@ * @brief * The handleSelfTestStart function handles the start state of the fans' * self test. - * @details Inputs: fansStatus + * @details Inputs: none * @details Outputs: none * @return next state of self test *************************************************************************/ static FANS_SELF_TEST_STATES_T handleSelfTestStart( void ) { - FANS_SELF_TEST_STATES_T state; - U32 failureCount = 0; - FAN_NAMES_T fan; + FANS_SELF_TEST_STATES_T state = FANS_SELF_TEST_CHECK_RPM_STATE; - // Get the raw toggle periods from FPGA and convert them to RPM. They all should be 0 upon staring - // the device - convertTogglePeriod2RPM(); + // Set the fans to the target PWM for the next stage + setInletFansDutyCycle( FANS_SELF_TEST_TARGET_PWM ); + setOutletFansDutyCycle( FANS_SELF_TEST_TARGET_PWM ); + state = FANS_SELF_TEST_CHECK_RPM_STATE; - // Loop through all the fans to check their RPM - // Upon starting the device the RPM of the fans should be 0 - for( fan = FAN_INLET_1; fan < NUM_OF_FANS_NAMES; fan++ ) - { - if ( fansStatus.rpm[ fan ] > 0 ) - { - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_FAN_RPM_OUT_OF_RANGE, fan, fansStatus.rpm[ fan ] ); - failureCount++; - } - } - - // If there was a failure, go to complete - if ( failureCount > 0 ) - { - fansSelfTestResult = SELF_TEST_STATUS_FAILED; - state = FAN_SELF_TEST_COMPLETE_STATE; - } - else - { - // Set the fans to the target PWM for the next stage - setInletFansDutyCycle( FANS_SELF_TEST_TARGET_PWM ); - setOutletFansDutyCycle( FANS_SELF_TEST_TARGET_PWM ); - state = FANS_SELF_TEST_CHECK_RPM_STATE; - } - return state; } @@ -344,7 +319,7 @@ //TODO REMOVE FOR TESTING only // Solve the linear equation to calculate the duty cycle from temperature - F32 dutyCycle = SLOPE * ( temperature - MIN_ALLOWED_AMBIENT_TEMPERATURE ) + FANS_MIN_DUTY_CYCLE; + F32 dutyCycle = ( SLOPE * ( temperature - MIN_ALLOWED_AMBIENT_TEMPERATURE ) ) + FANS_MIN_DUTY_CYCLE; // Check whether the duty cycle is not outside of the range and cap it if needed if ( dutyCycle < FANS_MIN_DUTY_CYCLE ) @@ -373,8 +348,17 @@ } else { - // If we are ramping down, set the target duty cycle to max allowed ramp down PWM - fansStatus.targetDutyCycle -= FANS_MAX_ALLOWED_RAMP_DOWN_DELTA_DUTY_CYCLE; + // 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.targetDutyCycle - 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.targetDutyCycle -= FANS_MAX_ALLOWED_RAMP_DOWN_DELTA_DUTY_CYCLE; + } + else + { + fansStatus.targetDutyCycle = dutyCycle; + } } // Set the PWM to inlet and outlet fans @@ -492,17 +476,21 @@ { FAN_NAMES_T fan; - if ( ++fansMonitorCounter >= FANS_MONITOR_INTERVAL ) + if ( ++fansMonitorCounter >= FANS_MONITOR_INTERVAL_COUNT ) { convertTogglePeriod2RPM(); for ( fan = FAN_INLET_1; fan < NUM_OF_FANS_NAMES; fan++ ) { // Call persistent alarm if a fan's RPM is out of range - if ( fansStatus.rpm[ fan ] >= FANS_MAX_ALLOWED_RPM || fansStatus.rpm[ fan ] <= NEARLY_ZERO ) + if ( fansStatus.rpm[ fan ] >= FANS_MAX_ALLOWED_RPM ) { - checkPersistentAlarm( PERSISTENT_ALARM_FANS_RPM_OUT_RANGE, TRUE, fansStatus.rpm[ fan ] ); + checkPersistentAlarm( PERSISTENT_ALARM_FANS_RPM_OUT_RANGE, TRUE, fansStatus.rpm[ fan ], FANS_MAX_ALLOWED_RPM ); } + else if ( fansStatus.rpm[ fan ] <= FANS_MIN_ALLOWED_RPM ) + { + checkPersistentAlarm( PERSISTENT_ALARM_FANS_RPM_OUT_RANGE, TRUE, fansStatus.rpm[ fan ], FANS_MIN_ALLOWED_RPM ); + } } fansMonitorCounter = 0;