Index: firmware/App/Controllers/DialOutFlow.c =================================================================== diff -u -r8ce8a04d4c7871337a6fa53dc8844bcc3c2c955b -r3d8d8451d10aaf2ea9fc9d83857699ef1ae1a0be --- firmware/App/Controllers/DialOutFlow.c (.../DialOutFlow.c) (revision 8ce8a04d4c7871337a6fa53dc8844bcc3c2c955b) +++ firmware/App/Controllers/DialOutFlow.c (.../DialOutFlow.c) (revision 3d8d8451d10aaf2ea9fc9d83857699ef1ae1a0be) @@ -55,20 +55,21 @@ #define MAX_DIAL_OUT_PUMP_PWM_OFFSET_CONTROL 0.4 ///< Maximum PWM offset (added to DPi PWM duty cycle). #define MIN_DIAL_OUT_PUMP_PWM_OFFSET_CONTROL -0.4 ///< Minimum PWM offset (added to DPi PWM duty cycle). -#define DOP_P_COEFFICIENT 0.0010 ///< P term for dialysate outlet pump control. -#define DOP_I_COEFFICIENT 0.0001 ///< I term for dialysate outlet pump control. -#define P_UF 0.001 -#define P_CORR 0.1666 +#define P_VOL 0.001 ///< P term for volume error feedback into dialysate outlet pump control. +#define P_UF 0.001 ///< P term for UF rate error feedback into dialysate outlet pump control. +#define P_CORR 0.1666 ///< P term for volume error feedback into dialysate outlet pump flow estimate correction offset. -#define RPM_2_ML_MIN_CONVERSION 0.215964 -#define SIZE_OF_ROLLING_AVG 100 +#define RPM_2_ML_MIN_CONVERSION 0.215964 ///< Conversion factor for estimating flow rate from pump motor RPM. +#define SIZE_OF_ROLLING_AVG 100 ///< Number of samples in DPo flow estimation moving average. #define DOP_HOME_RATE 100 ///< Target pump speed (in estimate mL/min) for homing. #define DOP_HOME_TIMEOUT_MS 10000 ///< Maximum time allowed for homing to complete (in ms). + /// Interval (ms/task time) at which the blood pump speed is calculated (every 40 ms). #define DOP_SPEED_CALC_INTERVAL ( 40 / TASK_PRIORITY_INTERVAL ) /// Number of hall sensor counts kept in buffer to hold last 1 second of count data. #define DOP_SPEED_CALC_BUFFER__LEN ( 1000 / DOP_SPEED_CALC_INTERVAL / TASK_PRIORITY_INTERVAL ) + #define DOP_HALL_EDGE_COUNTS_PER_REV 48 ///< Number of hall sensor edge counts per motor revolution. #define DOP_MAX_MOTOR_SPEED_WHILE_OFF_RPM 100.0 ///< Maximum motor speed (RPM) while motor is commanded off. @@ -157,17 +158,17 @@ static OVERRIDE_F32_T dialOutPumpSpeedRPM = { 0.0, 0.0, 0.0, 0 }; ///< Measured dialysate outlet pump motor speed. static F32 offsetPWMDutyCyclePct = 0.0; ///< PWM duty cycle percentage offset to add to inlet pump duty cycle for UF control. -static F32 dopMeasuredRate = 0.0; -static F32 ufMeasuredRate = 0.0; -static F32 dopRateCorrectionOffset = 0.0; +static F32 dopMeasuredRate = 0.0; ///< Estimated flow rate for dialysate outlet pump. +static F32 ufMeasuredRate = 0.0; ///< Calculated UF flow rate from measured dialysate flow rate subtracted from estimated dialysate outlet flow rate. +static F32 dopRateCorrectionOffset = 0.0; ///< Correction offset for estimated flow rate for dialysate outlet pump. -static U32 flowFilterTimerCount = 0; +static U32 flowFilterTimerCtr = 0; ///< Timer counter for determining when to add a new sample to the moving average. static F64 flowReadings[ SIZE_OF_ROLLING_AVG ]; ///< Holds flow samples for a rolling average. static U32 flowReadingsIdx = 0; ///< Index for next sample in rolling average array. static F64 flowReadingsTotal = 0.0; ///< Rolling total - used to calc average. static U32 flowReadingsCount = 0; ///< Number of samples in flow rolling average buffer. -static BOOL dopControlSignal = FALSE; +static BOOL dopControlSignal = FALSE; ///< Control signal for syncing UF control to follow control interval of dialysate inlet pump. static U32 dopCurrErrorDurationCtr = 0; ///< Timer counter for motor current error persistence. @@ -234,10 +235,6 @@ ufMeasuredRate = 0.0; dopRateCorrectionOffset = 40.0; // TODO - set to 0.0 when we have a better dop flow estimate. resetDialOutFlowMovingAverage(); - - // Initialize dialysate outlet flow PI controller - initializePIController( PI_CONTROLLER_ID_ULTRAFILTRATION, 0.0, DOP_P_COEFFICIENT, DOP_I_COEFFICIENT, - MIN_DIAL_OUT_PUMP_PWM_OFFSET_CONTROL, MAX_DIAL_OUT_PUMP_PWM_OFFSET_CONTROL ); } /*********************************************************************//** @@ -346,7 +343,6 @@ dialOutPumpState = DIAL_OUT_PUMP_OFF_STATE; dialOutPumpPWMDutyCyclePct = 0.0; resetDialOutFlowMovingAverage(); - resetPIController( PI_CONTROLLER_ID_ULTRAFILTRATION, MIN_DIAL_OUT_PUMP_PWM_DUTY_CYCLE ); } /*********************************************************************//** @@ -480,9 +476,9 @@ updateDialOutPumpSpeedAndDirectionFromHallSensors(); // Filter estimated dialysate out flow rate and calculate UF rate - if ( ++flowFilterTimerCount >= DIAL_OUT_FILTER_INTERVAL ) + if ( ++flowFilterTimerCtr >= DIAL_OUT_FILTER_INTERVAL ) { - flowFilterTimerCount = 0; + flowFilterTimerCtr = 0; // Calculate DPo flow in mL/min filterDialOutFlowReadings( getMeasuredDialOutPumpMCSpeed() * RPM_2_ML_MIN_CONVERSION ); // Calculate UF flow in mL/min @@ -673,7 +669,7 @@ dopRateCorrectionOffset += ( ( totVol - refVol ) * P_CORR ); - offsetPWMDutyCyclePct += volErr * DOP_P_COEFFICIENT; + offsetPWMDutyCyclePct += volErr * P_VOL; offsetPWMDutyCyclePct += ( ufrErr * P_UF ); // Add PWM offset to DPi PWM mirror for our new DPo PWM Index: firmware/App/Services/PIControllers.c =================================================================== diff -u -rccfd15568f1e3d304320c2babb2fd4bcf0413304 -r3d8d8451d10aaf2ea9fc9d83857699ef1ae1a0be --- firmware/App/Services/PIControllers.c (.../PIControllers.c) (revision ccfd15568f1e3d304320c2babb2fd4bcf0413304) +++ firmware/App/Services/PIControllers.c (.../PIControllers.c) (revision 3d8d8451d10aaf2ea9fc9d83857699ef1ae1a0be) @@ -64,7 +64,6 @@ /// PI Controllers -- initial configurations. static PI_CONTROLLER_T piControllers[ NUM_OF_PI_CONTROLLERS_IDS ] = { // Kp Ki uMax uMin ref meas err esw esum ctrl Ilimit controller type - { 0.0, 0.0, 0.90, 0.10, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 50.0, CONTROLLER_BIDIRECTIONAL }, // PI_CONTROLLER_ID_ULTRAFILTRATION { 0.0, 0.0, 0.90, 0.10, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 100.0, CONTROLLER_UNIDIRECTIONAL }, // PI_CONTROLLER_ID_BLOOD_FLOW { 0.0, 0.0, 0.90, 0.10, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 100.0, CONTROLLER_UNIDIRECTIONAL } // PI_CONTROLLER_ID_DIALYSATE_FLOW }; Index: firmware/App/Services/PIControllers.h =================================================================== diff -u -rccfd15568f1e3d304320c2babb2fd4bcf0413304 -r3d8d8451d10aaf2ea9fc9d83857699ef1ae1a0be --- firmware/App/Services/PIControllers.h (.../PIControllers.h) (revision ccfd15568f1e3d304320c2babb2fd4bcf0413304) +++ firmware/App/Services/PIControllers.h (.../PIControllers.h) (revision 3d8d8451d10aaf2ea9fc9d83857699ef1ae1a0be) @@ -33,8 +33,7 @@ /// Enumeration of PI controllers typedef enum ControllerList { - PI_CONTROLLER_ID_ULTRAFILTRATION = 0, ///< Load cell controller for dialysate outlet pump. - PI_CONTROLLER_ID_BLOOD_FLOW, ///< Flow controller for blood pump. + PI_CONTROLLER_ID_BLOOD_FLOW = 0, ///< Flow controller for blood pump. PI_CONTROLLER_ID_DIALYSATE_FLOW, ///< Flow controller for dialysate inlet pump. NUM_OF_PI_CONTROLLERS_IDS ///< Number of PI controllers. } PI_CONTROLLER_ID_T;