Index: firmware/App/Controllers/Heaters.c =================================================================== diff -u -r4fdc3246f14c8b3b04724d39803530f60b6caac8 -re0265b8fad80add7a5d54db11ecc72fd6b1665a8 --- firmware/App/Controllers/Heaters.c (.../Heaters.c) (revision 4fdc3246f14c8b3b04724d39803530f60b6caac8) +++ firmware/App/Controllers/Heaters.c (.../Heaters.c) (revision e0265b8fad80add7a5d54db11ecc72fd6b1665a8) @@ -24,15 +24,10 @@ #include "ROPump.h" #include "PIControllers.h" #include "SystemCommMessages.h" -#include "TaskGeneral.h" +#include "TaskPriority.h" #include "TemperatureSensors.h" #include "Timers.h" -#ifdef ENABLE_DIP_SWITCHES -#include "mibspi.h" -#include "FPGA.h" -#endif - /** * @addtogroup Heaters * @{ @@ -54,7 +49,7 @@ #define CONTROLLER_CHECK_INTERVAL_COUNT 10U ///< Time interval count to check the PI controller. #define TEMP_SENSORS_INTERVAL_COUNT 10U ///< Temperature sensors interval count. -#define HEATERS_DATA_PUBLISH_INTERVAL (500 / TASK_GENERAL_INTERVAL ) ///< Heaters data publish interval. +#define HEATERS_DATA_PUBLISH_INTERVAL ( MS_PER_SECOND / ( 2 * TASK_PRIORITY_INTERVAL ) ) ///< Heaters data publish interval. #define SMALL_PRIMARY_AND_TRIMMER_HEATERS_POST_TARGET_TEMPERATURE 40U ///< Small primary and trimmer heaters target temperature during POST. #define MAIN_PRIMARY_HEATER_POST_TARGET_TEMPERATURE 35U ///< Main primary heater target temperature during POST. @@ -64,6 +59,8 @@ #define MINIMUM_TARGET_TEMPERATURE 10U ///< Minimum allowed target temperature for the heaters. #define MAXIMUM_TARGET_TEMPERATURE 90U ///< Maximum allowed target temperature for the heaters. +#define HEATERS_ON_WITH_NO_FLOW_TIMEOUT_COUNT ( ( 3 * MS_PER_SECOND ) / TASK_PRIORITY_INTERVAL ) ///< Heaters are on but there is no sufficient flow timeout in counts. + /// Heaters self-test enums typedef enum heaters_self_test_states { @@ -122,6 +119,7 @@ static U32 selfTestElapsedTime; ///< Self-test elapsed time variable. static BOOL hasStartPrimaryHeaterRequested; ///< Start primary heater request flag. static BOOL hasStartTrimmerHeaterRequested; ///< Start trimmer heater request flag. +static U32 heatersOnWithNoFlowTimeOut; ///< Heaters are on but there is no sufficient flow. // ********** private function prototypes ********** @@ -140,13 +138,8 @@ static void setTrimmerHeaterPWM( F32 pwm ); static void resetHeaterState( NAME_OF_HEATER_T heater ); static void publishHeatersData( void ); -static U32 getPublishHeatersDataInterval( void ); +static U32 getPublishHeatersDataInterval( void ); -// TODO: Remove the below code. FOR TESTING ONLY -#define PRIMARY_HEATER_MIBSPI1_PORT_MASK 0x00000002 // (CS1 - re-purposed as input GPIO) -#define TOGGLEPRIMAYHEATER() ( ( mibspiREG1->PC2 & PRIMARY_HEATER_MIBSPI1_PORT_MASK ) != 0 ) -//TODO: Remove the above code. FOR TESTING ONLY - /*********************************************************************//** * @brief * The initHeaters function initializes the variables and the PI controllers @@ -284,23 +277,33 @@ /*********************************************************************//** * @brief - * The execHeatersMonitor function turns off the heaters when RO pump is not on. - * @details Inputs: none - * @details Outputs: Turns off the heaters when RO pump is not on + * The execHeatersMonitor function turns off the heaters when RO pump is + * not on. + * @details Inputs: none TODO update the doxygen header function + * @details Outputs: none * @return none *************************************************************************/ void execHeatersMonitor( void ) { - // If the RO pump is not on, turn off the heaters - if ( ! isReverseOsmosisPumpOn() ) + if ( isPrimaryHeaterOn || isTrimmerHeaterOn ) { -#ifndef ENABLE_DIP_SWITCHES -#ifndef EMC_TEST_BUILD - stopPrimaryHeater(); // TODO - this is so immediate - if other module requests RO pump on and start heater, this monitor may stop the heater request before RO pump has a chance to start - stopTrimmerHeater(); -#endif -#endif + // If the RO pump is not on, turn off the heaters + if ( isReverseOsmosisPumpOn() && getMeasuredROFlowRate() < MIN_RO_FLOWRATE_LPM ) + { + if ( ++heatersOnWithNoFlowTimeOut > HEATERS_ON_WITH_NO_FLOW_TIMEOUT_COUNT ) + { + stopPrimaryHeater(); // TODO - this is so immediate - if other module requests RO pump on and start heater, this monitor may stop the heater request before RO pump has a chance to start + stopTrimmerHeater(); + + heatersOnWithNoFlowTimeOut = 0; + } + } } + + //TODO add code to remember the former state of the heaters and if they were on, turn them on again + + // Check for data publication + publishHeatersData(); } /*********************************************************************//** @@ -505,26 +508,6 @@ { PRIMARY_HEATERS_EXEC_STATES_T state = PRIMARY_HEATERS_EXEC_STATE_OFF; - // TODO for testing only. remove -#ifdef DEBUG_ENABLED -#ifdef ENABLE_DIP_SWITCHES -#ifndef EMC_TEST_BUILD - if ( TOGGLEPRIMAYHEATER() ) - { - setPrimaryHeaterTargetTemperature( 37 ); - startPrimaryHeater(); - F32 pumpPWM = 1; - etpwmSetCmpB( etpwmREG2, (U32)( (S32)( ( pumpPWM * (F32)(etpwmREG2->TBPRD) ) + FLOAT_TO_INT_ROUNDUP_OFFSET ) ) ); - F32 fanPWM = 0.25; - etpwmSetCmpA( etpwmREG6, (U32)( (S32)( ( fanPWM * (F32)(etpwmREG6->TBPRD) ) + FLOAT_TO_INT_ROUNDUP_OFFSET ) ) ); - etpwmSetCmpB( etpwmREG6, (U32)( (S32)( ( fanPWM * (F32)(etpwmREG6->TBPRD) ) + FLOAT_TO_INT_ROUNDUP_OFFSET ) ) ); - hasStartPrimaryHeaterRequested = TRUE; - } -#endif -#endif -#endif - // TODO remove this code for testing - if ( hasStartPrimaryHeaterRequested ) { resetHeaterState( PRIMARY_HEATER ); @@ -534,8 +517,6 @@ state = PRIMARY_HEATERS_EXEC_STATE_CONTROL_TO_TARGET; } - publishHeatersData(); - return state; } @@ -577,26 +558,6 @@ primaryHeaterTimerCounter = 0; } - publishHeatersData(); - - // TODO remove this code -#ifdef DEBUG_ENABLED -#ifdef ENABLE_DIP_SWITCHES -#ifndef EMC_TEST_BUILD - if ( !TOGGLEPRIMAYHEATER() ) - { - stopPrimaryHeater(); - F32 pumpPWM = 0; - etpwmSetCmpB( etpwmREG2, (U32)( (S32)( ( pumpPWM * (F32)(etpwmREG2->TBPRD) ) + FLOAT_TO_INT_ROUNDUP_OFFSET ) ) ); - F32 fanPWM = 0; - etpwmSetCmpA( etpwmREG6, (U32)( (S32)( ( fanPWM * (F32)(etpwmREG6->TBPRD) ) + FLOAT_TO_INT_ROUNDUP_OFFSET ) ) ); - etpwmSetCmpB( etpwmREG6, (U32)( (S32)( ( fanPWM * (F32)(etpwmREG6->TBPRD) ) + FLOAT_TO_INT_ROUNDUP_OFFSET ) ) ); - } -#endif -#endif -#endif - // TODO Remove this code - if ( ! isPrimaryHeaterOn ) { state = PRIMARY_HEATERS_EXEC_STATE_OFF; @@ -617,29 +578,6 @@ { TRIMMER_HEATER_EXEC_STATES_T state = TRIMMER_HEATER_EXEC_STATE_OFF; - // TODO for testing only. remove -#ifdef DEBUG_ENABLED -#ifdef ENABLE_DIP_SWITCHES -#ifndef EMC_TEST_BUILD -// if ( TOGGLEPRIMAYHEATER() ) -// { - //setTrimmerHeaterTargetTemperature( 38 ); - //startTrimmerHeater(); - //F32 pumpPWM = 1; - //etpwmSetCmpB( etpwmREG2, (U32)( (S32)( ( pumpPWM * (F32)(etpwmREG2->TBPRD) ) + FLOAT_TO_INT_ROUNDUP_OFFSET ) ) ); - //temporaryStartROPump(); - //temporaryStartFan(); - //F32 fanPWM = 0.25; - //etpwmSetCmpA( etpwmREG6, (U32)( (S32)( ( fanPWM * (F32)(etpwmREG6->TBPRD) ) + FLOAT_TO_INT_ROUNDUP_OFFSET ) ) ); - //etpwmSetCmpB( etpwmREG6, (U32)( (S32)( ( fanPWM * (F32)(etpwmREG6->TBPRD) ) + FLOAT_TO_INT_ROUNDUP_OFFSET ) ) ); - //temporaryStartROPump(); - //temporaryStartFan(); -// } -#endif -#endif -#endif - // TODO remove this code for testing - if ( hasStartTrimmerHeaterRequested ) { resetHeaterState( TRIMMER_HEATER ); @@ -649,8 +587,6 @@ state = TRIMMER_HEATER_EXEC_STATE_CONTROL_TO_TARGET; } - publishHeatersData(); - return state; } @@ -674,30 +610,6 @@ trimmerHeaterTimerCounter = 0; } - publishHeatersData(); - - // TODO remove this code -#ifdef DEBUG_ENABLED -#ifdef ENABLE_DIP_SWITCHES -#ifndef EMC_TEST_BUILD -// if ( !TOGGLEPRIMAYHEATER() ) -// { - //stopTrimmerHeater(); - //F32 pumpPWM = 0; - //etpwmSetCmpB( etpwmREG2, (U32)( (S32)( ( pumpPWM * (F32)(etpwmREG2->TBPRD) ) + FLOAT_TO_INT_ROUNDUP_OFFSET ) ) ); - //temporaryStartROPump(); - //temporaryStartFan(); - //F32 fanPWM = 0; - //etpwmSetCmpA( etpwmREG6, (U32)( (S32)( ( fanPWM * (F32)(etpwmREG6->TBPRD) ) + FLOAT_TO_INT_ROUNDUP_OFFSET ) ) ); - //etpwmSetCmpB( etpwmREG6, (U32)( (S32)( ( fanPWM * (F32)(etpwmREG6->TBPRD) ) + FLOAT_TO_INT_ROUNDUP_OFFSET ) ) ); - //temporaryStopROPump(); - //temporaryStopFan(); -// } -#endif -#endif -#endif - // TODO Remove this code - if ( ! isTrimmerHeaterOn ) { state = TRIMMER_HEATER_EXEC_STATE_OFF; @@ -788,23 +700,28 @@ /*********************************************************************//** * @brief - * The publishTemperatureData function publishes the temperature sensors - * data into the USB debug port at the defined time interval. + * The publishTemperatureData function publishes the heaters data into + * at the defined time interval. * @details Inputs: dataPublicationTimerCounter - * @details Outputs: Broadcast temperature sensors' data + * @details Outputs: dataPublicationTimerCounter * @return none *************************************************************************/ static void publishHeatersData( void ) { if ( ++dataPublicationTimerCounter >= getPublishHeatersDataInterval() ) { - broadcastHeatersData( (U32)(mainPrimaryHeaterDutyCycle*100), (U32)(smallPrimaryHeaterDutyCycle*100), (U32)(trimmerHeaterDutyCycle*100) ); + HEATERS_DATA_T data; + data.mainPrimaryDutyCyclePct = mainPrimaryHeaterDutyCycle * 100; + data.smallPrimaryDutyCyclePct = smallPrimaryHeaterDutyCycle * 100; + data.trimmerDutyCyclePct = trimmerHeaterDutyCycle * 100; + + broadcastHeatersData( &data ); + dataPublicationTimerCounter = 0; } } - /************************************************************************* * TEST SUPPORT FUNCTIONS *************************************************************************/ @@ -824,7 +741,7 @@ if ( isTestingActivated() ) { - U32 interval = value / TASK_GENERAL_INTERVAL; + U32 interval = value / TASK_PRIORITY_INTERVAL; result = TRUE; heatersDataPublishInterval.ovData = interval;