Index: firmware/App/Controllers/DialInFlow.c =================================================================== diff -u -r5e77f78c5dee9dfb441bd5d2053f7f4ac50dc619 -r29e57b5232f605a871c62580e16a7db297aae992 --- firmware/App/Controllers/DialInFlow.c (.../DialInFlow.c) (revision 5e77f78c5dee9dfb441bd5d2053f7f4ac50dc619) +++ firmware/App/Controllers/DialInFlow.c (.../DialInFlow.c) (revision 29e57b5232f605a871c62580e16a7db297aae992) @@ -52,8 +52,10 @@ #define DIP_HOME_RATE 100 ///< target pump speed (in estimate mL/min) for homing. #define DIP_HOME_TIMEOUT_MS 10000 ///< maximum time allowed for homing to complete (in ms). -#define DIP_SPEED_CALC_INTERVAL ( 40 / TASK_PRIORITY_INTERVAL ) ///< interval (ms/task time) at which the dialysate inlet pump speed is calculated. -#define DIP_SPEED_CALC_BUFFER__LEN 25 ///< number of hall sensor counts kept in buffer to hold last 1 second of count data. +/// interval (ms/task time) at which the blood pump speed is calculated (every 40 ms). +#define DIP_SPEED_CALC_INTERVAL ( 40 / TASK_PRIORITY_INTERVAL ) +/// number of hall sensor counts kept in buffer to hold last 1 second of count data. +#define DIP_SPEED_CALC_BUFFER__LEN ( 1000 / DIP_SPEED_CALC_INTERVAL / TASK_PRIORITY_INTERVAL ) #define DIP_HALL_EDGE_COUNTS_PER_REV 48 ///< number of hall sensor edge counts per motor revolution. #define DIP_MAX_FLOW_VS_SPEED_DIFF_ML_MIN 50.0 ///< maximum difference between measured flow and flow implied by measured motor speed. @@ -884,7 +886,9 @@ { U16 dipMotorHallSensorCount = getFPGADialInPumpHallSensorCount(); U32 nextIdx = INC_WRAP( dipMotorSpeedCalcIdx, 0, DIP_SPEED_CALC_BUFFER__LEN - 1 ); - U16 incDelta = ( dipMotorHallSensorCount >= dipLastMotorHallSensorCounts[ nextIdx ] ? dipMotorHallSensorCount - dipLastMotorHallSensorCounts[ nextIdx ] : ( HEX_64_K - dipLastMotorHallSensorCounts[ nextIdx ] ) + dipMotorHallSensorCount ); + U16 incDelta = ( dipMotorHallSensorCount >= dipLastMotorHallSensorCounts[ dipMotorSpeedCalcIdx ] ? \ + dipMotorHallSensorCount - dipLastMotorHallSensorCounts[ dipMotorSpeedCalcIdx ] : \ + ( HEX_64_K - dipLastMotorHallSensorCounts[ dipMotorSpeedCalcIdx ] ) + dipMotorHallSensorCount ); U16 decDelta = HEX_64_K - incDelta; U16 delta;