L298 issues

i’ve been testing the L298 and have encountered a couple of issues…
My setup is the following…my windows PC communicates with the cerebuino through xbee/wifi and issues commands to move forward, backwards, left, right or stop.
[ul]On my windows box, i have an XBee module connected to COM1 via USB[/ul]
[ul]A small .net app runs on the window box that allows me to issue commands to my rover…the app will write values of 0 to 4 to COM1 , which correspond to directions to move in or to stop.
[ul]on my Cerebuino, i also have XBee module. in the xbee_datareceived handler, i read a single byte from and then attempt to move the motors accordingly[/ul]
[ul]as far as the hardware, the L298 is powered by separate a 9.6V nimh battery.[/ul]

The code currently looks like this:

        void xBeePort_DataReceived(object sender, SerialDataReceivedEventArgs e)
            byte[] buffer = new byte[1];
            xBeePort.Read(buffer, 0, 1);
            byte action = buffer[0];

            switch (action)
                case 0:
                    Debug.Print("Moving forward");
                    motorControllerL298.MoveMotor(MotorControllerL298.Motor.Motor1, 100);
                    motorControllerL298.MoveMotor(MotorControllerL298.Motor.Motor2, 100);
                case 1:
                    Debug.Print("Moving backward");
                    motorControllerL298.MoveMotor(MotorControllerL298.Motor.Motor1, -100);
                    motorControllerL298.MoveMotor(MotorControllerL298.Motor.Motor2, -100);
                case 2:
                    Debug.Print("Moving left");
                    motorControllerL298.MoveMotor(MotorControllerL298.Motor.Motor1, 100);
                    motorControllerL298.MoveMotor(MotorControllerL298.Motor.Motor2, -100);
                case 3:
                    Debug.Print("Moving right");
                    motorControllerL298.MoveMotor(MotorControllerL298.Motor.Motor1, -100);
                    motorControllerL298.MoveMotor(MotorControllerL298.Motor.Motor2, 100);
                case 4:
                    motorControllerL298.MoveMotor(MotorControllerL298.Motor.Motor1, 0);
                    motorControllerL298.MoveMotor(MotorControllerL298.Motor.Motor2, 0);


  1. Using the above code, I am able to move forward, backward, right and left fine. The problem is with “Stop”. Stop only works if the rover is moving forward. If the rover is moving backwards, stop does not work. if the rover is moving right or left, the wheel that is spinning backwards, does not stop, but the one that is spinning forward does. So to stop, i have to always i first move forward by 1% then set motor speed to 0…weird and feels like a bug in the driver.

  2. In the above code, you see that i am using the MoveMotor function. if i use the MoveMotorRamp or MoveMotorRampNB, things get really funky and unpredictable.
    -If i issue two move forward in a row (even after a long pause), and exception is thrown
    -There are times where ‘Forward’, spins only one 1 wheel
    -There are times when it initially moves foward first, but then all other subsequent commands are ignored (even though i’ll see the Debug.Print statements, meaning it is hitting that code)
    -and lastly, i don’t really see any “Ramping up” it always seem to kick in a 100%.

I am wondering if these are possibly thread related. What exactly does this mean from the wiki(GHI Electronics – Where Hardware Meets Software): “Will NOT block the calling thread’s execution until finished. Spawns a new thread to alter the motor’s speed”.
So does this mean that as soon as a i call MoveMotorRampNB, a new thread is spawned that sets the motor speed repeatedly. When it returns, why does it need to block (referring to the “… until finished”)…at that point isn’t the final value 100?

Has anyone else seen weird behaviors w/ using MoveMotorRamp and MoveMotorRampNB?

Does that mean while a motor is running, the calling thread (which would be the one that my xbee lives on in this case and the one that controls the motors) is blocked?

Looking at this code here: http://www.tinyclr.com/forum/topic?id=4596, which appears to be the driver for the l298, i think i see one issue that might explain one of the problems i’m seeing

public void MoveMotorRamp(Motor _motorSide, int _newSpeed, int _rampingDelayMilli)
// Determine which motor we are going to change.
if (_motorSide == Motor.Motor1)
	temp_speed = m_lastSpeed1;
	startSpeed = m_lastSpeed1;
	lastSpeed = m_lastSpeed1;
	temp_speed = m_lastSpeed2;
	startSpeed = m_lastSpeed2;
	lastSpeed = m_lastSpeed2;

// Determine how long we need to wait between move calls.
timeStep = _rampingDelayMilli / (_newSpeed - lastSpeed);

If your current speed is +100 and you try to do a reverse by specifying -100, the above will throw an exception (divide-by-zero). this would explain one strange exception i keep seeing when both motors are moving forward by 100 and then i go left or right, in which case i invert/negate the value of one motor by 100.
I’ll probably down load the source to confirm…

Edit: i see this was discussed only a few weeks ago: http://www.tinyclr.com/forum/topic?id=8798

If you don’t fancy modifying and rebuilding the source code, this works well.


Cant…the whole thing went up in smoke!

I made two fixes to the source and things were working well…but…after a while, it started behaving a lil weird again, where only one motor would move. I put my hand on the chip on the L298 and realize it was extremely hot. pulled the power and unplugged everything…about 15 seconds later, the board started smoking.

What on earth would cause this now! ugh!

If anyone has some insights as to what the issue might be here, please advise…

This afternoon i connected the external battery (9.6v) back to the l298 as was surprised to see the power light turn on. i then connected it back to the cerebuino and decided to give it a quick test…
-only one wheel turns when moving forward and very slowly
-moving the left or right wheels by them selves works fine
-moving backwards works fine
-BUT the big issue is with just this quick test, when i put my finger on the chip at the center of the L298, it is extremely hot (similar to when it started smoking before)…so to be safe, i unplugged everything once more…

probably motors have drawn too much current for the chips or for their heatsinking capability. What motors have you used?

I’m using these: roboticsconnection.com

Motor Specifications

Rated Input Voltage: 12 Volts
No Load Speed: 175rpm
Gear Reduction: 1:40
Stall Torque: 125 oz-in (9 kg-cm)
Weight: 4.7oz
Motor leads: 12" long 28AWG
Quadrature Encoder leads: 12" long 28AWG with 0.100 Header (Encoder Adpater board: +5V, Gnd, Channel A, Channel B)
Pulses: 480 Pulses per output shaft revolution
Drive Shaft Diameter: 6mm
No Load Current Draw: 130mA
Max Current Draw (Shaft Lockup): 1.5A
Wiring Specifications

Motor Power Supply Wire: Vcc Power In (0 - 12 volts)
Motor Power Supply Wire: Gnd Power In
Encoder Adapter Board Vcc: +5V to 12V
Encoder Adapter Board Gnd:
Encoder Adapter Board Channel A (0v-5v out)
Encoder Adapter Board Channel B (0v-5v out)

stall current draw is 1.5A which seems to be under the rated 3A that this page talks about http://www.ghielectronics.com/catalog/product/315 so that doesn’t immediately suggest overloading - sorry I can’t suggest anything else.

Thanks for trying Brett. Hopefully one of the GHI folks can offer some advice…not sure.
What’s strange is that with only the battery connected to the L298 and no app running (the L298 is not connected to the Cerebuino), the chip still gets extremely hot.

yep, that is probably “I’ve failed, the smoke came out, now I’m not running well”. I wouldn’t be surprised too much by that; it’s probably terminal.

Anyone from ghi have any input on this issue? I dont want to get another module and have this happen again. I need to understand what might have happened here…

Form what you describe, I am not seeing anything that would cause the damage. Was it the chip itself of other parts that got hot?

Hi Gus, it was the chip itself that got extremely hot. It is definitely possible, as brett suggests, that the board is hosed at this point and that is why its getting hot just w/ the battery connected. But i know that the first time, just before it started to smoke, i had put my finger on the chip and it was extremely hot then too.

So i guess we can agree that based on the motor and battery specs, the board should have been able to handle this. Anything is possible and i’m open to the possibility that there might have been a short somewhere that caused this, but i really don’t think that was it for several reasons…

-Even a hardware ignorant person like myself found it relatively straight forward to connect the wires to this thing
-After making two fixes to the code, the unit was running fine for a while…then after some time, started to behave more erratically (from subsequent readings, i’ve learned that this can be indicative of overheating)
-And finally i see other references to the l298 overheating on the web. for example read OddBot’s comment at this link: http://letsmakerobots.com/node/30999

My questions are these

  1. has GHI stressed tested this unit in a similar configuration as i have and for how long was it continuously run?
  2. i notice in the source code, that the pwm frequency is set to 1000. The .netmf documentation does not explain in detail what this does (though i can guess). Can you tell me what 1000 means in terms interaction w/ the hardware?

I’d like to get another one (or two…backup) of these modules and try this again, but i am hoping it not an exercise in futility. I’d rather get the right component that will work for me if this one can’t.

Thanks much for any assistance/advice…