Index: firmware/App/Drivers/PeristalticPump.c =================================================================== diff -u -r395522dffef1348e176564925656012f529c1910 -ra78f3727da3bafa9bf6a387c82292dacef8c52c5 --- firmware/App/Drivers/PeristalticPump.c (.../PeristalticPump.c) (revision 395522dffef1348e176564925656012f529c1910) +++ firmware/App/Drivers/PeristalticPump.c (.../PeristalticPump.c) (revision a78f3727da3bafa9bf6a387c82292dacef8c52c5) @@ -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 ); @@ -81,14 +87,16 @@ * peristaltic pump from the FPGA. * @note This function should be called periodically to maintain fresh * sensor readings for the pump. - * @details \b Inputs: pumpSetSpeedRPM, pumpHomeInProgress, FPGA - * @details \b Outputs: pumpMeasSpeedRPM, pumpHomeInProgress + * @details \b Inputs: pumpSetSpeedRPM, pumpHomeInProgress, FPGA, rotorRevsPrev, rotorRevsAccum + * @details \b Outputs: pumpMeasSpeedRPM, pumpHomeInProgress, rotorRevsPrev, rotorRevsAccu * @return none *************************************************************************/ 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