Index: firmware/App/Controllers/Valves.c =================================================================== diff -u -reef24091316f7c4b5717e72fef7ca06e58fc174a -r5e92f2578534a1f51e10d181d2566939b890e687 --- firmware/App/Controllers/Valves.c (.../Valves.c) (revision eef24091316f7c4b5717e72fef7ca06e58fc174a) +++ firmware/App/Controllers/Valves.c (.../Valves.c) (revision 5e92f2578534a1f51e10d181d2566939b890e687) @@ -43,7 +43,7 @@ #define VALVE_FORCE_HOME TRUE ///< Force valve to home even if already homed. #define ZERO_ENC_DEBOUNCE_THRESHOLD_CNT 5 ///< Valves zero encoder debounce threshold count. #define ZERO_ENC_DEBOUNCE_TIMEOUT_MS ( 0.25 * MS_PER_SECOND ) ///< Valves zero encoder debounce timeout in milliseconds. -#define VALVE_OFFEST_FROM_EDG_CNT 200 ///< Valves offset from the edge. +#define VALVE_OFFEST_FROM_EDG_CNT 320 ///< Valves offset from the edge. #define POS_C_FROM_ZERO_CNT VALVE_OFFEST_FROM_EDG_CNT ///< Position C from zero position in counts. #define POS_D_PARTIAL_CLOSE_FROM_ZERO_CNT ( POS_C_FROM_ZERO_CNT + 32 ) ///< Position D partial close from zero position in counts. @@ -268,8 +268,8 @@ for ( valve = FIRST_VALVE; valve < NUM_OF_VALVES; valve++ ) { // Update valve encoder positions - currentValveStates[ valve ].priorEncPosition = currentValveStates[ valve ].currentEncPosition; - currentValveStates[ valve ].currentEncPosition = getValveEncoderPosition( valve ); + currentValveStates[ valve ].priorEncPosition = currentValveStates[ valve ].currentEncPosition; + currentValveStates[ valve ].currentEncPosition = getValveEncoderPosition( valve ); // Update valve max encoder positions currentValveStates[ valve ].previousMaxEncPositionCnt = currentValveStates[ valve ].currentMaxEncPositionCnt; currentValveStates[ valve ].currentMaxEncPositionCnt = getValveMaximumEncoderPosition( valve ); @@ -473,31 +473,6 @@ checkValveInRange( valve, SW_FAULT_ID_TD_VALVES_INVALID_FIND_ENERGIZED_EDGE ); - // TODO remove - //S16 currPos = currentValveStates[ valve ].currentEncPosition; - //BOOL hasEdgeBeenReached = FALSE; - //// have we found forward edge of travel? - //if ( abs( currPos - currentValveStates[ valve ].priorEncPosition ) < VALVE_HOME_MIN_POS_CHG ) - //{ - // if ( 0 == currentValveStates[ valve ].valveOpsStartTime ) - // { - // currentValveStates[ valve ].valveOpsStartTime = getMSTimerCount(); - // } - // else if ( TRUE == didTimeout( currentValveStates[ valve ].valveOpsStartTime, HOMING_EDGE_DETECTION_TIMEOUT_MS ) ) - // { - // hasEdgeBeenReached = TRUE; - // currPos -= VALVE_OFFEST_FROM_EDG_CNT; - // } - //} - //else if ( currPos <= 100 ) - //{ - // // Lost the shaft. Get the maximum value in the special register as the maximum. - // S16 maxEncPosition = getValveMaximumEncoderPosition( valve ); - // - // hasEdgeBeenReached = TRUE; - // currPos = maxEncPosition - VALVE_OFFEST_FROM_EDG_CNT; - //} - if ( TRUE == hasEdgeBeenReached( valve ) ) { nextState = VALVE_STATE_HOMING_FIND_DEENERGIZED_EDGE; @@ -518,6 +493,9 @@ static VALVE_STATE_T handleValvesFindDeenergizedEdgeState( VALVE_T valve ) { VALVE_STATE_T nextState = VALVE_STATE_HOMING_FIND_DEENERGIZED_EDGE; + S16 posB = 0; + S16 posC = 0; + S16 posA = 0; checkValveInRange( valve, SW_FAULT_ID_TD_VALVES_INVALID_FIND_DEENERGIZED_EDGE ); @@ -529,10 +507,9 @@ // TODO in the future this needs to be searched currentValveStates[ valve ].positionsABC[ VALVE_POSITION_D_PARTIAL_CLOSE ] = POS_D_PARTIAL_CLOSE_FROM_ZERO_CNT; - S16 posB = currentValveStates[ valve ].positionsABC[ VALVE_POSITION_B_OPEN ]; - S16 posC = currentValveStates[ valve ].positionsABC[ VALVE_POSITION_C_CLOSE ]; - S16 posA = posC + ( ( posB - posC ) / 2 ); - + posB = currentValveStates[ valve ].positionsABC[ VALVE_POSITION_B_OPEN ]; + posC = currentValveStates[ valve ].positionsABC[ VALVE_POSITION_C_CLOSE ]; + posA = posC + ( ( posB - posC ) / 2 ); posA = convertCountToDivision8( posA ); currentValveStates[ valve ].positionsABC[ VALVE_POSITION_A_INSERT_EJECT ] = posA; @@ -689,13 +666,12 @@ *************************************************************************/ static BOOL hasEdgeBeenReached( VALVE_T valve ) { - BOOL status = FALSE; - - checkValveInRange( valve, SW_FAULT_ID_VALVES_INVALID_VALVE_FINDING_EDGE ); - + BOOL status = FALSE; S16 previousMaxEnc = currentValveStates[ valve ].previousMaxEncPositionCnt; S16 currentMaxEnc = currentValveStates[ valve ].currentMaxEncPositionCnt; + checkValveInRange( valve, SW_FAULT_ID_VALVES_INVALID_VALVE_FINDING_EDGE ); + if ( abs( currentMaxEnc - previousMaxEnc ) < VALVE_HOME_MIN_POS_CHG ) { if ( 0 == currentValveStates[ valve ].valveOpsStartTime ) @@ -721,6 +697,10 @@ //} } } + else + { + currentValveStates[ valve ].valveOpsStartTime = 0; + } return status; } @@ -736,8 +716,13 @@ *************************************************************************/ static S16 convertCountToDivision8( S16 count ) { + S16 convCount = 0; + // If position A was calculated to not be a division of 8 it is rounded down to be a division of 8 - S16 convCount = ( count % ROTARY_VALVE_MICROSTEP_FRACTION ) < 4 ? ( count >> 3 ) << 3 : count; + if ( ( count % ROTARY_VALVE_MICROSTEP_FRACTION ) < 4 ) + { + convCount = ( count >> 3 ) << 3; + } return convCount; }