Using the Motor Driver (ST L298p) - pdiefend/Turbocharger GitHub Wiki
Motor Control
The L298p is a quad-half H-bridge which means there are two full H-bridges inside the chip. These H-bridges can be used together or separately based on your application. Each bridge is designed to be controlled using only two pins with one optional feedback pin. The direction pins control the direction the motor will spin by controlling the polarity of the motor. You are free to decide how the polarity of the motor is connected and you may decide which direction you want to define as Forward. In the example code provided with this repository writing a digital high to the direction pin is defined as forward.
The speed of the motor is set using the PWM pins. The PWM pins are connected to the enable pins on the H-bridges. Writing a digital low to this pin will disable the motor regardless of the direction. Otherwise use of the analogWrite function will output a PWM signal that can control the motor driver.
Around the Motor Driver is all of the circuit protection you should need Except for a fuse!!!!. You are responsible for adding proper fusing to your system to protect the circuit from short circuits. I recommend adding a one-time blow fuse. A slow blow may be used if you are sure the prolonged conduction time will not damage the driver. Flyback diodes in the form of a rectifier and a filter cap for the output are included for your convenience. This driver was based on the Arduino Motor Driver Shield which had LEDs to indicate direction and PWM; if popular demand requests these, they may be added in a future revision.
Current Sensing
The current sensing is used through the analogRead function on the current sensing pin. The amplifier is set to a gain of 15:1 across the 0.15Ω sense resistor. This gives an output of 2.25V/1A of current through the motor. This gives a ratio of 460.35/A on the analog inputs. So an analog reading of 460 is about 1A and an analog reading of 920 is about 2A.