Index: firmware/App/Controllers/ROPump.c =================================================================== diff -u -rdc0d9b087c609e71cacdb7f0395cccf29d749c00 -r5a882c7292cea58e74b5a28d4e85dd60e741b834 --- firmware/App/Controllers/ROPump.c (.../ROPump.c) (revision dc0d9b087c609e71cacdb7f0395cccf29d749c00) +++ firmware/App/Controllers/ROPump.c (.../ROPump.c) (revision 5a882c7292cea58e74b5a28d4e85dd60e741b834) @@ -24,11 +24,11 @@ #include "OperationModes.h" #include "PIControllers.h" #include "Pressures.h" +#include "ROPump.h" #include "SystemCommMessages.h" #include "TaskGeneral.h" #include "TaskPriority.h" #include "Timers.h" -#include "ROPump.h" #ifdef EMC_TEST_BUILD #include "Heaters.h" #endif @@ -43,40 +43,40 @@ // ********** private definitions ********** -#define RO_PUMP_DATA_PUB_INTERVAL ( MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) ///< interval (ms/task time) at which the RO Pump data is published on the CAN bus +#define RO_PUMP_DATA_PUB_INTERVAL ( MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) ///< Interval (ms/task time) at which the RO Pump data is published on the CAN bus. -#define MAX_RO_PUMP_PWM_STEP_CHANGE 0.01 ///< max duty cycle change for controller -#define MAX_RO_PUMP_PWM_DUTY_CYCLE 0.99 ///< max duty cycle -#define MIN_RO_PUMP_PWM_DUTY_CYCLE 0.00 ///< min duty cycle +#define MAX_RO_PUMP_PWM_STEP_CHANGE 0.01 ///< Max duty cycle change for controller. +#define MAX_RO_PUMP_PWM_DUTY_CYCLE 0.99 ///< Max duty cycle. +#define MIN_RO_PUMP_PWM_DUTY_CYCLE 0.00 ///< Min duty cycle. -#define ROP_CONTROL_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< interval (ms/task time) at which the RO pump is controlled -#define ROP_P_COEFFICIENT 0.0020 ///< P term for RO pump control -#define ROP_I_COEFFICIENT 0.0015 ///< I term for RO pump control +#define ROP_CONTROL_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the RO pump is controlled. +#define ROP_P_COEFFICIENT 0.0020 ///< P term for RO pump control. +#define ROP_I_COEFFICIENT 0.0015 ///< I term for RO pump control. -#define FLOW_SENSOR_ZERO_READING 0xFFFF ///< Flow sensor reading indicates zero flow (or flow lower than can be detected by sensor) +#define FLOW_SENSOR_ZERO_READING 0xFFFF ///< Flow sensor reading indicates zero flow (or flow lower than can be detected by sensor). #define FLOW_SAMPLES_TO_AVERAGE (250 / TASK_PRIORITY_INTERVAL) ///< Averaging flow data over 250 ms intervals. #define FLOW_AVERAGE_MULTIPLIER (1.0 / (F32)FLOW_SAMPLES_TO_AVERAGE) ///< Optimization - multiplying is faster than dividing. + +// TODO - this is a place holder for real conversion +#define ROP_PSI_TO_PWM_DC(p) ( 0.2 + ( (F32)((p) - 100) * 0.01 ) ) ///< conversion factor from target PSI to PWM duty cycle estimate. +#define RO_FLOW_ADC_TO_LPM_FACTOR 10909.0909 ///< conversion factor from ADC counts to LPM (liters/min) for RO flow rate (multiply this by inverse of FPGA reading). -#define ROP_PSI_TO_PWM_DC(p) ( 0.2 + ( (F32)((p) - 100) * 0.01 ) ) ///< conversion factor from target PSI to PWM duty cycle estimate TODO - this is a place holder for real conversion - -#define RO_FLOW_ADC_TO_LPM_FACTOR 10909.0909 ///< conversion factor from ADC counts to LPM (liters/min) for RO flow rate (multiply this by inverse of FPGA reading). - /// Enumeration of RO pump states. typedef enum ROPump_States { - RO_PUMP_OFF_STATE = 0, ///< RO pump off state. - RO_PUMP_CONTROL_TO_TARGET_STATE, ///< RO pump control to target pressure state. - NUM_OF_RO_PUMP_STATES ///< Number of RO pump states. + RO_PUMP_OFF_STATE = 0, ///< RO pump off state + RO_PUMP_CONTROL_TO_TARGET_STATE, ///< RO pump control to target pressure state + NUM_OF_RO_PUMP_STATES ///< Number of RO pump states } RO_PUMP_STATE_T; /// Enumeration of RO pump self test states. typedef enum ROPump_Self_Test_States { - RO_PUMP_SELF_TEST_STATE_START = 0, ///< RO pump self test start state. - RO_PUMP_TEST_STATE_IN_PROGRESS, ///< RO pump self tests in progress state. - RO_PUMP_TEST_STATE_COMPLETE, ///< RO pump self tests completed state. - NUM_OF_RO_PUMP_SELF_TEST_STATES ///< Number of RO pump self test states. + RO_PUMP_SELF_TEST_STATE_START = 0, ///< RO pump self test start state + RO_PUMP_TEST_STATE_IN_PROGRESS, ///< RO pump self tests in progress state + RO_PUMP_TEST_STATE_COMPLETE, ///< RO pump self tests completed state + NUM_OF_RO_PUMP_SELF_TEST_STATES ///< Number of RO pump self test states } RO_PUMP_SELF_TEST_STATE_T; // TODO - test code - remove later @@ -87,26 +87,27 @@ // ********** private data ********** -static RO_PUMP_STATE_T roPumpState = RO_PUMP_OFF_STATE; ///< current state of RO pump controller state machine -static U32 roPumpDataPublicationTimerCounter = 0; ///< used to schedule RO pump data publication to CAN bus -static BOOL isROPumpOn = FALSE; ///< RO pump is currently running -static F32 roPumpPWMDutyCyclePct = 0.0; ///< initial RO pump PWM duty cycle -static F32 roPumpPWMDutyCyclePctSet = 0.0; ///< currently set RO pump PWM duty cycle -static PUMP_CONTROL_MODE_T roPumpControlMode = PUMP_CONTROL_MODE_CLOSED_LOOP; ///< requested RO pump control mode. -static PUMP_CONTROL_MODE_T roPumpControlModeSet = PUMP_CONTROL_MODE_CLOSED_LOOP; ///< currently set RO pump control mode. +static RO_PUMP_STATE_T roPumpState = RO_PUMP_OFF_STATE; ///< Current state of RO pump controller state machine. +static U32 roPumpDataPublicationTimerCounter = 0; ///< RO pump data publication timer counter. +static BOOL isROPumpOn = FALSE; ///< RO pump is currently running. +static F32 roPumpPWMDutyCyclePct = 0.0; ///< Initial RO pump PWM duty cycle. +static F32 roPumpPWMDutyCyclePctSet = 0.0; ///< Currently set RO pump PWM duty cycle. +static PUMP_CONTROL_MODE_T roPumpControlMode = PUMP_CONTROL_MODE_CLOSED_LOOP; ///< Requested RO pump control mode. +static PUMP_CONTROL_MODE_T roPumpControlModeSet = PUMP_CONTROL_MODE_CLOSED_LOOP; ///< Currently set RO pump control mode. -static OVERRIDE_U32_T roPumpDataPublishInterval = { RO_PUMP_DATA_PUB_INTERVAL, RO_PUMP_DATA_PUB_INTERVAL, 0, 0 }; ///< interval (in ms) at which to publish RO flow data to CAN bus. -static OVERRIDE_U32_T targetROPumpPressure = { 0, 0, 0, 0 }; ///< Target RO pressure (in PSI). -static OVERRIDE_F32_T measuredROFlowRateLPM = { 0.0, 0.0, 0.0, 0 }; ///< measured RO flow rate (in LPM). -static F32 measuredROPumpPressure = 0.0; ///< measured RO pressure (in PSI). +static OVERRIDE_U32_T roPumpDataPublishInterval = { RO_PUMP_DATA_PUB_INTERVAL, + RO_PUMP_DATA_PUB_INTERVAL, 0, 0 }; ///< Interval (in ms) at which to publish RO flow data to CAN bus. +static OVERRIDE_U32_T targetROPumpPressure = { 0, 0, 0, 0 }; ///< Target RO pressure (in PSI). +static OVERRIDE_F32_T measuredROFlowRateLPM = { 0.0, 0.0, 0.0, 0 }; ///< Measured RO flow rate (in LPM). +static F32 measuredROPumpPressure = 0.0; ///< Measured RO pressure (in PSI). -static S32 measuredFlowReadingsSum = 0; ///< Raw flow reading sums for averaging. -static U32 flowFilterCounter = 0; ///< used to schedule flow filtering. +static S32 measuredFlowReadingsSum = 0; ///< Raw flow reading sums for averaging. +static U32 flowFilterCounter = 0; ///< Flow filtering counter. -static U32 roControlTimerCounter = 0; ///< determines when to perform control on ro pump +static U32 roControlTimerCounter = 0; ///< Timer counter for perform control on RO pump. -static RO_PUMP_SELF_TEST_STATE_T roPumpSelfTestState = RO_PUMP_SELF_TEST_STATE_START; ///< current ro pump self test state -static U32 roPumpSelfTestTimerCount = 0; ///< timer counter for ro pump self test +static RO_PUMP_SELF_TEST_STATE_T roPumpSelfTestState = RO_PUMP_SELF_TEST_STATE_START; ///< Current RO pump self test state. +static U32 roPumpSelfTestTimerCount = 0; ///< Timer counter for RO pump self test. // ********** private function prototypes ********** @@ -130,15 +131,13 @@ stopROPump(); // initialize RO pump PI controller - initializePIController( PI_CONTROLLER_ID_RO_PUMP, MIN_RO_PUMP_PWM_DUTY_CYCLE, - ROP_P_COEFFICIENT, ROP_I_COEFFICIENT, - MIN_RO_PUMP_PWM_DUTY_CYCLE, MAX_RO_PUMP_PWM_DUTY_CYCLE ); + initializePIController( PI_CONTROLLER_ID_RO_PUMP, MIN_RO_PUMP_PWM_DUTY_CYCLE, ROP_P_COEFFICIENT, + ROP_I_COEFFICIENT, MIN_RO_PUMP_PWM_DUTY_CYCLE, MAX_RO_PUMP_PWM_DUTY_CYCLE ); } /*********************************************************************//** * @brief - * The setROPumpTargetPressure function sets a new target pressure for the \n - * RO pump. + * The setROPumpTargetPressure function sets a new target pressure for the RO pump. * @details * Inputs : none * Outputs : targetROPumpPressure, roPumpPWMDutyCyclePct @@ -194,7 +193,7 @@ * @brief * The execROPumpMonitor function executes the RO Pump monitor. * @details - * Inputs : none + * Inputs : flowFilterCounter * Outputs : measuredROPumpPressure, measuredROFlowRateLPM * @return none *************************************************************************/ @@ -261,7 +260,7 @@ /*********************************************************************//** * @brief - * The isROPumpOn function returns the status of RO pump + * The isROPumpOn function returns the status of RO pump. * @details * Inputs : none * Outputs : none @@ -274,8 +273,8 @@ /*********************************************************************//** * @brief - * The handleROPumpOffState function handles the ro pump off state \n - * of the ro pump controller state machine. + * The handleROPumpOffState function handles the RO pump off state of the + * RO pump controller state machine. * @details * Inputs : targetROPumpPressure * Outputs : roPumpPWMDutyCyclePctSet, isROPumpOn @@ -328,8 +327,8 @@ /*********************************************************************//** * @brief - * The handleROPumpControlToTargetState function handles the "control to \n - * target" state of the ro pump controller state machine. + * The handleROPumpControlToTargetState function handles the "control to + * target" state of the RO pump controller state machine. * @details * Inputs : none * Outputs : roPumpState @@ -378,8 +377,8 @@ /*********************************************************************//** * @brief - * The setROPumpControlSignalPWM function sets the PWM duty cycle for \n - * the RO pump to a given %. + * The setROPumpControlSignalPWM function sets the PWM duty cycle for the + * RO pump to a given %. * @details * Inputs : none * Outputs : PWM duty cycle zeroed @@ -408,8 +407,7 @@ /*********************************************************************//** * @brief - * The getPublishROPumpDataInterval function gets the RO pump data \n - * publication interval. + * The getPublishROPumpDataInterval function gets the RO pump data publish interval. * @details * Inputs : roPumpDataPublishInterval * Outputs : none @@ -429,8 +427,7 @@ /*********************************************************************//** * @brief - * The getTargetROPumpPressure function gets the current target RO pump \n - * pressure. + * The getTargetROPumpPressure function gets the current target RO pump pressure. * @details * Inputs : targetROPumpPressure * Outputs : none @@ -450,8 +447,7 @@ /*********************************************************************//** * @brief - * The getMeasuredROFlowRate function gets the measured RO pump \n - * flow rate. + * The getMeasuredROFlowRate function gets the measured RO pump flow rate. * @details * Inputs : measuredROFlowRateLPM * Outputs : none @@ -471,8 +467,7 @@ /*********************************************************************//** * @brief - * The publishROPumpData function publishes RO pump data at the set \n - * interval. + * The publishROPumpData function publishes RO pump data at the set interval. * @details * Inputs : target pressure, measured pressure, measured RO pump speed. * Outputs : RO pump data is published to CAN bus. @@ -513,10 +508,9 @@ * TEST SUPPORT FUNCTIONS *************************************************************************/ - /*********************************************************************//** * @brief - * The testSetROPumpDataPublishIntervalOverride function overrides the \n + * The testSetROPumpDataPublishIntervalOverride function overrides the * RO pump data publish interval. * @details * Inputs : none @@ -542,7 +536,7 @@ /*********************************************************************//** * @brief - * The testResetROPumpDataPublishIntervalOverride function resets the override \n + * The testResetROPumpDataPublishIntervalOverride function resets the override * of the RO pump data publish interval. * @details * Inputs : none @@ -565,8 +559,8 @@ /*********************************************************************//** * @brief - * The testSetTargetROPumpPressureOverride function overrides the target \n - * RO pressure. \n + * The testSetTargetROPumpPressureOverride function overrides the target + * RO pressure. * @details * Inputs : none * Outputs : targetROPumpPressure @@ -590,7 +584,7 @@ /*********************************************************************//** * @brief - * The testResetTargetROPumpPressureOverride function resets the override of the \n + * The testResetTargetROPumpPressureOverride function resets the override of the * target RO pressure. * @details * Inputs : none @@ -615,7 +609,7 @@ /*********************************************************************//** * @brief - * The testSetMeasuredROFlowRateOverride function overrides the measured \n + * The testSetMeasuredROFlowRateOverride function overrides the measured * RO flow rate. * @details * Inputs : none @@ -639,7 +633,7 @@ /*********************************************************************//** * @brief - * The testResetMeasuredROFlowRateOverride function resets the override of the \n + * The testResetMeasuredROFlowRateOverride function resets the override of the * measured RO flow rate. * @details * Inputs : none