analogWrite (speedPinA, motor_speed); //Turn motor on
Varying the motor speed as you get closer to the limit would be a good thing. That's what the PID idea is all about. Sneak up on the limits to avoid overshooting.
You only need to flip the motor direction if it changes, not on every pass through loop.
Your commented out Serial.print() information does not reflect reality.