Index: firmware/App/Controllers/ROPump.c =================================================================== diff -u -r16dfbeeca1bcf1d2115c2f7549999fdaae0700e9 -r416a8fba5774e6cd64c69513e082afbd79f75ccf --- firmware/App/Controllers/ROPump.c (.../ROPump.c) (revision 16dfbeeca1bcf1d2115c2f7549999fdaae0700e9) +++ firmware/App/Controllers/ROPump.c (.../ROPump.c) (revision 416a8fba5774e6cd64c69513e082afbd79f75ccf) @@ -1,4 +1,4 @@ -/************************************************************************** +/**********************************************************************//** * * Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. * @@ -19,9 +19,9 @@ #endif #include "etpwm.h" +#include "mibspi.h" #include "FPGA.h" -//#include "InternalADC.h" #include "OperationModes.h" #include "PIControllers.h" #include "Pressures.h" @@ -31,6 +31,11 @@ #include "Timers.h" #include "ROPump.h" +/** + * @addtogroup ROPump + * @{ + */ + // ********** 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 @@ -39,11 +44,10 @@ #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 ( 1000 / TASK_GENERAL_INTERVAL ) ///< interval (ms/task time) at which the RO pump is controlled +#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.005 ///< P term for RO pump control #define ROP_I_COEFFICIENT 0.00015 ///< I term for RO pump control -#define ROP_SPEED_ADC_TO_RPM_FACTOR 1.0 ///< conversion factor from ADC counts to RPM for RO pump #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 0.00018 ///< conversion factor from ADC counts to LPM (liters/min) for RO flow rate. @@ -63,10 +67,16 @@ NUM_OF_RO_PUMP_SELF_TEST_STATES } RO_PUMP_SELF_TEST_STATE_T; +// TODO - test code - remove later +// pin assignments for pump test DIP switch 0 +#define RO_PUMP_TEST_SPI5_PORT_MASK 0x00000100 // (ENA - re-purposed as input GPIO) +// dialIn pump stop and direction macros +#define GET_DIP_SW0_TEST() ( ( mibspiREG5->PC2 & RO_PUMP_TEST_SPI5_PORT_MASK ) != 0 ) + // ********** private data ********** -static RO_PUMP_STATE_T roPumpState = RO_PUMP_OFF_STATE; ///< current state of RO flow controller state machine -static U32 roPumpDataPublicationTimerCounter = 0; ///< used to schedule RO flow data publication to CAN bus +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 @@ -78,7 +88,7 @@ static OVERRIDE_F32_T measuredROPumpPressure = { 0.0, 0.0, 0.0, 0 }; ///< measured RO pressure (in PSI). static OVERRIDE_F32_T measuredROFlowRateLPM = { 0.0, 0.0, 0.0, 0 }; ///< measured RO flow rate (in LPM). -static U32 roControlTimerCounter = 0; ///< determines when to perform control on ro flow +static U32 roControlTimerCounter = 0; ///< determines when to 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 @@ -92,7 +102,7 @@ static void publishROPumpData( void ); static DATA_GET_PROTOTYPE( U32, getPublishROPumpDataInterval ); -/************************************************************************* +/*********************************************************************//** * @brief initROPump * The initROPump function initializes the ROPump module. * @details @@ -111,10 +121,10 @@ MIN_RO_PUMP_PWM_DUTY_CYCLE, MAX_RO_PUMP_PWM_DUTY_CYCLE ); } -/************************************************************************* +/*********************************************************************//** * @brief - * The setROPumpTargetPressure function sets a new target pressure and - * pump direction. + * The setROPumpTargetPressure function sets a new target pressure for the \n + * RO pump. * @details * Inputs : none * Outputs : targetROPumpPressure, roPumpPWMDutyCyclePct @@ -144,7 +154,7 @@ return result; } -/************************************************************************* +/*********************************************************************//** * @brief * The signalROPumpHardStop function stops the RO pump immediately. * @details @@ -163,7 +173,7 @@ resetPIController( PI_CONTROLLER_ID_RO_PUMP, MIN_RO_PUMP_PWM_DUTY_CYCLE ); } -/************************************************************************* +/*********************************************************************//** * @brief * The execROPumpMonitor function executes the RO Pump monitor. * @details @@ -196,7 +206,7 @@ publishROPumpData(); } -/************************************************************************* +/*********************************************************************//** * @brief * The execROPumpController function executes the RO Pump controller. * @details @@ -223,20 +233,26 @@ } } -/************************************************************************* +/*********************************************************************//** * @brief * The handleROPumpOffState function handles the ro pump off state \n * of the ro pump controller state machine. * @details - * Inputs : targetROPumpPressure, roPumpDirection - * Outputs : roPumpPWMDutyCyclePctSet, roPumpDirectionSet, isROPumpOn + * Inputs : targetROPumpPressure + * Outputs : roPumpPWMDutyCyclePctSet, isROPumpOn * @param none * @return next state *************************************************************************/ static RO_PUMP_STATE_T handleROPumpOffState( void ) { RO_PUMP_STATE_T result = RO_PUMP_OFF_STATE; + // TODO - test code - remove later + if ( GET_DIP_SW0_TEST() ) + { + setROPumpTargetPressure( 130, PUMP_CONTROL_MODE_CLOSED_LOOP ); + } + // if we've been given a pressure, transition to control to target state if ( getTargetROPumpPressure() > 0 ) { @@ -253,7 +269,7 @@ return result; } -/************************************************************************* +/*********************************************************************//** * @brief * The handleROPumpControlToTargetState function handles the "control to \n * target" state of the ro pump controller state machine. @@ -283,10 +299,16 @@ roControlTimerCounter = 0; } + // TODO - test code - remove later + if ( !GET_DIP_SW0_TEST() ) + { + signalROPumpHardStop(); + } + return result; } -/************************************************************************* +/*********************************************************************//** * @brief * The setROPumpControlSignalPWM function sets the PWM duty cycle for \n * the RO pump to a given %. @@ -301,7 +323,7 @@ etpwmSetCmpB( etpwmREG2, (U32)( (S32)( ( newPWM * (F32)(etpwmREG2->TBPRD) ) + FLOAT_TO_INT_ROUNDUP_OFFSET ) ) ); } -/************************************************************************* +/*********************************************************************//** * @brief * The stopROPump function sets the RO pump PWM to zero. * @details @@ -317,7 +339,7 @@ etpwmSetCmpB( etpwmREG2, 0 ); } -/************************************************************************* +/*********************************************************************//** * @brief * The getPublishROPumpDataInterval function gets the RO pump data \n * publication interval. @@ -339,7 +361,7 @@ return result; } -/************************************************************************* +/*********************************************************************//** * @brief * The getTargetROPumpPressure function gets the current target RO pump \n * pressure. @@ -361,7 +383,7 @@ return result; } -/************************************************************************* +/*********************************************************************//** * @brief * The getMeasuredROPumpPressure function gets the measured RO pump \n * pressure. @@ -383,7 +405,7 @@ return result; } -/************************************************************************* +/*********************************************************************//** * @brief * The getMeasuredROFlowRate function gets the measured RO pump \n * flow rate. @@ -405,7 +427,7 @@ return result; } -/************************************************************************* +/*********************************************************************//** * @brief * The publishROPumpData function publishes RO pump data at the set \n * interval. @@ -427,7 +449,7 @@ } } -/************************************************************************* +/*********************************************************************//** * @brief * The execROPumpTest function executes the state machine for the ROPump self test. * @details @@ -444,13 +466,15 @@ return result; } +/**@}*/ + /************************************************************************* * TEST SUPPORT FUNCTIONS *************************************************************************/ -/************************************************************************* +/*********************************************************************//** * @brief * The testSetROPumpDataPublishIntervalOverride function overrides the \n * RO pump data publish interval. @@ -476,7 +500,7 @@ return result; } -/************************************************************************* +/*********************************************************************//** * @brief * The testResetROPumpDataPublishIntervalOverride function resets the override \n * of the RO pump data publish interval. @@ -499,7 +523,7 @@ return result; } -/************************************************************************* +/*********************************************************************//** * @brief * The testSetTargetROPumpPressureOverride function overrides the target \n * RO pressure. \n @@ -524,7 +548,7 @@ return result; } -/************************************************************************* +/*********************************************************************//** * @brief * The testResetTargetROPumpPressureOverride function resets the override of the \n * target RO pressure. @@ -550,7 +574,7 @@ return result; } -/************************************************************************* +/*********************************************************************//** * @brief * The testSetMeasuredROFlowRateOverride function overrides the measured \n * RO flow rate. @@ -574,7 +598,7 @@ return result; } -/************************************************************************* +/*********************************************************************//** * @brief * The testResetMeasuredROFlowRateOverride function resets the override of the \n * measured RO flow rate.