I have worked with it for several hours without success.
I chose to create a new project, where I have only made pwm setup and dutycycle update.
But the same exception appeared.
using System;
using System.Threading;
using System.IO;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using GHI.Hardware.G120;
using GHI.Premium;
using GHI.Premium.System;
namespace PWMsetup_test
{
public class Program
{
public static void Main()
{
PWM_setup MotorPan = new PWM_setup(0, 20000, false);
while (true)
{
MotorPan.Update();
}
}
}
}
namespace PWMsetup_test
{
class PWM_setup
{
PWM pwmPhaseA1;
public PWM_setup(int pinPhaseA1, int Freq, bool Invert)
{
PWM pwmPhaseA1 = new PWM((Cpu.PWMChannel)pinPhaseA1, Freq, 0.0, Invert);
}
public void Update()
{
pwmPhaseA1.DutyCycle = 0.2;
Thread.Sleep(100);
pwmPhaseA1.DutyCycle = 0.8;
Thread.Sleep(100);
}
}
}
The PWM you declared in PWM_setup shadowed the global PWM inside the function, so the global one was never set, only a temporary local one was. The below code fixes that.
PWM pwmPhaseA1;
public PWM_setup(int pinPhaseA1)
{
pwmPhaseA1 = new PWM((Cpu.PWMChannel)pinPhaseA1, 20000, 0.0, false); // =0.0
pwmPhaseA1.DutyCycle = 0.5; // =0.5
}
public void Update()
{
pwmPhaseA1.DutyCycle = 0.2; // = NULL and break
Thread.Sleep(100);
pwmPhaseA1.DutyCycle = 0.8;
Thread.Sleep(100);
}