Index: firmware/App/Controllers/Valves.c =================================================================== diff -u -r575f9b78ced835f11c015d652be1bd8b83fc9578 -r3aed94a6a0af49bed46f25c900f74e98997ac2e7 --- firmware/App/Controllers/Valves.c (.../Valves.c) (revision 575f9b78ced835f11c015d652be1bd8b83fc9578) +++ firmware/App/Controllers/Valves.c (.../Valves.c) (revision 3aed94a6a0af49bed46f25c900f74e98997ac2e7) @@ -87,7 +87,8 @@ #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_HOMING_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 @@ -680,7 +681,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_HOMING_CNTS ) { if ( valvesStatus[ valve ].homingEdgeDetectionCounter >= HOMING_EDGE_DETECTION_TIME_INTERVAL ) { @@ -725,10 +726,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_HOMING_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 ]; @@ -737,15 +738,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 ) )