Index: firmware/App/Controllers/Valves.c =================================================================== diff -u -r7ce686fa967206c341805b79916298ae187854de -r9224712d825c7ecee623abc78d704fbd3c2dbde8 --- firmware/App/Controllers/Valves.c (.../Valves.c) (revision 7ce686fa967206c341805b79916298ae187854de) +++ firmware/App/Controllers/Valves.c (.../Valves.c) (revision 9224712d825c7ecee623abc78d704fbd3c2dbde8) @@ -1,5 +1,8 @@ // Includes +#include "reg_het.h" +#include "gio.h" + #include "Valves.h" #include "FPGA.h" #include "Timers.h" @@ -50,16 +53,17 @@ #define ADC_TO_CURRENT_CONVERSION_CONSTANT 2048.0 #define INITIAL_EDGE_OFFSET_READ_COUNT 100 -#define INITIAL_DEENERGIZED_POSITION ( 0 - INITIAL_EDGE_OFFSET_READ_COUNT ) -#define INITIAL_ENERGIZED_POSITION ( 12000 + INITIAL_EDGE_OFFSET_READ_COUNT ) +#define INITIAL_ENERGIZED_EDGE_UPPER_RANGE 13000U +#define INITIAL_ENERGIZED_EDGE_LOWER_RANGE 9000U + #define STEP_CHANGE_IN_COUNTS 1000 -#define MAX_POS_DEVIATION_FROM_TARGET_COUNTS 1000 //TODO test this tolerance -#define VALVE_TRANSITION_TIMEOUT_MS 5000 //TODO test the timeout -#define MAX_POSITION_DEVIATION_FROM_TARGET_IN_COUNTS 150U -#define MAX_ALLOWED_FAILED_HOMINGS 3U -#define HOMING_EDGE_DETECTION_TARGET_COUNTER 12U -#define VALVES_CURRENT_THRESHOLD_AMPS 1U +//#define MAX_POS_DEVIATION_FROM_TARGET_COUNTS 1000 //TODO test this tolerance +//#define VALVE_TRANSITION_TIMEOUT_MS 5000 //TODO test the timeout +#define MAX_DEVIATION_FROM_TARGET_IN_COUNTS 150U +#define MAX_ALLOWED_FAILED_HOMINGS 3U +#define HOMING_EDGE_DETECTION_TARGET_COUNTER 12U +#define VALVES_CURRENT_THRESHOLD_AMPS 1U #define OVER_CURRENT_COUNTER 100U #define OUT_OF_RANGE_COUNTER 100U @@ -158,6 +162,9 @@ { U08 i; + // To set the NHET direction to output + //gioSetDirection( hetPORT1, 1 ); + valveSelfTestState = VALVE_SELF_TEST_ENABLE_VALVES; valvesSelfTestResult = SELF_TEST_STATUS_IN_PROGRESS; @@ -234,7 +241,15 @@ *************************************************************************/ BOOL setValveBloodTrap( OPN_CLS_STATE_T state ) { - //TODO fill up the function + BOOL energized = FALSE; + + if ( state == STATE_OPEN ) + { + energized = TRUE; + } + + gioSetBit( hetPORT1, 0x12, energized ); + return TRUE; } @@ -463,14 +478,14 @@ S16 nextStep = 0; VALVE_POSITION_T commandedPositionEnum = valvesStatus[ valve ].commandedPosition; - VALVE_POSITION_T currentPositionEnum = valvesStatus[ valve ].currentPosition; + VALVE_POSITION_T currentPositionEnum = valvesStatus[ valve ].currentPosition; // Get the corresponding counts of the positions - S16 commandedPositionCounts = fabs( valvesStatus[ valve ].positions[ commandedPositionEnum ] ); - S16 currentPositionCounts = fabs( valvesStatus[ valve ].currentPositionInCounts ); + S16 commandedPositionCounts = valvesStatus[ valve ].positions[ commandedPositionEnum ]; + S16 currentPositionCounts = valvesStatus[ valve ].currentPositionInCounts; // Check if the valve is within range of the commanded position - if ( fabs( commandedPositionCounts - currentPositionCounts ) <= STEP_CHANGE_IN_COUNTS - 1 ) + if ( fabs( fabs(commandedPositionCounts) - fabs(currentPositionCounts) ) <= MAX_DEVIATION_FROM_TARGET_IN_COUNTS ) { // The valve is in range. Set the current position to the commanded position valvesStatus[ valve ].currentPosition = commandedPositionEnum; @@ -546,7 +561,6 @@ { // Get ready for the energized state valvesStatus[ valve ].homingEdgeDetectionCounter = 0; - valvesStatus[ valve ].numberOfFailedHomings = 0; valvesStatus[ valve ].targetPositionInCounts = STEP_CHANGE_IN_COUNTS; valvesStatus[ valve ].hasValveBeenHomed = FALSE; valvesStatus[ valve ].currentPosition = VALVE_POSITION_NOT_IN_POSITION; @@ -573,7 +587,9 @@ S16 currentPosition = valvesStatus[ valve ].currentPositionInCounts; S16 targetPosition = valvesStatus[ valve ].targetPositionInCounts; - if ( fabs( fabs(targetPosition) - fabs(currentPosition) ) > MAX_POSITION_DEVIATION_FROM_TARGET_IN_COUNTS && + S16 absDeltaPosition = fabs( fabs(currentPosition) - fabs(targetPosition) ); + + if ( absDeltaPosition > MAX_DEVIATION_FROM_TARGET_IN_COUNTS && ++valvesStatus[ valve ].homingEdgeDetectionCounter >= HOMING_EDGE_DETECTION_TARGET_COUNTER ) { // Current position (positive or negative) will be stored in the Position B of the current valve @@ -584,7 +600,7 @@ state = VALVE_STATE_HOMING_FIND_DEENERGIZED_EDGE; } - else if ( fabs( fabs(currentPosition) - fabs(targetPosition) ) <= MAX_POSITION_DEVIATION_FROM_TARGET_IN_COUNTS ) + else if ( absDeltaPosition <= MAX_DEVIATION_FROM_TARGET_IN_COUNTS ) { if ( ++valvesStatus[ valve ].valveRestCounter >= 0 ) //TODO add a #define for the rest time. Do we need the rest? { @@ -613,30 +629,50 @@ S16 currentPosition = valvesStatus[ valve ].currentPositionInCounts; S16 targetPosition = valvesStatus[ valve ].targetPositionInCounts; - if ( fabs( fabs(targetPosition) - fabs(currentPosition) ) > MAX_POSITION_DEVIATION_FROM_TARGET_IN_COUNTS && + S16 absDeltaPosition = fabs( fabs(currentPosition) - fabs(targetPosition) ); + + if ( absDeltaPosition > MAX_DEVIATION_FROM_TARGET_IN_COUNTS && ++valvesStatus[ valve ].homingEdgeDetectionCounter >= HOMING_EDGE_DETECTION_TARGET_COUNTER ) { - S16 positionB = valvesStatus[ valve ].positions[ VALVE_POSITION_B_OPEN ]; - // Positions B and C will have an offset from the edge to make sure each time the valve will not hit the edge - valvesStatus[ valve ].positions[ VALVE_POSITION_B_OPEN ] = positionB - INITIAL_EDGE_OFFSET_READ_COUNT; - valvesStatus[ valve ].positions[ VALVE_POSITION_C_CLOSE ] = currentPosition + INITIAL_EDGE_OFFSET_READ_COUNT; - // Position A is the average of the Position B that was read last time and position C that was - // the target of this state - valvesStatus[ valve ].positions[ VALVE_POSITION_A_INSERT_EJECT ] = ( valvesStatus[ valve ].positions[ VALVE_POSITION_B_OPEN ] + - valvesStatus[ valve ].positions[ VALVE_POSITION_C_CLOSE ] ) / 2; + S16 energizedEdge = valvesStatus[ valve ].positions[ VALVE_POSITION_B_OPEN ]; + S16 absEnergizedDelta = fabs( fabs(energizedEdge) - fabs(currentPosition) ); - // Set the current position to Position C and the commanded position to Position A - // Request a transition - valvesStatus[ valve ].hasValveBeenHomed = TRUE; - valvesStatus[ valve ].currentPosition = VALVE_POSITION_C_CLOSE; - valvesStatus[ valve ].commandedPosition = VALVE_POSITION_A_INSERT_EJECT; - valvesStatus[ valve ].hasTransitionBeenRequested = TRUE; - valvesStatus[ valve ].hasHomingBeenRequested = FALSE; + if ( absEnergizedDelta <= INITIAL_ENERGIZED_EDGE_UPPER_RANGE && absEnergizedDelta >= INITIAL_ENERGIZED_EDGE_LOWER_RANGE ) + { + S16 positionB = valvesStatus[ valve ].positions[ VALVE_POSITION_B_OPEN ]; + // Positions B and C will have an offset from the edge to make sure each time the valve will not hit the edge + valvesStatus[ valve ].positions[ VALVE_POSITION_B_OPEN ] = positionB - INITIAL_EDGE_OFFSET_READ_COUNT; + valvesStatus[ valve ].positions[ VALVE_POSITION_C_CLOSE ] = currentPosition + INITIAL_EDGE_OFFSET_READ_COUNT; + // Position A is the average of the Position B that was read last time and position C that was the target of this state + valvesStatus[ valve ].positions[ VALVE_POSITION_A_INSERT_EJECT ] = ( valvesStatus[ valve ].positions[ VALVE_POSITION_B_OPEN ] + + valvesStatus[ valve ].positions[ VALVE_POSITION_C_CLOSE ] ) / 2; - // Idle will initiate a transition - state = VALVE_STATE_IDLE; + // Set the current position to Position C and the commanded position to Position A + // Request a transition + valvesStatus[ valve ].hasValveBeenHomed = TRUE; + valvesStatus[ valve ].currentPosition = VALVE_POSITION_C_CLOSE; + valvesStatus[ valve ].commandedPosition = VALVE_POSITION_A_INSERT_EJECT; + valvesStatus[ valve ].hasTransitionBeenRequested = TRUE; + valvesStatus[ valve ].hasHomingBeenRequested = FALSE; + valvesStatus[ valve ].numberOfFailedHomings = 0; + + // Idle will initiate a transition + state = VALVE_STATE_IDLE; + } + // Max number of failed homing. Fault + else if ( ++valvesStatus[ valve ].numberOfFailedHomings >= MAX_ALLOWED_FAILED_HOMINGS ) + { + //TODO Alarm + valvesStatus[ valve ].hasValveBeenHomed = FALSE; + state = VALVE_STATE_IDLE; + } + else + { + state = VALVE_STATE_HOMING_NOT_STARTED; + } + } - else if ( fabs( fabs(currentPosition) - fabs(targetPosition) ) <= MAX_POSITION_DEVIATION_FROM_TARGET_IN_COUNTS ) + else if ( absDeltaPosition <= MAX_DEVIATION_FROM_TARGET_IN_COUNTS ) { if ( ++valvesStatus[ valve ].valveRestCounter >= 0 ) //TODO add a #define for the rest time. Do we need the rest? { @@ -870,14 +906,14 @@ // Check if the current position has deviated from the position it is supposed to be in // for more than a certain amount of time. If it has, raise an alarm - if ( fabs( currentPostion - commandedPoistion ) > MAX_POS_DEVIATION_FROM_TARGET_COUNTS && + if ( fabs( currentPostion - commandedPoistion ) > MAX_DEVIATION_FROM_TARGET_IN_COUNTS && ++valvesStatus[ i ].valvePositionOutOfRangeCounter > OUT_OF_RANGE_COUNTER ) { // TODO fault } // If the deviation came back to within the maximum amount and the time counter was > 0, // set the counter to 0 - else if ( fabs( currentPostion - commandedPoistion ) < MAX_POS_DEVIATION_FROM_TARGET_COUNTS && + else if ( fabs( currentPostion - commandedPoistion ) < MAX_DEVIATION_FROM_TARGET_IN_COUNTS && valvesStatus[ i ].valvePositionOutOfRangeCounter > 0 ) { valvesStatus[ i ].valvePositionOutOfRangeCounter = 0; Index: firmware/App/Services/SystemComm.c =================================================================== diff -u -r9d40104500ae1c144a19b36b83a0515d32fb7fc9 -r9224712d825c7ecee623abc78d704fbd3c2dbde8 --- firmware/App/Services/SystemComm.c (.../SystemComm.c) (revision 9d40104500ae1c144a19b36b83a0515d32fb7fc9) +++ firmware/App/Services/SystemComm.c (.../SystemComm.c) (revision 9224712d825c7ecee623abc78d704fbd3c2dbde8) @@ -1394,6 +1394,10 @@ handleHomeHDValve( message ); break; + case MSG_ID_HD_VALVES_SET_BLOOD_TRAP_VALVE: + handleSetBloodValve( message ); + break; + default: // TODO - unrecognized message ID received - ignore break; Index: firmware/App/Services/SystemCommMessages.c =================================================================== diff -u -r7ce686fa967206c341805b79916298ae187854de -r9224712d825c7ecee623abc78d704fbd3c2dbde8 --- firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision 7ce686fa967206c341805b79916298ae187854de) +++ firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision 9224712d825c7ecee623abc78d704fbd3c2dbde8) @@ -1152,6 +1152,7 @@ return result; } +// TODO remove this function BOOL broadcastFastTempHDValves() { BOOL result; @@ -2469,3 +2470,31 @@ sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, result ); } + +/*********************************************************************//** + * @brief + * The handleSetBloodValve function handles a request to set the HD air + * (blood) trap valve to open or close + * @details + * Inputs: none + * Outputs: message handled + * @param message a pointer to the message to handle + * @return none + *************************************************************************/ +void handleSetBloodValve( MESSAGE_T *message ) +{ + BOOL result = FALSE; + + if ( message->hdr.payloadLen == sizeof(U32) ) + { + OPN_CLS_STATE_T payload; + + memcpy( &payload, message->payload, sizeof(U32) ); + setValveBloodTrap( payload ); + + result = TRUE; + } + + // respond to request + sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, result ); +} Index: firmware/App/Services/SystemCommMessages.h =================================================================== diff -u -r2a2d6a224532304e29f948fc43711ee6e99f915b -r9224712d825c7ecee623abc78d704fbd3c2dbde8 --- firmware/App/Services/SystemCommMessages.h (.../SystemCommMessages.h) (revision 2a2d6a224532304e29f948fc43711ee6e99f915b) +++ firmware/App/Services/SystemCommMessages.h (.../SystemCommMessages.h) (revision 9224712d825c7ecee623abc78d704fbd3c2dbde8) @@ -164,7 +164,7 @@ BOOL broadcastHDValves(); // MSG_ID_TEMP_FAST_HD_VALVES_REMOVE_LATER -BOOL broadcastFastTempHDValves(); +BOOL broadcastFastTempHDValves(); //TODO remove this function #ifdef EMC_TEST_BUILD // MSG_ID_CAN_ERROR_COUNT @@ -325,6 +325,9 @@ // MSG_ID_HD_VALVES_POSITION_OVERRIDE void handleSetHDValvesPosition( MESSAGE_T *message ); + +// MSG_ID_HD_VALVES_SET_BLOOD_TRAP_VALVE +void handleSetBloodValve( MESSAGE_T *message ); #endif Index: firmware/HD.dil =================================================================== diff -u -rbf7c3835ce5a7bcbc47c305fb2fe5490d0899db8 -r9224712d825c7ecee623abc78d704fbd3c2dbde8 --- firmware/HD.dil (.../HD.dil) (revision bf7c3835ce5a7bcbc47c305fb2fe5490d0899db8) +++ firmware/HD.dil (.../HD.dil) (revision 9224712d825c7ecee623abc78d704fbd3c2dbde8) @@ -1,4 +1,4 @@ -# RM46L852PGE 06/14/20 15:02:15 +# RM46L852PGE 08/27/20 09:02:46 # ARCH=RM46L852PGE # @@ -6553,7 +6553,7 @@ DRIVER.HET.VAR.HET2_PWM7_PERIOD_LVL.VALUE=0x00000000 DRIVER.HET.VAR.HET1_EDGE2_BOTH.VALUE=0 DRIVER.HET.VAR.HET1_BIT26_DIR.VALUE=0x00000000 -DRIVER.HET.VAR.HET1_BIT18_DIR.VALUE=0x00000000 +DRIVER.HET.VAR.HET1_BIT18_DIR.VALUE=0x00040000 DRIVER.HET.VAR.HET2_PWM1_DUTY_INTENA.VALUE=0x00000000 DRIVER.HET.VAR.HET2_BIT16_XORSHARE.VALUE=0x00000000 DRIVER.HET.VAR.HET2_BIT5_PULDIS.VALUE=0x00000000 @@ -7253,7 +7253,7 @@ DRIVER.PINMUX.VAR.MUX14_OPTION5.VALUE=0 DRIVER.PINMUX.VAR.DMA_INTBTCEN_14.VALUE=1 DRIVER.PINMUX.VAR.MUX101_CONFLICT.VALUE=0 -DRIVER.PINMUX.VAR.PIN_MUX_50_SELECT.VALUE=1 +DRIVER.PINMUX.VAR.PIN_MUX_50_SELECT.VALUE=0 DRIVER.PINMUX.VAR.PIN_MUX_42_SELECT.VALUE=0 DRIVER.PINMUX.VAR.PIN_MUX_34_SELECT.VALUE=0 DRIVER.PINMUX.VAR.PIN_MUX_26_SELECT.VALUE=0 @@ -7297,7 +7297,7 @@ DRIVER.PINMUX.VAR.DMA_PRITY_16.VALUE=FIXED DRIVER.PINMUX.VAR.PINMUX33.VALUE="PINMUX_PIN_36_HET1_04 | PINMUX_PIN_51_MIBSPI3SOMI | PINMUX_PIN_52_MIBSPI3SIMO | PINMUX_PIN_53_MIBSPI3CLK" DRIVER.PINMUX.VAR.PINMUX17.VALUE="PINMUX_PIN_118_HET1_10 | PINMUX_PIN_124_HET1_12" -DRIVER.PINMUX.VAR.PINMUX34.VALUE="PINMUX_PIN_139_HET1_16 | PINMUX_PIN_140_ETPWM6A | PINMUX_PIN_141_HET1_20" +DRIVER.PINMUX.VAR.PINMUX34.VALUE="PINMUX_PIN_139_HET1_16 | PINMUX_PIN_140_HET1_18 | PINMUX_PIN_141_HET1_20" DRIVER.PINMUX.VAR.PINMUX18.VALUE="PINMUX_PIN_125_HET1_14 | PINMUX_PIN_126_GIOB_0" DRIVER.PINMUX.VAR.DMA_ADDMR_26_VALUE.VALUE=0x0001 DRIVER.PINMUX.VAR.DMA_CHANNEL_20_VALUE.VALUE=0x0001 @@ -7951,7 +7951,7 @@ DRIVER.PINMUX.VAR.DMA_IFT_COUNT_7.VALUE=0 DRIVER.PINMUX.VAR.DMA_BYP_13.VALUE=1 DRIVER.PINMUX.VAR.DMA_INTBTCEN_3.VALUE=1 -DRIVER.PINMUX.VAR.MUX50_OPTION1.VALUE=1 +DRIVER.PINMUX.VAR.MUX50_OPTION1.VALUE=0 DRIVER.PINMUX.VAR.MUX42_OPTION1.VALUE=0 DRIVER.PINMUX.VAR.MUX34_OPTION1.VALUE=0 DRIVER.PINMUX.VAR.MUX26_OPTION1.VALUE=0 Index: firmware/include/het.h =================================================================== diff -u -r0a0b6c446cd0f428af75b28e6ca8206bbcf148ac -r9224712d825c7ecee623abc78d704fbd3c2dbde8 --- firmware/include/het.h (.../het.h) (revision 0a0b6c446cd0f428af75b28e6ca8206bbcf148ac) +++ firmware/include/het.h (.../het.h) (revision 9224712d825c7ecee623abc78d704fbd3c2dbde8) @@ -345,6 +345,7 @@ | (uint32)0x00000000U \ | (uint32)0x00000000U \ | (uint32)0x00000000U \ + | (uint32)0x00040000U \ | (uint32)0x00000000U \ | (uint32)0x00000000U \ | (uint32)0x00000000U \ @@ -362,7 +363,6 @@ | (uint32)0x00000000U \ | (uint32)0x00000000U \ | (uint32)0x00000000U \ - | (uint32)0x00000000U \ | (uint32)0x00000000U) #define HET1_PDR_CONFIGVALUE ((uint32)0x00000000U \ Index: firmware/source/het.c =================================================================== diff -u -rbf7c3835ce5a7bcbc47c305fb2fe5490d0899db8 -r9224712d825c7ecee623abc78d704fbd3c2dbde8 --- firmware/source/het.c (.../het.c) (revision bf7c3835ce5a7bcbc47c305fb2fe5490d0899db8) +++ firmware/source/het.c (.../het.c) (revision 9224712d825c7ecee623abc78d704fbd3c2dbde8) @@ -1124,6 +1124,7 @@ | (uint32) 0x00000000U | (uint32) 0x00000000U | (uint32) 0x00000000U + | (uint32) 0x00040000U | (uint32) 0x00000000U | (uint32) 0x00000000U | (uint32) 0x00000000U @@ -1141,7 +1142,6 @@ | (uint32) 0x00000000U | (uint32) 0x00000000U | (uint32) 0x00000000U - | (uint32) 0x00000000U | (uint32) 0x00000000U; /** - Set HET pins open drain enable */ Index: firmware/source/pinmux.c =================================================================== diff -u -ra74a984a7059f75d86ad87d6d9499bd8f94cc976 -r9224712d825c7ecee623abc78d704fbd3c2dbde8 --- firmware/source/pinmux.c (.../pinmux.c) (revision a74a984a7059f75d86ad87d6d9499bd8f94cc976) +++ firmware/source/pinmux.c (.../pinmux.c) (revision 9224712d825c7ecee623abc78d704fbd3c2dbde8) @@ -236,7 +236,7 @@ pinMuxReg->PINMMR33 = PINMUX_PIN_36_HET1_04 | PINMUX_PIN_51_MIBSPI3SOMI | PINMUX_PIN_52_MIBSPI3SIMO | PINMUX_PIN_53_MIBSPI3CLK; - pinMuxReg->PINMMR34 = PINMUX_PIN_139_HET1_16 | PINMUX_PIN_140_ETPWM6A | PINMUX_PIN_141_HET1_20; + pinMuxReg->PINMMR34 = PINMUX_PIN_139_HET1_16 | PINMUX_PIN_140_HET1_18 | PINMUX_PIN_141_HET1_20; /* USER CODE BEGIN (3) */