But the motor gets heating. (indicated and given current for the motor is 500mA)
That's not a software problem.