Solarbotics/L298.h

See http://www.solarbotics.com/assets/datasheets/solarbotics_l298_compact_motor_driver_kit.pdf for the datasheet.

If you create the additional circuitry shown on page 12 of the datasheet (3 resistors and one transistor) then you only need one IOPin per motor and it can be driven using the code in motorPWM.h

Otherwise you need to include this file.

Each motor requires an I/O pin which provides hardware PWM and two I/O pins to control the direction.

Since we are using hardware PWM then the pulses sent to the motors are very exact. This library can cope with any number of motors and so the only real limitation is the number of PWM channels that your micro controller provides.

If you attempt to use pins that are not valid: say because they are not PWM pins, or the timer doesn't provide hardware PWM then error codes will be set on the status LED.

The remaining two pins are the 'enable' pins. If the motor is turning the wrong way then you can either swap the two enable pins or you can toggle the first parameter to MAKE_SOLAR_L298_MOTOR.

It's very easy to use: you just give it a list of motors and that's it. The motor can then be controlled using the commands in actuators.h.

Note that setting a speed of 0 will cause the motor to brake wheres disconnecting the motor will cause it to coast.

Here is an example of the code in your application:-

#include "Motors/Solarbotics/L298.h"

// Define two motors

SOLAR_L298_MOTOR left = MAKE_SOLAR_L298_MOTOR(FALSE, B1,B4,B5);

SOLAR_L298_MOTOR right = MAKE_SOLAR_L288_MOTOR(TRUE , B2,B6,B7);

// Create the list - remember to place an & at the

// start of each motor name, and to use PROGMEM

SOLAR_L298_MOTOR_LIST PROGMEM motors[] = {&left,&right};

// Create a driver for the list of motors

SOLAR_L298_MOTOR_DRIVER bank1 = MAKE_SOLAR_L298_MOTOR_DRIVER(motors);

// In my initialising code - pass the list of motors to control

void appInitHardware(void){

// Initialise the motors and use a 5kHz PWM frequency

solarL298Init(&bank1, 5000);

}

TICK_COUNT appInitSoftware(TICK_COUNT loopStart){

// Give each servo a start value - make them go full ahead

act_setSpeed(&left,DRIVE_SPEED_MAX);

act_setSpeed(&right,DRIVE_SPEED_MAX);

return 0;

}

// This is the main loop

TICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart){

.. nothing to do. But in reality I would use act_speed to change the speed of each motor ...