Index: firmware/.launches/HD.launch =================================================================== diff -u -r8b3285681e02f365746d148315b32ea603f2d6e0 -r316e7117180362d54af53818822694c4f936e550 --- firmware/.launches/HD.launch (.../HD.launch) (revision 8b3285681e02f365746d148315b32ea603f2d6e0) +++ firmware/.launches/HD.launch (.../HD.launch) (revision 316e7117180362d54af53818822694c4f936e550) @@ -4,7 +4,7 @@ - + Index: firmware/App/Common.h =================================================================== diff -u -r8b3285681e02f365746d148315b32ea603f2d6e0 -r316e7117180362d54af53818822694c4f936e550 --- firmware/App/Common.h (.../Common.h) (revision 8b3285681e02f365746d148315b32ea603f2d6e0) +++ firmware/App/Common.h (.../Common.h) (revision 316e7117180362d54af53818822694c4f936e550) @@ -24,7 +24,7 @@ #ifndef _VECTORCAST_ #define RM46_EVAL_BOARD_TARGET 1 // #define SIMULATE_UI 1 -//leo-cb #define DEBUG_ENABLED 1 +// #define DEBUG_ENABLED 1 #ifdef DEBUG_ENABLED #include Index: firmware/App/Controllers/DialOutFlow.c =================================================================== diff -u -re7e4d0d8f84b61de25fe21ecf9aa11b2732b598d -r316e7117180362d54af53818822694c4f936e550 --- firmware/App/Controllers/DialOutFlow.c (.../DialOutFlow.c) (revision e7e4d0d8f84b61de25fe21ecf9aa11b2732b598d) +++ firmware/App/Controllers/DialOutFlow.c (.../DialOutFlow.c) (revision 316e7117180362d54af53818822694c4f936e550) @@ -55,6 +55,7 @@ #define DIAL_OUT_FLOW_SAMPLE_FREQ ( MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) +#define DIAL_OUT_CONTROLLER_SAMPLE_FREQ ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) // dialOut pump stop and direction macros #define STOP_DO_PUMP_SPI4_PORT_MASK 0x00000200 // (SPI4CLK - re-purposed as output GPIO) @@ -85,10 +86,10 @@ static U32 dialOutFlowDataPublicationTimerCounter = 5; // used to schedule dialIn flow data publication to CAN bus // Rx values -static F32 rxTotalTargetVolumeInMl; -static U32 rxTargetTimeInSamples; -static F32 rxInitialTargetFlowRatePWM; -static F32 targetVolumeUFRatePerSample; +static volatile F32 rxTotalTargetVolumeInMl; +static volatile U32 rxTargetTimeInSamples; +static volatile F32 rxInitialTargetFlowRatePWM; +static volatile F32 targetVolumeUFRatePerSample; // Variables used in loop @@ -100,15 +101,20 @@ static F32 bagMeasuredUFVolumeInMl; static F32 accumulativeTotalUFVolumeInMl; -static F32 totalMeasuredUFVolumeInMl; -static F32 totalTargetUFVolumeInMl; +static volatile F32 totalMeasuredUFVolumeInMl; +static volatile F32 totalTargetUFVolumeInMl; -static F32 sentPWM; +static volatile F32 sentPWM; +static volatile U32 targetVolumeTimer; // Pump variables static F32 dialOutPumpSpeedInRPM; static F32 dialOutPumpCurrentInMA; +// Simulator +static volatile F32 simulator_volume_in_ml_per_min; +static volatile F32 simulator_inlet_flow_rate; + // ********** private function prototypes ********** static DIALOUT_FLOW_STATE_T handleDialOutFlowStopState( void ); @@ -123,7 +129,10 @@ static void publishDialOutFlowData( void ); +static F32 UFSimulator( F32 pwm ); +static void ResetSimulator( void ); + /************************************************************************* * @brief setDialOutFlowNewState * The setDialOutNew function changes the state to STOP, PAUSE or RUN. @@ -137,14 +146,20 @@ switch( newState ) { case DIALOUT_FLOW_RUN_UF_STATE: + break; case DIALOUT_FLOW_PAUSE_UF_STATE: - if( isNewBag ) - { - bagStartVolumeInMl = 0.0; - } + bagStartVolumeInMl = (isNewBag == TRUE) ? 0.0 : bagStartVolumeInMl; break; case DIALOUT_FLOW_STOP_STATE: + // Reset total target volume + totalTargetUFVolumeInMl = 0.0; + accumulativeTotalUFVolumeInMl = 0.0; + bagStartVolumeInMl = 0.0; + sentPWM = 0.0; + bagStartVolumeInMl = (isNewBag == TRUE) ? 0.0 : bagStartVolumeInMl; + ResetSimulator(); + stopDialOutPump(); break; default: @@ -176,7 +191,7 @@ *************************************************************************/ static void updateTargetVolume( void ) { - rxTotalTargetVolumeInMl += targetVolumeUFRatePerSample; + totalTargetUFVolumeInMl += targetVolumeUFRatePerSample; } /************************************************************************* @@ -189,7 +204,7 @@ * @param rxFlowRateinMlPerMin * @return none *************************************************************************/ -BOOL setDialOutFlowRxTotalVolumeAndRxTime( U32 rxTotaVolumeInMl, U32 rxTotalTimeInMinutes, U32 rxFlowRateinMlPerMin) +BOOL setDialOutFlowRxTotalVolumeAndRxTime( U16 rxTotaVolumeInMl, U16 rxTotalTimeInMinutes, U16 rxFlowRateinMlPerMin) { #define SECS_IN_MIN 60 @@ -204,12 +219,32 @@ BOOL returnValue = TRUE; - rxTotalTargetVolumeInMl = rxTotaVolumeInMl; - rxTargetTimeInSamples = rxTotalTimeInMinutes * SEC_PER_MIN * DIAL_OUT_FLOW_SAMPLE_FREQ ; - rxInitialTargetFlowRatePWM = DOP_PWM_FROM_ML_PER_MIN(rxFlowRateinMlPerMin); + totalTargetUFVolumeInMl = 0.0; + simulator_inlet_flow_rate = (F32) rxFlowRateinMlPerMin; + + rxTotalTargetVolumeInMl = (F32) rxTotaVolumeInMl; + rxTargetTimeInSamples = (U32) rxTotalTimeInMinutes * SEC_PER_MIN * DIAL_OUT_CONTROLLER_SAMPLE_FREQ ; + rxInitialTargetFlowRatePWM = RANGE(DOP_PWM_FROM_ML_PER_MIN(rxFlowRateinMlPerMin), MIN_DIAL_OUT_PUMP_PWM_DUTY_CYCLE, MAX_DIAL_OUT_PUMP_PWM_DUTY_CYCLE); + + resetPIController( PI_CONTROLLER_ID_LOAD_CELL, rxInitialTargetFlowRatePWM ); + + targetVolumeUFRatePerSample = (F32) rxTotalTargetVolumeInMl / (F32) rxTargetTimeInSamples; + #ifdef DEBUG_ENABLED + // TODO - temporary debug code - remove later + char debugFlowStr[ 128 ]; + + sprintf( debugFlowStr, "target:%5.4f, time:%5d, InitTarget:%6.4f, RatePerSample:%8.4f", + rxTotalTargetVolumeInMl, + rxTargetTimeInSamples, + rxInitialTargetFlowRatePWM, + targetVolumeUFRatePerSample ); + + sendDebugData( (U08*)debugFlowStr, strlen(debugFlowStr) ); + #endif + return returnValue; } @@ -221,16 +256,12 @@ *************************************************************************/ void initDialOutFlow( void ) { - dialOutFlowState = DIALOUT_FLOW_STOP_STATE; - totalTargetUFVolumeInMl = 0.0; - stopDialOutPump(); setDialOutPumpDirection( MOTOR_DIR_FORWARD ); initializeFilter(FILTER_ID_LOAD_CELL_WEIGHT, 0); - bagStartVolumeInMl = 0.0; - accumulativeTotalUFVolumeInMl = 0.0; + setDialOutFlowNewState( DIALOUT_FLOW_STOP_STATE , TRUE ); // initialize dialysate outlet flow PI controller initializePIController( PI_CONTROLLER_ID_LOAD_CELL, rxInitialTargetFlowRatePWM, @@ -293,9 +324,42 @@ // publish dialIn flow data on interval + bagMeasuredUFVolumeInMl = loadCellVolumeInMl - bagStartVolumeInMl; + totalMeasuredUFVolumeInMl = bagMeasuredUFVolumeInMl + accumulativeTotalUFVolumeInMl; + + totalMeasuredUFVolumeInMl = UFSimulator(sentPWM); + + publishDialOutFlowData(); } +/* + * TODO: Delete UFSimulator when hardware is ready + */ + +F32 UFSimulator(F32 pwm) { + F32 flow; + + if(dialOutFlowState == DIALOUT_FLOW_STOP_STATE) + { + flow = 0; + } + else + { + flow = ( ((678.0*pwm - simulator_inlet_flow_rate - 67.80) * (F32) TASK_PRIORITY_INTERVAL )/ (F32) MS_PER_SECOND ); + } + simulator_volume_in_ml_per_min += flow; + + return simulator_volume_in_ml_per_min; +} + +/* + * TODO: Delete ResetSimulator when hardware is ready. + */ +void ResetSimulator() { + simulator_volume_in_ml_per_min = 0.0; +} + /************************************************************************* * @brief execDialOutFlowController * The execDialOutFlowController function executes the dialIn flow controller. @@ -341,6 +405,8 @@ { DIALOUT_FLOW_STATE_T result = DIALOUT_FLOW_STOP_STATE; + targetVolumeTimer = 0; + stopDialOutPump(); return result; @@ -452,7 +518,6 @@ // publish dialIn flow data on interval if ( ++dialOutFlowDataPublicationTimerCounter > DIAL_OUT_FLOW_DATA_PUB_INTERVAL ) { - //leo-del dialOutFlowState = dialOutFlowState == DIALOUT_FLOW_STOP_STATE ? DIALOUT_FLOW_RUN_UF_STATE : DIALOUT_FLOW_STOP_STATE; #ifdef DEBUG_ENABLED // TODO - temporary debug code - remove later char debugFlowStr[ 128 ]; Index: firmware/App/Controllers/DialOutFlow.h =================================================================== diff -u -r5a8668a1a04cfa46b1a0aeece4f527ebbf26a106 -r316e7117180362d54af53818822694c4f936e550 --- firmware/App/Controllers/DialOutFlow.h (.../DialOutFlow.h) (revision 5a8668a1a04cfa46b1a0aeece4f527ebbf26a106) +++ firmware/App/Controllers/DialOutFlow.h (.../DialOutFlow.h) (revision 316e7117180362d54af53818822694c4f936e550) @@ -38,12 +38,11 @@ // Rx setting can be done in DIALOUT_FLOW_STOP_STATE and DIALOUT_FLOW_PAUSE_UF_STATE BOOL resetDialOutFlowRx(); -BOOL setDialOutFlowRxTotalVolumeAndRxTime( U32 rxTotaVolume, U32 rxTotalTimeInMinutes, U32 rxFlowRate); DIALOUT_FLOW_STATE_T getDialOutFlowState( void ); BOOL setdialOutFlowState( DIALOUT_FLOW_STATE_T setNewState ); void setDialOutFlowNewState( DIALOUT_FLOW_STATE_T newState , BOOL isNewBag ); -BOOL setDialOutFlowRxTotalVolumeAndRxTime( U32 rxTotaVolumeInMl, U32 rxTotalTimeInMinutes, U32 rxFlowRateinMlPerMin); +BOOL setDialOutFlowRxTotalVolumeAndRxTime( U16 rxTotaVolumeInMl, U16 rxTotalTimeInMinutes, U16 rxFlowRateinMlPerMin); Index: firmware/App/Services/PIControllers.c =================================================================== diff -u -rf8395d7271a1fbcb2e577ce48b9327b16d2b97e0 -r316e7117180362d54af53818822694c4f936e550 --- firmware/App/Services/PIControllers.c (.../PIControllers.c) (revision f8395d7271a1fbcb2e577ce48b9327b16d2b97e0) +++ firmware/App/Services/PIControllers.c (.../PIControllers.c) (revision 316e7117180362d54af53818822694c4f936e550) @@ -136,7 +136,7 @@ controller->referenceSignal = referenceSignal; controller->measuredSignal = measuredSignal; // calculate error signal - controller->errorSignal = fabs( referenceSignal ) - ( referenceSignal < 0.0 ? ( measuredSignal * -1.0 ) : measuredSignal ); + controller->errorSignal = referenceSignal-measuredSignal;//fabs( referenceSignal ) - ( referenceSignal < 0.0 ? ( measuredSignal * -1.0 ) : measuredSignal ); controller->errorSum += controller->errorSignal; // anti-windup controller->errorSumBeforeWindUp = controller->errorSum; Index: firmware/App/Services/SystemCommMessages.c =================================================================== diff -u -re7e4d0d8f84b61de25fe21ecf9aa11b2732b598d -r316e7117180362d54af53818822694c4f936e550 --- firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision e7e4d0d8f84b61de25fe21ecf9aa11b2732b598d) +++ firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision 316e7117180362d54af53818822694c4f936e550) @@ -864,9 +864,9 @@ DATA_OVERRIDE_HANDLER_FUNC( U32, handleTestDialFlowBroadcastIntervalOverrideRequest, testSetDialInFlowDataPublishIntervalOverride, testResetDialInFlowDataPublishIntervalOverride ) /************************************************************************* - * @brief handleTesterLogInRequest - * The handleTesterLogInRequest function handles a request to login as a \n - * tester. + * @brief handleDialOutFlowRx + * The handleDialOutFlowRx function handles a request to set the Rx values + * of the DialOut Flow system. * @details * Inputs : none * Outputs : message handled @@ -875,13 +875,13 @@ *************************************************************************/ void handleDialOutFlowRx( MESSAGE_T *message ) { - U32 rxVolumeInMl = * ( (U32*) (&message->payload[0]) ); - U32 timeInMinutes = * ( (U32*) (&message->payload[4]) ); - U32 FlowRateInMlMin = * ( (U32*) (&message->payload[8]) ); + U32 rxVolumeInMl = * ( (U16*) (&message->payload[0]) ); + U32 timeInMinutes = * ( (U16*) (&message->payload[2]) ); + U32 FlowRateInMlMin = * ( (U16*) (&message->payload[4]) ); BOOL areArgumentsValid = FALSE; - if ( ( 12 == message->hdr.payloadLen ) ) + if ( ( 6 == message->hdr.payloadLen ) ) { areArgumentsValid = setDialOutFlowRxTotalVolumeAndRxTime( rxVolumeInMl, timeInMinutes, FlowRateInMlMin); }