Index: firmware/App/Controllers/Fans.c =================================================================== diff -u -r58129c9bb3053c39efa07f60e975f17e2a04755a -rf9b3862d01ce6c64bd05b8649e69b44fa155b8e0 --- firmware/App/Controllers/Fans.c (.../Fans.c) (revision 58129c9bb3053c39efa07f60e975f17e2a04755a) +++ firmware/App/Controllers/Fans.c (.../Fans.c) (revision f9b3862d01ce6c64bd05b8649e69b44fa155b8e0) @@ -20,9 +20,9 @@ #define FANS_MAX_ALLOWED_RAMP_UP_DELTA_DUTY_CYCLE 0.3 ///< Fans max allowed ramp up PWM change. #define FANS_MAX_ALLOWED_RAMP_DOWN_DELTA_DUTY_CYCLE 0.005 ///< Fans min allowed ramp down PWM change. -#define ONE_MINUTE_TO_MICRO_SECONDS ( SEC_PER_MIN * US_PER_SECOND ) ///< One minute to micro seconds conversion. -#define TOGGLE_PERIOD_RESOLUTION 2.5 ///< FPGA fans toggle period resolution in micro seconds. -#define ROTATIONAL_TO_TOGGLE_PERIOD_CONVERSION_COEFF 4 ///< FPGA rotational to toggle period conversion coefficient. +//#define ONE_MINUTE_TO_MICRO_SECONDS ( SEC_PER_MIN * US_PER_SECOND ) ///< One minute to micro seconds conversion. +#define TOGGLE_PERIOD_RESOLUTION_SECONDS 0.0000025 ///< FPGA fans toggle period resolution in micro seconds. +#define ROTATIONAL_TO_TOGGLE_PERIOD_CONVERSION 4 ///< FPGA rotational to toggle period conversion coefficient. #define FANS_DATA_PUBLISH_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Fans publish data time interval in counts. #define FANS_CONTROL_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Fans control time interval in counts. @@ -66,7 +66,7 @@ static const F32 slope = ( FANS_MAX_DUTY_CYCLE - FANS_MIN_DUTY_CYCLE ) / ( MAX_ALLOWED_AMBINET_TEMPERATURE - MIN_ALLOWED_AMBIENT_TEMPERATURE ); /// FGPA Toggle to RPM conversion coefficient -static const F32 toggle2RPMCoefficient = ( ONE_MINUTE_TO_MICRO_SECONDS * ROTATIONAL_TO_TOGGLE_PERIOD_CONVERSION_COEFF ) / TOGGLE_PERIOD_RESOLUTION; +static const F32 toggle2RPMCoefficient = SEC_PER_MIN / ( TOGGLE_PERIOD_RESOLUTION_SECONDS * ROTATIONAL_TO_TOGGLE_PERIOD_CONVERSION ); static OVERRIDE_U32_T fansPublishInterval = { FANS_DATA_PUBLISH_INTERVAL, FANS_DATA_PUBLISH_INTERVAL, 0, 0 }; ///< Fans publish time interval override @@ -76,8 +76,8 @@ static FANS_EXEC_STATES_T handleExecStateWaitForPOST( void ); static FANS_EXEC_STATES_T handleExecStateRun( void ); -static void setInletFansPWM( F32 pwm ); -static void setOutletFansPWM( F32 pwm ); +static void setInletFansDutyCycle( F32 pwm ); +static void setOutletFansDutyCycle( F32 pwm ); static F32 getMaximumTemperature( void ); static void convertFansTogglePeriod2RPM( void ); static U32 getPublishFansDataInterval( void ); @@ -160,6 +160,8 @@ break; } + convertFansTogglePeriod2RPM(); + publishFansData(); } @@ -206,6 +208,7 @@ convertFansTogglePeriod2RPM(); // 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 ) @@ -215,8 +218,8 @@ } // Set the fans to the target PWM for the next stage - setInletFansPWM( FANS_SELF_TEST_TARGET_PWM ); - setOutletFansPWM( FANS_SELF_TEST_TARGET_PWM ); + setInletFansDutyCycle( FANS_SELF_TEST_TARGET_PWM ); + setOutletFansDutyCycle( FANS_SELF_TEST_TARGET_PWM ); state = FANS_SELF_TEST_CHECK_RPM; return state; @@ -250,8 +253,8 @@ } // Turn off the fans, done with self test - setInletFansPWM( 0 ); - setOutletFansPWM( 0 ); + setInletFansDutyCycle( 0 ); + setOutletFansDutyCycle( 0 ); state = FAN_SELF_TEST_COMPLETE; } @@ -274,11 +277,14 @@ if ( fansSelfTestState == FAN_SELF_TEST_COMPLETE ) { // Start the fans with minimum PWM. The control will decide the next PWM automatically. - setInletFansPWM( FANS_MIN_DUTY_CYCLE ); - setOutletFansPWM( FANS_MIN_DUTY_CYCLE ); + setInletFansDutyCycle( FANS_MIN_DUTY_CYCLE ); + setOutletFansDutyCycle( FANS_MIN_DUTY_CYCLE ); state = FANS_EXEC_STATE_RUN; } + // TODO REMOVE + state = FANS_EXEC_STATE_RUN; + // TODO REMOVE return state; } @@ -300,6 +306,10 @@ // Get the maximum temperature among all the thermistors and sensors to run fan from the hottest F32 temperature = getMaximumTemperature(); + //TODO REMOVE FOR TESTING + temperature = getThermistorTemperatureValue( THERMISTOR_ONBOARD_NTC ); + //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; @@ -336,8 +346,8 @@ } // Set the PWM to inlet and outlet fans - setInletFansPWM( fansStatus.targetDutyCycle ); - setOutletFansPWM( fansStatus.targetDutyCycle ); + setInletFansDutyCycle( fansStatus.targetDutyCycle ); + setOutletFansDutyCycle( fansStatus.targetDutyCycle ); // Reset the counter fansControlCounter = 0; @@ -354,7 +364,7 @@ * @param PWM that will be set * @return none *************************************************************************/ -static void setInletFansPWM( F32 pwm ) +static void setInletFansDutyCycle( F32 pwm ) { etpwmSetCmpA( etpwmREG6, (U32)( (S32)( ( pwm * (F32)(etpwmREG6->TBPRD) ) + FLOAT_TO_INT_ROUNDUP_OFFSET ) ) ); } @@ -367,7 +377,7 @@ * @param PWM that will be set * @return none ************************************************************************/ -static void setOutletFansPWM( F32 pwm ) +static void setOutletFansDutyCycle( F32 pwm ) { etpwmSetCmpB( etpwmREG6, (U32)( (S32)( ( pwm * (F32)(etpwmREG6->TBPRD) ) + FLOAT_TO_INT_ROUNDUP_OFFSET ) ) ); } @@ -459,7 +469,8 @@ } else { - fansStatus.rpm[ fan ] = togglePeriod * toggle2RPMCoefficient; + // Convert toggle period to RPM + fansStatus.rpm[ fan ] = toggle2RPMCoefficient / togglePeriod; } } }