Hey guys,
thanks for that useful answers ![:slight_smile: :slight_smile:](https://forums.ghielectronics.com/images/emoji/twitter/slight_smile.png?v=12)
However I’m having problems with the OutputCompare, combined with the brushless motor controller from this source http://code.tinyclr.com/project/62/brushless-motor-esc-for-aircrafts/
With PWM the SetPower function looks like this:
/// <summary>
/// Sets the outputpower, from 0 to "Scale"
/// </summary>
/// <param name="power">0..."Scale"</param>
public void SetPower(int power)
{
uint highTime = (uint)(Min + (Precalc * Constrain(power, 0, (int) _scale)));
this._pwmPin.SetPulse(Period, highTime);
}
As there are only 3 PWM’s on one P-socket, and I need 4, I decided to use an Output-Compare so I don’t have to connect another extender module.
I wrote a small wrapper class for the OutputCompare based on the wiki entry GHI Electronics – Where Hardware Meets Software (Section "Include PWM signal) , but the motor just beeps and doesn’t rotate…
The original code works fine with PWM pins.
That’s the class:
class BrushlessMotorOutputCompare : OutputCompare, IBrushlessMotorInterface
{
static uint[] timings = new uint[2];
public BrushlessMotorOutputCompare(Microsoft.SPOT.Hardware.Cpu.Pin pin) : base(pin, false, timings.Length)
{
}
public static BrushlessMotorOutputCompare Create(int extenderSocket, Gadgeteer.Socket.Pin pin)
{
Gadgeteer.Socket socket = Gadgeteer.Socket.GetSocket(extenderSocket, true, null, null);
return new BrushlessMotorInterfaceOutputCompare( socket.ReservePin(pin, null));
}
void IBrushlessMotorInterface.SetPulse(uint period, uint highTime)
{
//from wiki
//public static void Set(int frequency, byte dutyCycle)
//{
//to make sure period time is microsecond
//uint period = ((uint)(1000000000 / frequency))/1000;
//uint highTime = (period * dutyCycle) / 100;
timings[0] = period - highTime; ;
timings[1] = highTime;
base.Set(true, timings, 0, timings.Length, true);
}
}
That’s the adapted SetPower function:
/// <summary>
/// Sets the outputpower, from 0 to "Scale"
/// </summary>
/// <param name="power">0..."Scale"</param>
public void SetPowerOutputCompare(int power)
{
uint highTime = (uint)(Min + (Precalc * Constrain(power, 0, (int) _scale)));
this._outputComparePin.SetPulse(Period, highTime);
}
Thanks for help ![:slight_smile: :slight_smile:](https://forums.ghielectronics.com/images/emoji/twitter/slight_smile.png?v=12)