When programming the FEZ Mini Robot I noticed that the motors Servo’s influence. The engines are controlled with PWM and the Servos with the OutputCompare function GHI.
To be able to easily demonstrate this, I made a small test program. The servo is controlled by pushbuttons and Di2 DI4 and engine with the LDR button.
In the diagram of the control board, I can’t find anything about a possible cause of this problem.
Who can advise me or is it a bug in the library.
The source of the test program:
using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using GHIElectronics.NETMF.FEZ;
using GHIElectronics.NETMF.Hardware;
namespace FEZ_Mini_Application1
{
public class Program
{
public static void Main()
{
OutputCompare _srv = new OutputCompare((Cpu.Pin)FEZ_Pin.Digital.Di7, true, 5);
OutputPort _dir1 = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.Di3, false);
PWM _pwm1 = new PWM((PWM.Pin)FEZ_Pin.PWM.Di5);
OutputPort _dir2 = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.Di9, false);
PWM _pwm2 = new PWM((PWM.Pin)FEZ_Pin.PWM.Di6);
InputPort _but1 = new InputPort((Cpu.Pin)FEZ_Pin.Digital.Di2, false, Port.ResistorMode.PullUp);
InputPort _but2 = new InputPort((Cpu.Pin)FEZ_Pin.Digital.Di4, false, Port.ResistorMode.PullUp);
InputPort _ldr = new InputPort((Cpu.Pin)FEZ_Pin.Digital.LDR, false, Port.ResistorMode.PullUp);
OutputPort led = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.LED, true);
uint[] timings = new uint[5];
byte pos = 0;
int count = 0;
_dir1.Write(false);
_dir2.Write(false);
_pwm1.Set(1000, 0);
_pwm2.Set(1000, 0);
while (true)
{
if (!_ldr.Read())
{
_pwm1.Set(1000, 50);
_pwm2.Set(1000, 50);
}
else
{
_pwm1.Set(1000, 0);
_pwm2.Set(1000, 0);
}
if (!_but1.Read())
{
if (pos < 180)
pos += 5;
if (pos == 0)
pos = 1;
timings[0] = (uint)(((float)((2500 - 400) / 180) * (pos)) + 400);
timings[1] = 50000;
_srv.Set(true, timings, 0, 2, true);
}
if (!_but2.Read())
{
if (pos > 5)
pos -= 5;
if (pos == 0)
pos = 1;
timings[0] = (uint)(((float)((2500 - 400) / 180) * (pos)) + 400);
timings[1] = 50000;
_srv.Set(true, timings, 0, 2, true);
}
if (count++ > 20)
{
count = 0;
led.Write(!led.Read());
}
Thread.Sleep(10);
}
}
}
}