Split out code for PWM in, Motor control (PWM out), target position, and main logic