Index: firmware/App/Controllers/RinsePump.c =================================================================== diff -u -r3417933e6edf61a914c428e2fa944b3b349272a4 -r72802c396f436d451920fc3be5f2e351b5a2ea73 --- firmware/App/Controllers/RinsePump.c (.../RinsePump.c) (revision 3417933e6edf61a914c428e2fa944b3b349272a4) +++ firmware/App/Controllers/RinsePump.c (.../RinsePump.c) (revision 72802c396f436d451920fc3be5f2e351b5a2ea73) @@ -15,10 +15,11 @@ * ***************************************************************************/ -#include "RinsePump.h" +#include "FpgaDD.h" #include "Messaging.h" #include "OperationModes.h" #include "PersistentAlarm.h" +#include "RinsePump.h" #include "TaskGeneral.h" #include "Timers.h" #include "Valves.h" @@ -30,14 +31,25 @@ // ********** private definitions ********** -#define RINSE_PUMP_DATA_PUB_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Rinse pump data publish interval. -#define DATA_PUBLISH_COUNTER_START_COUNT 13 ///< Rinse pump data publish start counter. +#define RINSE_PUMP_DATA_PUB_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Rinse pump data publish interval. +#define DATA_PUBLISH_COUNTER_START_COUNT 13 ///< Rinse pump data publish start counter. +#define RINSE_PUMP_OFF_COUNT 0U ///< Rinse Pump OFF value in count +#define RINSE_PUMP_DEFAULT_PWM_PERCENT 10.0F ///< Initial Rinse pump PWM percentage +#define RINSE_PUMP_MAX_PWM_PERCENT 100.0F ///< Max Rinse pump PWM percentage +#define RINSE_PUMP_PWM_IN_COUNT_MAX 255.0F ///< Rinse pump max count (100% PWM = 255) +#define RINSE_PUMP_PWM_PULSE_RESOLUTION_US 10 ///< Rinse pump PWM pulse resolution in 10us +// TODO remove once PMW control is implemented +#define RINSE_PUMP_TURN_OFF_CONTROL_BIT 0xFE ///< Rinse pump turn off control bit. +#define RINSE_PUMP_TURN_ON_CONTROL_BIT 0xFF ///< Rinse pump turn on control bit. + // ********** private data ********** -static RINSE_PUMP_STATE_T currentRinsePumpState; ///< Current rinse pump control state. -static U32 rinsePumpDataPublicationTimerCounter; ///< Rinse pump data broadcast timer counter. -static OVERRIDE_U32_T rinsePumpDataPublishInterval; ///< Rinse pump data broadcast interval (in ms). +static RINSE_PUMP_STATE_T currentRinsePumpState; ///< Current rinse pump control state. +static U32 rinsePumpDataPublicationTimerCounter; ///< Rinse pump data broadcast timer counter. +static U32 rinsePumpMeasuredSpeed; ///< Rinse pump measured speed +static OVERRIDE_F32_T rinsePumpPwmPercentage; ///< Rinse pump PWM percentage. +static OVERRIDE_U32_T rinsePumpDataPublishInterval; ///< Rinse pump data broadcast interval (in ms). // ********** private function prototypes ********** @@ -62,6 +74,11 @@ rinsePumpDataPublishInterval.ovData = RINSE_PUMP_DATA_PUB_INTERVAL; rinsePumpDataPublishInterval.ovInitData = RINSE_PUMP_DATA_PUB_INTERVAL; rinsePumpDataPublishInterval.override = OVERRIDE_RESET; + rinsePumpPwmPercentage.data = RINSE_PUMP_DEFAULT_PWM_PERCENT; + rinsePumpPwmPercentage.ovData = RINSE_PUMP_DEFAULT_PWM_PERCENT; + rinsePumpPwmPercentage.ovInitData = RINSE_PUMP_DEFAULT_PWM_PERCENT; + rinsePumpPwmPercentage.override = OVERRIDE_RESET; + rinsePumpMeasuredSpeed = 0; } /*********************************************************************//** @@ -99,6 +116,24 @@ /*********************************************************************//** * @brief + * The calculateRinsePumpSpeed function calculate rinse pump speed based + * on FPGA report pulse width value. + * @details \b Inputs: fpgaD79PumpSpeed + * @details \b Outputs: rinsePumpMeasuredSpeed + * @return none. + *************************************************************************/ +void calculateRinsePumpSpeed( void ) +{ + // Pulse width in 10us resolution + U16 pumpPulseWidth = 0; //getFPGAD79RinsePumpSpeed(); // TODO ucomment + U32 pumpSpeedPerSec = US_PER_SECOND / ( pumpPulseWidth * RINSE_PUMP_PWM_PULSE_RESOLUTION_US ); + + //Speed in RPM + rinsePumpMeasuredSpeed = pumpSpeedPerSec * SEC_PER_MIN; +} + +/*********************************************************************//** + * @brief * The execRinsePumpController function executes the rinse pump state machine. * @details \b Alarm: ALARM_ID_DD_SOFTWARE_FAULT if the current state is invalid. * @details \b Inputs: currentRinsePumpState @@ -154,9 +189,16 @@ { RINSE_PUMP_STATE_T state = RINSE_PUMP_STATE_OFF; - // Current alpha system uses valve D65 to turn on the rinse pump - // and its just On/off control for now. - setValveState( D79_PMP_VALV, VALVE_STATE_CLOSED ); + if ( TRUE == getTestConfigStatus( TEST_CONFIG_ENABLE_4WIRE_RINSE_PUMP ) ) + { + // Set PWM count zero to stop the pump + setFPGAD79RinsePumpPWMControl( RINSE_PUMP_OFF_COUNT ); + } + else + { + // Current Beat 1.9 system uses on/off bit + setFPGAD79RinsePumpControl( RINSE_PUMP_TURN_OFF_CONTROL_BIT ); + } return state; } @@ -172,9 +214,20 @@ { RINSE_PUMP_STATE_T state = RINSE_PUMP_STATE_ON; - // D79 Pump On/off control - setValveState( D79_PMP_VALV, VALVE_STATE_OPEN ); + if ( TRUE == getTestConfigStatus( TEST_CONFIG_ENABLE_4WIRE_RINSE_PUMP ) ) + { + F32 pwmPercent = getF32OverrideValue( &rinsePumpPwmPercentage ); + U32 pwmInCount = (U32)( ( pwmPercent / RINSE_PUMP_MAX_PWM_PERCENT ) * RINSE_PUMP_PWM_IN_COUNT_MAX ); + //Turn on Rinse pump with given PWM value + setFPGAD79RinsePumpPWMControl( pwmInCount ); + } + else + { + // Current Beat 1.9 system uses on/off bit + setFPGAD79RinsePumpControl( RINSE_PUMP_TURN_ON_CONTROL_BIT ); + } + return state; } @@ -193,7 +246,9 @@ { RINSE_PUMP_PAYLOAD_T data; - data.d79State = getRinsePumpState(); + data.d79State = getRinsePumpState(); + data.d79PumpPWM = getF32OverrideValue( &rinsePumpPwmPercentage ); + data.d79PumpRPM = rinsePumpMeasuredSpeed; broadcastData( MSG_ID_DD_RINSE_PUMP_DATA, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08*)&data, sizeof( RINSE_PUMP_PAYLOAD_T ) ); rinsePumpDataPublicationTimerCounter = 0; @@ -223,5 +278,54 @@ return result; } +/*********************************************************************//** + * @brief + * The testRinsePumpPWMPercentOverride function sets the override value + * of the rinse pump PWM percentage. + * @details Inputs: rinsePumpPwmPercentage (0 to 100%) + * @details Outputs: rinsePumpPwmPercentage + * @param message Override message from Dialin which includes the override + * value of the rinse pump PWM percentage. + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testRinsePumpPWMPercentOverride( MESSAGE_T *message ) +{ + BOOL result = f32Override( message, &rinsePumpPwmPercentage ); + + return result; +} + +/*********************************************************************//** + * @brief + * The testRinsePumpTurnOnOffRequest function sets the rinse pump status to + * On or Off. + * @details Inputs: none + * @details Outputs: none + * @param message Override message from Dialin which includes the rinse pump + * value of being 0 (Off) or 1 (On) + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testRinsePumpTurnOnOffRequest( MESSAGE_T *message ) +{ + BOOL result = FALSE; + + if ( message->hdr.payloadLen == sizeof( U32 ) ) + { + U32 rinsePumpOnOff; + RINSE_PUMP_STATE_T rinsePumpState; + + U08* payloadPtr = message->payload; + + memcpy( &rinsePumpOnOff, payloadPtr, sizeof( U32 ) ); + rinsePumpState = ( 0 == rinsePumpOnOff ? RINSE_PUMP_STATE_OFF : RINSE_PUMP_STATE_ON ); + + setRinsePumpState( rinsePumpState ); + + result = TRUE; + } + + return result; +} + /**@}*/ Index: firmware/App/Controllers/RinsePump.h =================================================================== diff -u -r3417933e6edf61a914c428e2fa944b3b349272a4 -r72802c396f436d451920fc3be5f2e351b5a2ea73 --- firmware/App/Controllers/RinsePump.h (.../RinsePump.h) (revision 3417933e6edf61a914c428e2fa944b3b349272a4) +++ firmware/App/Controllers/RinsePump.h (.../RinsePump.h) (revision 72802c396f436d451920fc3be5f2e351b5a2ea73) @@ -37,6 +37,8 @@ typedef struct { U32 d79State; ///< Rinse pump state status + F32 d79PumpPWM; ///< Rinse pump PWM value + U32 d79PumpRPM; ///< Rinse pump RPM value } RINSE_PUMP_PAYLOAD_T; #pragma pack(pop) @@ -57,6 +59,8 @@ RINSE_PUMP_STATE_T getRinsePumpState( void ); BOOL testRinsePumpDataPublishIntervalOverride( MESSAGE_T *message ); +BOOL testRinsePumpPWMPercentOverride( MESSAGE_T *message ); +BOOL testRinsePumpTurnOnOffRequest( MESSAGE_T *message ); // TODO remove when the PWM is implemented /**@}*/ Index: firmware/App/Services/FpgaDD.c =================================================================== diff -u -r3417933e6edf61a914c428e2fa944b3b349272a4 -r72802c396f436d451920fc3be5f2e351b5a2ea73 --- firmware/App/Services/FpgaDD.c (.../FpgaDD.c) (revision 3417933e6edf61a914c428e2fa944b3b349272a4) +++ firmware/App/Services/FpgaDD.c (.../FpgaDD.c) (revision 72802c396f436d451920fc3be5f2e351b5a2ea73) @@ -295,7 +295,7 @@ U08 fpgaD42FIFOTx; ///< Reg 48. Blood leak sensor FIFO transmit control U08 fpgaD5HeaterPWMControl; ///< Reg 49. Primary heater PWM control U08 fpgaD45HeaterPWMControl; ///< Reg 50. Trimmer heater PWM control - U08 fpgaNotUsed; ///< Reg 51. Not used + U08 fpgaD79PWMPumpCtl; ///< Reg 51. Rinse pump PWM control U16 fpgaVBCPWMLow; ///< Reg 52. VBC PWM low ( Balancing chamber valves) U16 fpgaVBCPWMPeriod; ///< Reg 54. VBC PWM period U16 fpgaVBCPWMPullin; ///< Reg 56. VBC PWM pull in @@ -2841,6 +2841,32 @@ /*********************************************************************//** * @brief + * The setFPGAD79RinsePumpControl function sets the control bit of the rinse + * pump to turn it on or off. + * @details \b Inputs: none + * @details \b Outputs: fpgaActuatorSetPoints.fpgaDDSpareValveControl + * @return none + *************************************************************************/ +void setFPGAD79RinsePumpControl( U08 value ) +{ + fpgaActuatorSetPoints.fpgaDDSpareValveControl &= value; +} + +/*********************************************************************//** + * @brief + * The setFPGAD79RinsePumpPWMControl function sets the PWM value of the rinse + * pump to turn it on or off. + * @details \b Inputs: none + * @details \b Outputs: fpgaActuatorSetPoints.fpgaD79PWMPumpCtl + * @return none + *************************************************************************/ +void setFPGAD79RinsePumpPWMControl( U08 value ) +{ + fpgaActuatorSetPoints.fpgaD79PWMPumpCtl = value; +} + +/*********************************************************************//** + * @brief * The setFPGAIOValveStates function sets the IO valve states with an 8-bit * mask of states - one bit per valve, with a 1 meaning "energized" and a 0 * meaning "de-energized". The bit positions for these bit states are as follows: Index: firmware/App/Services/FpgaDD.h =================================================================== diff -u -r3417933e6edf61a914c428e2fa944b3b349272a4 -r72802c396f436d451920fc3be5f2e351b5a2ea73 --- firmware/App/Services/FpgaDD.h (.../FpgaDD.h) (revision 3417933e6edf61a914c428e2fa944b3b349272a4) +++ firmware/App/Services/FpgaDD.h (.../FpgaDD.h) (revision 72802c396f436d451920fc3be5f2e351b5a2ea73) @@ -149,6 +149,7 @@ void setFPGAD11PumpRevolutionCount( U16 count ); void setFPGAD10PumpRevolutionCount( U16 count ); void setFPGAD76PumpRevolutionCount( U16 count ); +void setFPGAD79RinsePumpPWMControl( U08 control ); U08 getFPGAD11PumpControlStatus( void ); U08 getFPGAD10PumpControlStatus( void ); @@ -167,6 +168,7 @@ U16 getFPGAD11PumpRevolutionCountStatus( void ); U16 getFPGAD10PumpRevolutionCountStatus( void ); U16 getFPGAD76PumpRevolutionCountStatus( void ); +U16 getFPGAD79RinsePumpSpeed( void ); void setFPGAD48PumpSpeed( U16 speed ); void setFPGAD12PumpSpeed( U16 speed ); @@ -231,6 +233,10 @@ U08 getFPGABloodLeakRxErrorCount( void ); U08 getFPGABloodLeakRxFIFODataOut( void ); +// Rinse pump +void setFPGAD79RinsePumpControl( U08 value ); +void setFPGAD79RinsePumpPWMControl( U08 value ); + //*************** IOFP ******************* void setFPGAIOValveStates( U08 valveStates ); Index: firmware/App/Services/Messaging.c =================================================================== diff -u -r2475e55c224cbd841d61b76f1618451efe6be1f5 -r72802c396f436d451920fc3be5f2e351b5a2ea73 --- firmware/App/Services/Messaging.c (.../Messaging.c) (revision 2475e55c224cbd841d61b76f1618451efe6be1f5) +++ firmware/App/Services/Messaging.c (.../Messaging.c) (revision 72802c396f436d451920fc3be5f2e351b5a2ea73) @@ -239,9 +239,11 @@ { MSG_ID_FP_PERMEATE_TANK_PUBLISH_INTERVAL_OVERRIDE_REQUEST, &testPermeateTankDataPublishIntervalOverride }, { MSG_ID_FP_RO_PUMP_PUBLISH_INTERVAL_OVERRIDE_REQUEST, &testROPumpDataPublishIntervalOverride }, { MSG_ID_DD_RINSE_PUMP_DATA_PUBLISH_INTERVAL_OVERRIDE_REQUEST, &testRinsePumpDataPublishIntervalOverride }, + { MSG_ID_DD_RINSE_PUMP_PWM_PERCENT_OVERRIDE_REQUEST, &testRinsePumpPWMPercentOverride }, + { MSG_ID_DD_RINSE_PUMP_TURN_ON_OFF_REQUEST, &testRinsePumpTurnOnOffRequest }, { MSG_ID_FP_SET_START_STOP_OVERRIDE_REQUEST, &testSetGeneratePermeateSignal }, - { MSG_ID_FP_RO_REJECTION_RATIO_PUBLISH_INTERVAL_OVERRIDE_REQUEST, &testRORejectionRatioDataPublishIntervalOverride }, - { MSG_ID_FP_RO_FILTERED_REJECTION_RATIO_OVERRIDE_REQUEST, &testRORejectionRatioFilteredOverride }, + { MSG_ID_FP_RO_REJECTION_RATIO_PUBLISH_INTERVAL_OVERRIDE_REQUEST, &testRORejectionRatioDataPublishIntervalOverride }, + { MSG_ID_FP_RO_FILTERED_REJECTION_RATIO_OVERRIDE_REQUEST, &testRORejectionRatioFilteredOverride }, }; /// Calculation for number of entries in the incoming message function handler look-up table.