Hi All,
I’m very new to all this but i’m stuck for days allready so am hoping for some help. I have the FEZ Panda 2 controller running on the latest firmware. On top of that I stocked the fez connect shield and on top of that is the DFIRobot DFRduino L298p shield.
M1 and M2 are both connected to a 6v, 180rpm DC Geared motor. A 6pack AA batteries power my FEZ Panda 2. I’ve got the motor shield on “power from internal device”. I know it’s powering the engine’s because as the microcontroller boots they run at full speed.
But when I start controlling the engines with the FEZ Panda 2 it seems to freeze all the time. I’m using the following code to initialize:
static PWM _pwm1;
static OutputPort _dir1;
static PWM _pwm2; static OutputPort _dir2;
static sbyte _last_speed1, _last_speed2;
static public void Initialize()
{
_pwm1 = new PWM((PWM.Pin)FEZ_Pin.PWM.Di5);
_dir1 = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.Di4, false);
_pwm2 = new PWM((PWM.Pin)FEZ_Pin.PWM.Di6);
_dir2 = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.Di7, false);
}
And there are functions to set the speed and direction as well:
static public void Move(sbyte speed1, sbyte speed2)
{
if (speed1 > 100 || speed1 < -100 || speed2 > 100 || speed2 < -100)
new ArgumentException();
_last_speed1 = speed1;
_last_speed2 = speed2;
if (speed1 < 0)
_dir1.Write(true);
else
_dir1.Write(false);
_pwm1.Set(1000, (byte)(Math.Abs(speed1)));
////////////////////////////
if (speed2 < 0)
_dir2.Write(true);
else
_dir2.Write(false);
_pwm2.Set(1000, (byte)(Math.Abs(speed2)));
}
static public void MoveRamp(sbyte speed1, sbyte speed2, byte ramping_delay)
{
sbyte temp_speed1 = _last_speed1;
sbyte temp_speed2 = _last_speed2;
while ((speed1 != temp_speed1) || (speed2 != temp_speed2))
{
if (temp_speed1 > speed1)
temp_speed1--;
if (temp_speed1 < speed1)
temp_speed1++;
if (temp_speed2 > speed2)
temp_speed2--;
if (temp_speed2 < speed2)
temp_speed2++;
Move(temp_speed1, temp_speed2);
Thread.Sleep(ramping_delay);
}
}
MoveRamp accepts 3 parameters, one for the first engine speed, the second engine speed and the delay (so it’s increasing speed with a certain delay).
If I set MoveRamp with 100,100, 20 i can debug the FEZ. It run’s the MoveRamp loop about 20 times and then stops debugging and completely freezes. If I stop the program in C# and re deploy it’s nagging about a hardware problem.
Removing the power and booting the FEZ again helps to be able to deploy and debug again.
“Move” has a similar problem. It runs the function but does not proceed to the next function afterwards.
For instance:
Move(50,50);
Sleep(5000);
Move(20,20);
This should start driving for 5 seconds and then drive slower. However, FEZ freezes and the engines just keep running at the 50,50 speed.
I tried hooking up another battery pack to the motor controller and set the jumpers to “external power” but this does not change anything. You can find the motor shield manual here Arduino_Motor_Shield__L298N___SKU_DRI0009_-DFRobot
Really hope someone can help me out here / help troubleshoot. I don’t have any more clues on how to fix this issue.
Best regards,
Arjan.