Get rid of back emf in motors
You need to use flyback diodes to protect from large inductive currents on motor startup and shutdown. I used the following circuit with the L293B, you have to adopt it for the 298, but the basic principle and arrangement of the diodes is the same. 



The flyback diodes provide a path for the current generated by the back-EMF (stored in the motor's magnetic field) when the motor is switched off/turned on. You can read more on flyback diodes on Wikipedia. Also, take care to use Schottky diodes (a special type of diodes) which are much faster than the generic rectifier diodes. I used SB260 (60V, 2A) but you may need to use something larger, depending on the current and voltage. Allow for a significant voltage overhead above your operating voltage, because these inductive voltage spikes can be big. The resistors R1 to R6 are there for current overload protection for the microcontroller, they are not strictly necessary, but can save your ucontroller if you screw up something.