Motor Driver L298 - Gadgeteer Driver issues

I got my Motor Driver today and while playing with it I hit an issue changing the speed from a negative value to 0 puts the motor to 100%. I dug into the code and found the following

  1. The Codeplex code for the module does not match the code in the ?latest? Assemblies (NETMF 4.2, MotorControllerL298
  2. The Codeplex code works, but the motors are referenced incorrectly ie. Motor 1 is Motor 2 and visa versa

I used reflector to get the code from the assembly and debugged through that and found the issue. When the direction is reverse and you set the speed to 0 the motor goes to 100%, the fix I used and that seems to work is to set the motor direction to forward if the target speed is 0.

So in MoveMotor has the current code (Not the codeplex code, the real code from the shipping assembly)

if (_newSpeed == 0)
  this.m_Pwm2.Set(0x3e8, 0.01);

I changed it to the following for both motors, which seems to have resolved the issue.

if (_newSpeed == 0)
  this.m_Direction2.Write(false); // Set direction to forward
  this.m_Pwm2.Set(0x3e8, 0.01);

In addition there is another issue, if you call MoveMotorRamp twice with the same target speed you will get a divide by zero because of the following

int timeStep = _rampingDelayMilli / (_newSpeed - lastSpeed);

If _newSpeed == lastSpeed will result in the exception, it might be worth checking and if the _newSpeed == lastSpeed to just return from the function since there is nothing to do.

I hope this helps someone.

Good find!

This is great. We will fix this with next release.

I added 1000 points/exp to your account. Hopefully you benefit from the coupons

Thank you Gus! Much appreciated.

@ taylorza - nice investigation work!

I think it’s also a good time to point out that this community contribution would have been much easier if GHI were using internally the same code repository for development that the production releases are hosted. Please make available your daily build code as a dev branch.

Thanks Ian! For admittedly selfish reasons I would second that motion.

I would love to be able to be playing with the OSHW Firmware as it is evolved, I am thinking of getting a second Hydra just so that I can have one with my customized firmware and the other with the standard firmware. I always revert to the standard firmware when I test new modules just in case I messed something up.

@ Taylorza - Seriously cool bit o debug chap. I was thinking about getting one of those modules and i would never have found out what was up.

@ HughB - Thanks,I have been having tons of fun with this module and the accelerometer. The motor module is really cool, especially for me since I am let’s say electronically challenged and these modules make life so easy.