MoveMotorRampNonBlocking only while debugging

in my Gadgeteer 4.2 Project i have a strange issue with the Motor Controller298.
I want to control 2 Motors, when i use MoveMotorRampNonBlocking() the second Motor only rotate in Debugging mode, when i run the code without degug only 1 Motor rotate.
Other methods e.g. MoveMotorRamp works fine.

Environment: Visual Studio 2012/R3/Project 4.2

Thx for any tip

Can you show your code please?

Here is the code:

        void ProgramStarted()
            motorController.MoveMotorRampNonBlocking(MotorControllerL298.Motor.Motor1, 100, 5000);
            motorController.MoveMotorRampNonBlocking(MotorControllerL298.Motor.Motor2, 100, 5000);

Have you tried different parameters?

For example ramp it up to 50% instead of 100 and over smaller timespans. 1000ms or 500ms for example. Is it the first motor or the second that is not turning on?

Yes I try it now, it is the same behavior. The first Motor stand still…

The move non blocking functions use threads behind the scenes, but the driver does not appear to be thread safe so there is a race between the two calls.

A possible work around is:

Follow this document: and add the MotorControllerL298 driver to your project. Replace lines 380 to 400 (functions MoveMotorRampNonBlocking and MoveMotorRampThreadStart) of MotorControllerL298_42.cs with:

        public void MoveMotorRampNonBlocking(Motor _motorSide, int _newSpeed, int _rampingDelayMilli)
            var m = new tMovement();
            m.m_motorSide = _motorSide;
            m.m_newSpeed = _newSpeed;
            m.m_rampingDelayMilli = _rampingDelayMilli;

            Thread moveThread = new Thread(() => this.MoveMotorRampThreadStart(m));

        private tMovement movement;// = new tMovement();

        /// <summary>
        /// Represents the function that is used to start a thread to asynchronously move a motor.
        /// </summary>
        private void MoveMotorRampThreadStart(tMovement vars)
			MoveMotorRamp(vars.m_motorSide, vars.m_newSpeed, vars.m_rampingDelayMilli);

1 Like

@ John - And remove private movement to avoid confusion?

I do this exactly, but the same behavior. While Debugging all works fine, without Debugging only second Motor is rotating…

@ dutzend - Can you post entire code for your modified motor driver, please. Also make sure you are not referencing the driver dll that comes with the sdk (remove the module in the designer completely and instantiate it manually in your “program started”).

Thx, the reference is now right and all works fine!

@ Architect, it will be cleaned up in the next release. Just wanted to get the simplest fix out for dutzend without changing too many lines.