Index: firmware/App/Controllers/BloodFlow.c =================================================================== diff -u -r5e77f78c5dee9dfb441bd5d2053f7f4ac50dc619 -r29e57b5232f605a871c62580e16a7db297aae992 --- firmware/App/Controllers/BloodFlow.c (.../BloodFlow.c) (revision 5e77f78c5dee9dfb441bd5d2053f7f4ac50dc619) +++ firmware/App/Controllers/BloodFlow.c (.../BloodFlow.c) (revision 29e57b5232f605a871c62580e16a7db297aae992) @@ -55,8 +55,10 @@ #define BP_HOME_RATE 100 ///< target pump speed (in estimate mL/min) for homing. #define BP_HOME_TIMEOUT_MS 10000 ///< maximum time allowed for homing to complete (in ms). -#define BP_SPEED_CALC_INTERVAL ( 40 / TASK_PRIORITY_INTERVAL ) ///< interval (ms/task time) at which the blood pump speed is calculated. -#define BP_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 BP_SPEED_CALC_INTERVAL ( 40 / TASK_PRIORITY_INTERVAL ) +/// number of hall sensor counts kept in buffer to hold last 1 second of count data. +#define BP_SPEED_CALC_BUFFER__LEN ( 1000 / BP_SPEED_CALC_INTERVAL / TASK_PRIORITY_INTERVAL ) #define BP_HALL_EDGE_COUNTS_PER_REV 48 ///< number of hall sensor edge counts per motor revolution. #define BP_MAX_ROTOR_SPEED_RPM 100.0 ///< maximum rotor speed allowed for blood pump. @@ -905,7 +907,9 @@ { U16 bpMotorHallSensorCount = getFPGABloodPumpHallSensorCount(); U32 nextIdx = INC_WRAP( bpMotorSpeedCalcIdx, 0, BP_SPEED_CALC_BUFFER__LEN - 1 ); - U16 incDelta = ( bpMotorHallSensorCount >= bpLastMotorHallSensorCounts[ nextIdx ] ? bpMotorHallSensorCount - bpLastMotorHallSensorCounts[ nextIdx ] : ( HEX_64_K - bpLastMotorHallSensorCounts[ nextIdx ] ) + bpMotorHallSensorCount ); + U16 incDelta = ( bpMotorHallSensorCount >= bpLastMotorHallSensorCounts[ bpMotorSpeedCalcIdx ] ? \ + bpMotorHallSensorCount - bpLastMotorHallSensorCounts[ bpMotorSpeedCalcIdx ] : \ + ( HEX_64_K - bpLastMotorHallSensorCounts[ bpMotorSpeedCalcIdx ] ) + bpMotorHallSensorCount ); U16 decDelta = HEX_64_K - incDelta; U16 delta;