Index: firmware/App/Controllers/DialOutFlow.c =================================================================== diff -u -r6463655c18b173e335b6d475ac7289336f1bf092 -r4ebc1f7e1aeb3a332e91fcdd1bbbe1a01873d93a --- firmware/App/Controllers/DialOutFlow.c (.../DialOutFlow.c) (revision 6463655c18b173e335b6d475ac7289336f1bf092) +++ firmware/App/Controllers/DialOutFlow.c (.../DialOutFlow.c) (revision 4ebc1f7e1aeb3a332e91fcdd1bbbe1a01873d93a) @@ -52,6 +52,9 @@ #define DOP_P_COEFFICIENT 0.0050 ///< P term for dialysate outlet pump control. #define DOP_I_COEFFICIENT 0.0001 ///< I term for dialysate outlet pump control. +#define DOP_HOME_RATE 50 ///< target pump speed (in estimate mL/min) for homing. +#define DOP_HOME_TIMEOUT_MS 10000 ///< maximum time allowed for homing to complete (in ms). + #define DOP_MAX_CURR_WHEN_STOPPED_MA 150.0 ///< Motor controller current should not exceed this when pump should be stopped. #define DOP_MIN_CURR_WHEN_RUNNING_MA 150.0 ///< Motor controller current should always exceed this when pump should be running. #define DOP_MAX_CURR_WHEN_RUNNING_MA 1000.0 ///< Motor controller current should not exceed this when pump should be running. @@ -94,15 +97,15 @@ // pin assignments and macros for pump stop and direction outputs #define STOP_DO_PUMP_MIBSPI1_PORT_MASK 0x00000400 ///< MIBSPI1 SIMO[0] - re-purposed as GPIOoutput for pump controller run/stop pin. #ifndef BREADBOARD_TARGET - #define SET_DOP_STOP() {mibspiREG1->PC3 &= ~STOP_DO_PUMP_MIBSPI1_PORT_MASK;} ///< Macro sets pump controller run/stop signal to stop. - #define CLR_DOP_STOP() {mibspiREG1->PC3 |= STOP_DO_PUMP_MIBSPI1_PORT_MASK;} ///< Macro sets pump controller run/stop signal to run. + #define SET_DOP_STOP() {mibspiREG1->PC3 &= ~STOP_DO_PUMP_MIBSPI1_PORT_MASK;} ///< Macro sets pump controller run/stop signal to stop. + #define CLR_DOP_STOP() {mibspiREG1->PC3 |= STOP_DO_PUMP_MIBSPI1_PORT_MASK;} ///< Macro sets pump controller run/stop signal to run. #else - #define SET_DOP_STOP() {mibspiREG1->PC3 |= STOP_DO_PUMP_MIBSPI1_PORT_MASK;} ///< Macro sets pump controller run/stop signal to stop. - #define CLR_DOP_STOP() {mibspiREG1->PC3 &= ~STOP_DO_PUMP_MIBSPI1_PORT_MASK;} ///< Macro sets pump controller run/stop signal to run. + #define SET_DOP_STOP() {mibspiREG1->PC3 |= STOP_DO_PUMP_MIBSPI1_PORT_MASK;} ///< Macro sets pump controller run/stop signal to stop. + #define CLR_DOP_STOP() {mibspiREG1->PC3 &= ~STOP_DO_PUMP_MIBSPI1_PORT_MASK;} ///< Macro sets pump controller run/stop signal to run. #endif -#define STOP_DO_PUMP_GIO_PORT_PIN 6U ///< GIO port A pin used for pump controller direction pin. -#define SET_DOP_DIR() gioSetBit( gioPORTA, STOP_DO_PUMP_GIO_PORT_PIN, PIN_SIGNAL_HIGH ) ///< Macro sets pump controller direction to forward direction. -#define CLR_DOP_DIR() gioSetBit( gioPORTA, STOP_DO_PUMP_GIO_PORT_PIN, PIN_SIGNAL_LOW ) ///< Macro sets pump controller direction to reverse direction. +#define STOP_DO_PUMP_GIO_PORT_PIN 6U ///< GIO port A pin used for pump controller direction pin. +#define SET_DOP_DIR() gioSetBit( gioPORTA, STOP_DO_PUMP_GIO_PORT_PIN, PIN_SIGNAL_HIGH ) ///< Macro sets pump controller direction to forward direction. +#define CLR_DOP_DIR() gioSetBit( gioPORTA, STOP_DO_PUMP_GIO_PORT_PIN, PIN_SIGNAL_LOW ) ///< Macro sets pump controller direction to reverse direction. // ********** private data ********** @@ -129,6 +132,10 @@ static U32 dopControlTimerCounter = 0; ///< Timer counter to determine when to control dialysate outlet pump. static U32 dopCurrErrorDurationCtr = 0; ///< Timer counter for motor current error persistence. +static U32 dopRotorRevStartTime = 0; ///< dialysate outlet pump rotor rotation start time (in ms) +static BOOL dopStopAtHomePosition = FALSE; ///< stop dialysate outlet pump at next home position +static U32 dopHomeStartTime = 0; ///< when did dialysate outlet pump home command begin? (in ms) + static DIAL_OUT_PUMP_SELF_TEST_STATE_T dialOutPumpSelfTestState = DIAL_OUT_PUMP_SELF_TEST_STATE_START; ///< Current state of the dialysate outlet pump self test state machine. static U32 dialOutPumpSelfTestTimerCount = 0; ///< Timer counter for time reference during self test. @@ -295,6 +302,55 @@ /*********************************************************************//** * @brief + * The signalDialOutPumpRotorHallSensor function handles the dialysate outlet \n + * pump rotor hall sensor detection. Calculates rotor speed (in RPM). \n + * Stops pump if there is a pending request to home the pump. + * @details + * Inputs : dopRotorRevStartTime, dopStopAtHomePosition + * Outputs : dopRotorRevStartTime, dialOutPumpRotorSpeedRPM + * @return none + *************************************************************************/ +void signalDialOutPumpRotorHallSensor( void ) +{ + U32 rotTime = getMSTimerCount(); + U32 deltaTime = calcTimeBetween( dopRotorRevStartTime, rotTime ); + + // calculate rotor speed (in RPM) + dialOutPumpRotorSpeedRPM.data = ( 1.0 / (F32)deltaTime ) * (F32)MS_PER_SECOND * (F32)SEC_PER_MIN; + dopRotorRevStartTime = rotTime; + + // if we're supposed to stop pump at home position, stop pump now. + if ( TRUE == dopStopAtHomePosition ) + { + signalDialOutPumpHardStop(); + dopStopAtHomePosition = FALSE; + } +} + +/*********************************************************************//** + * @brief + * The homeDialOutPump function initiates a dialysate outlet pump home operation. + * @details + * Inputs : dialOutPumpState + * Outputs : dopStopAtHomePosition, dopHomeStartTime, dialysate outlet pump started (slow) + * @return none + *************************************************************************/ +BOOL homeDialOutPump( void ) +{ + BOOL result = FALSE; + + if ( DIAL_OUT_PUMP_OFF_STATE == dialOutPumpState ) + { + dopStopAtHomePosition = TRUE; + dopHomeStartTime = getMSTimerCount(); + result = setDialOutPumpTargetRate( DOP_HOME_RATE, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_OPEN_LOOP ); + } + + return result; +} + +/*********************************************************************//** + * @brief * The setDialOutUFVolumes function sets the ultrafiltration reference and \n * measured total volumes (in mL). * @details @@ -343,6 +399,14 @@ checkDialOutPumpMCCurrent(); } + // if homing, check timeout + if ( ( TRUE == dopStopAtHomePosition ) && ( TRUE == didTimeout( dopHomeStartTime, DOP_HOME_TIMEOUT_MS ) ) ) + { + signalDialOutPumpHardStop(); + dopStopAtHomePosition = FALSE; + // TODO - alarm??? + } + publishDialOutFlowData(); } @@ -558,7 +622,7 @@ /*********************************************************************//** * @brief stopDialOutPump - * The stopDialOutPump function sets the dialout flow stop signal and PWM + * The stopDialOutPump function sets the dialout flow stop signal and PWM \n * duty cycle to 0.0. * @details * Inputs : none @@ -587,7 +651,7 @@ } /*********************************************************************//** - * @brief setDialOutPumpDirection + * @brief * The setDialOutPumpDirection function sets the set dialOut pump direction to \n * the given direction. * @details @@ -617,7 +681,7 @@ } /*********************************************************************//** - * @brief publishDialOutFlowData + * @brief * The publishDialOutFlowData function publishes dialysate outlet data at \n * the set interval. * @details @@ -654,7 +718,6 @@ * @details * Inputs : adcDialOutPumpMCSpeedRPM, dialOutPumpDirectionSet, dialOutPumpState * Outputs : none - * @param none * @return none *************************************************************************/ static void checkDialOutPumpDirection( void ) @@ -679,7 +742,6 @@ * @details * Inputs : dialOutPumpState, dopCurrErrorDurationCtr, adcDialOutPumpMCCurrentmA * Outputs : none - * @param none * @return none *************************************************************************/ static void checkDialOutPumpMCCurrent( void ) @@ -863,7 +925,6 @@ * @details * Inputs : dialOutPumpMCSpeedRPM * Outputs : none -* @param none * @return the current dialOut pump speed (in RPM). *************************************************************************/ F32 getMeasuredDialOutPumpMCSpeed( void )