Index: firmware/App/Controllers/Valves.c =================================================================== diff -u -r5a5eda0e64a8990f5adecae65c035bfaeb77d8dd -rca1d817247bb037d238f611b99f01a0577b4c71c --- firmware/App/Controllers/Valves.c (.../Valves.c) (revision 5a5eda0e64a8990f5adecae65c035bfaeb77d8dd) +++ firmware/App/Controllers/Valves.c (.../Valves.c) (revision ca1d817247bb037d238f611b99f01a0577b4c71c) @@ -8,7 +8,7 @@ * @file Valves.c * * @author (last) Dara Navaei -* @date (last) 26-May-2022 +* @date (last) 01-Sep-2022 * * @author (original) Dara Navaei * @date (original) 07-Aug-2020 @@ -79,15 +79,16 @@ #define INITIAL_EDGE_OFFSET_READ_COUNT 100U ///< Offset in counts from energized and de-energized edges -#define INITIAL_ENERGIZED_EDGE_UPPER_RANGE 13000U ///< Energized edge maximum count +#define INITIAL_ENERGIZED_EDGE_UPPER_RANGE 14000U ///< Energized edge maximum count (originally 13000 count) #define INITIAL_ENERGIZED_EDGE_LOWER_RANGE 9000U ///< Energized edge minimum count #define AIR_TRAP_VALVE_GPIO_PIN 0x12 ///< Air trap valve GPIO Pin 18 of HET Port 1 #define HOMING_STEP_CHANGE_IN_COUNTS 1000 ///< Step change in counts during homing #define TRANSITION_STEP_CHANGE_IN_COUNTS 15000 ///< Step change in counts during normal operations -#define MAX_DEVIATION_FROM_TARGET_IN_COUNTS 150 ///< Maximum deviation from target in counts +#define MAX_DEVIATION_FROM_TARGET_IN_COUNTS 2500 ///< Maximum deviation from target in counts +#define MAX_DEVIATION_FROM_TGT_IN_TRAVEL_CNTS 150 ///< Maximum deviation from target in counts #define MAX_DEVIATION_FROM_TRAGET_IN_POS_B 1000 ///< Maximum allowed deviation from position B in counts #define MAX_ALLOWED_FAILED_HOMINGS 3U ///< Maximum allowed failed homings /// The time that the valve must be at the edge to be considered for edge detection @@ -295,11 +296,11 @@ /*********************************************************************//** * @brief - * The homeValve function sets the homing request flag of a valve to TRUE. - * @details Inputs: none - * @details Outputs: valvesStatus (The flag that sets the homing request) + * The homeValve function processes the homing of a valve + * @details Inputs: valvesStatus + * @details Outputs: valvesStatus * @param valve that is set to be homed - * @return none + * @return TRUE if the homing command accepted otherwise, FALSE *************************************************************************/ BOOL homeValve( VALVE_T valve ) { @@ -664,7 +665,7 @@ S16 deltaPosition = targetPosition - currentPosition; // If there has not been any major travel for a certain period of time - if ( deltaPosition > MAX_DEVIATION_FROM_TARGET_IN_COUNTS ) + if ( deltaPosition > MAX_DEVIATION_FROM_TGT_IN_TRAVEL_CNTS ) { if ( valvesStatus[ valve ].homingEdgeDetectionCounter >= HOMING_EDGE_DETECTION_TIME_INTERVAL ) { @@ -709,10 +710,10 @@ S16 targetPosition = valvesStatus[ valve ].targetPositionInCounts; S16 deltaPosition = currentPosition - targetPosition; - // If there has not been any major travel - if ( deltaPosition > MAX_DEVIATION_FROM_TARGET_IN_COUNTS ) + // Still too far from intermediate target position? Either still more travel to go or stuck at end of travel + if ( deltaPosition > MAX_DEVIATION_FROM_TGT_IN_TRAVEL_CNTS ) { - // Check if the specified time has elapsed + // Are we stuck at end of travel? if ( valvesStatus[ valve ].homingEdgeDetectionCounter >= HOMING_EDGE_DETECTION_TIME_INTERVAL ) { S16 energizedEdge = valvesStatus[ valve ].positions[ VALVE_POSITION_B_OPEN ]; @@ -721,15 +722,15 @@ // The range from energized to de-energized should be in between 9000 to 13000 steps if ( deltaEdges <= INITIAL_ENERGIZED_EDGE_UPPER_RANGE && deltaEdges >= INITIAL_ENERGIZED_EDGE_LOWER_RANGE ) { - S16 positionB = valvesStatus[ valve ].positions[ VALVE_POSITION_B_OPEN ]; + S16 positionC = currentPosition + INITIAL_EDGE_OFFSET_READ_COUNT; + S16 positionB = valvesStatus[ valve ].positions[ VALVE_POSITION_B_OPEN ] - INITIAL_EDGE_OFFSET_READ_COUNT; // 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_B_OPEN ] = positionB; + valvesStatus[ valve ].positions[ VALVE_POSITION_C_CLOSE ] = positionC; - 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; + valvesStatus[ valve ].positions[ VALVE_POSITION_A_INSERT_EJECT ] = positionC + ( ( positionB - positionC ) / 2 ); #ifndef _RELEASE_ if ( ( getSoftwareConfigStatus( SW_CONFIG_ENABLE_VBA_SPECIAL_POSITION_C ) == SW_CONFIG_ENABLE_VALUE ) && ( VBA == valve ) ) @@ -858,7 +859,7 @@ if ( commandedPositionEnum == VALVE_POSITION_B_OPEN ) { // Enable current relaxation - setFPGAValveSetPoint( valve, currentPosition, TRUE ); + setFPGAValveSetPoint( valve, targetPosition, TRUE ); } // Go back to Idle state @@ -878,7 +879,7 @@ } } // Check if the valve is close to the temporary target position and if it is, assign the next target position - else if ( abs( currentPosition - targetPosition ) < MAX_DEVIATION_FROM_TARGET_IN_COUNTS ) + else if ( abs( currentPosition - targetPosition ) < MAX_DEVIATION_FROM_TGT_IN_TRAVEL_CNTS ) { setValveNextStep( valve, TRANSITION_STEP_CHANGE_IN_COUNTS ); } @@ -1166,7 +1167,7 @@ { U32 maxDeviation = MAX_DEVIATION_FROM_TARGET_IN_COUNTS; - currentPosition = getValvePositionCounts( valve ); + currentPosition = getValvePositionCounts( valve ); commandedPositionEnum = valvesStatus[ valve ].commandedPosition; commandedPosition = valvesStatus[ valve ].positions[ commandedPositionEnum ]; @@ -1271,22 +1272,22 @@ // Subtract the defined number of steps for the next transition if ( commandedPositionEnum == VALVE_POSITION_B_OPEN ) { - valvesStatus[ valve ].targetPositionInCounts = getValvePositionCounts( valve ) + nextStep; + valvesStatus[ valve ].targetPositionInCounts = currentPosition + nextStep; } if ( commandedPositionEnum == VALVE_POSITION_C_CLOSE ) { - valvesStatus[ valve ].targetPositionInCounts = getValvePositionCounts( valve ) - nextStep; + valvesStatus[ valve ].targetPositionInCounts = currentPosition - nextStep; } break; case VALVE_POSITION_B_OPEN: // If the valve is currently in position B, subtract the defined number of steps for the next transition - valvesStatus[ valve ].targetPositionInCounts = getValvePositionCounts( valve ) - nextStep; + valvesStatus[ valve ].targetPositionInCounts = currentPosition - nextStep; break; case VALVE_POSITION_C_CLOSE: // If the valve is currently in position C, add the defined number of steps for the next transition - valvesStatus[ valve ].targetPositionInCounts = getValvePositionCounts( valve ) + nextStep; + valvesStatus[ valve ].targetPositionInCounts = currentPosition + nextStep; break; default: