Index: firmware/App/Drivers/PeristalticPump.c =================================================================== diff -u -r395522dffef1348e176564925656012f529c1910 -rfbe7e9a870c7ad78d3bd26f0f5cbb0277c733ac3 --- firmware/App/Drivers/PeristalticPump.c (.../PeristalticPump.c) (revision 395522dffef1348e176564925656012f529c1910) +++ firmware/App/Drivers/PeristalticPump.c (.../PeristalticPump.c) (revision fbe7e9a870c7ad78d3bd26f0f5cbb0277c733ac3) @@ -19,6 +19,7 @@ #include "FpgaTD.h" #include "Messaging.h" #include "PeristalticPump.h" +#include "Utilities.h" /** * @addtogroup PeristalticPump @@ -51,6 +52,8 @@ static F32 pumpMeasRotSpeedRPM; ///< Latest measured pump rotor speed (in RPM). static BOOL pumpHomeInProgress; ///< Flag indicates a pump home operation is in progress. static BOOL pumpHomeLowSignalSeen; ///< Flag indicates a pump home operation has seen a "not home" signal. +static U16 rotorRevsPrev; ///< Previous FPGA rotor revs counter value. +static U32 rotorRevsAccum; ///< Accumulated rotor revolutions count. // ********** private function prototypes ********** @@ -70,6 +73,9 @@ pumpMeasSpeedRPM = 0.0F; pumpMeasRotSpeedRPM = 0.0F; + rotorRevsPrev = getH4RotorRevsCounter(); + rotorRevsAccum = 0; + setH4Direction( MOTOR_DIR_FORWARD ); setH4SetSpeed( 0 ); setH4Enabled( TRUE ); @@ -87,8 +93,10 @@ *************************************************************************/ void readPeristalticPumps( void ) { - U16 period = getH4Period(); - S16 rotPer = getH4RotorCount(); + U16 delta; + U16 period = getH4Period(); + S16 rotPer = getH4RotorCount(); + U16 rotorRevsNow = getH4RotorRevsCounter(); // update measured pump motor speed if ( period != H4_ZERO_SPEED_PERIOD ) @@ -130,10 +138,28 @@ { pumpHomeLowSignalSeen = TRUE; } + + // update accumulated rotor revolutions count (extend 16-bit FPGA counter to 32-bit) + delta = u16DiffWithWrap( rotorRevsPrev, rotorRevsNow ); + rotorRevsAccum += (U32)delta; + rotorRevsPrev = rotorRevsNow; } /*********************************************************************//** * @brief + * The getPeristalticPumpRotorRevs function returns the accumulated + * rotor revolutions count for the blood pump. + * @details \b Inputs: rotorRevsAccum + * @details \b Outputs: none + * @return Accumulated rotor revolutions count. + *************************************************************************/ +U32 getPeristalticPumpRotorRevs( void ) +{ + return rotorRevsAccum; +} + +/*********************************************************************//** + * @brief * The cmdPeristalticPumpHome function initiates a pump home operation. * @details \b Inputs: none * @details \b Outputs: pumpHomeInProgress, FPGA