Index: firmware/App/Controllers/Valves.c =================================================================== diff -u -r8de3c971a08a5e2d822a6a1d1d1c477b6d4cbd5b -r6b4296cf35c80f2a8858020517cbfc48181144c7 --- firmware/App/Controllers/Valves.c (.../Valves.c) (revision 8de3c971a08a5e2d822a6a1d1d1c477b6d4cbd5b) +++ firmware/App/Controllers/Valves.c (.../Valves.c) (revision 6b4296cf35c80f2a8858020517cbfc48181144c7) @@ -449,7 +449,7 @@ } else { - // First enable the valve and then set the position to 0 to clear the FPGA command regitsters + // First enable the valve and then set the position to 0 to clear the FPGA command registers switch ( valve ) { case H1_VALV: @@ -521,9 +521,9 @@ currentValveStates[ valve ].valveOpsStartTime = 0; currentValveStates[ valve ].hasValveBeenHomed = FALSE; currentValveStates[ valve ].currentPosition = VALVE_POSITION_NOT_IN_POSITION; + nextState = VALVE_STATE_HOMING_FIND_ENERGIZED_EDGE; setValveCmdChangePosition( valve, (U16)currentValveStates[ valve ].proposedEnergizedPos, MOTOR_DIR_FORWARD ); - nextState = VALVE_STATE_HOMING_FIND_ENERGIZED_EDGE; } return nextState; @@ -572,7 +572,7 @@ S16 posA = posC + ( curPos / 2 ); // If position A was calculated to not be a division of 8 it is rounded down to be a division of 8 - posA = ( posA % ROTARY_VALVE_MICROSTEP_FRACTION ) < 4 ? ( posA >> 3 ) : posA; + posA = ( posA % ROTARY_VALVE_MICROSTEP_FRACTION ) < 4 ? ( posA >> 3 ) << 3 : posA; currentValveStates[ valve ].positionsABC[ VALVE_POSITION_B_OPEN ] = curPos; currentValveStates[ valve ].positionsABC[ VALVE_POSITION_A_INSERT_EJECT ] = posA; @@ -654,13 +654,13 @@ S16 mag = tgtPos - curPos; // calculate magnitude of position change MOTOR_DIR_T dir = ( mag < 0 ? MOTOR_DIR_REVERSE : MOTOR_DIR_FORWARD ); // determine direction of position change - // set commanded position and transition start time stamp + // Set commanded position and transition start time stamp currentValveStates[ valve ].commandedPosition = currentValveStates[ valve ].pendingCommandedPosition; currentValveStates[ valve ].valveOpsStartTime = getMSTimerCount(); - // command FPGA to move valve to commanded position + nextState = VALVE_STATE_IN_TRANSITION; + + // Command FPGA to move valve to commanded position setValveCmdChangePosition( valve, (U16)( abs(mag) ), dir ); - // go on to transition state - nextState = VALVE_STATE_IN_TRANSITION; } }