But when I put it in some methode’s body it throws following execption: System.InvalidOperationException’ occurred in GHIElectronics.NETMF.Hardware.dll
Methode example:
static public void Intensity(float p)
{
PWM pwm3 = new PWM((PWM.Pin)FEZ_Pin.PWM.Di10);
pwm3.Set(100, 0);
Debug.Print((p * 30).ToString());
if (p * 30 < 100 && p * 30 > 30)
{
if (p * 30 > 80)
pwm3.Set(100, 80);
else
pwm3.Set(100, (byte)(p * 30));
}
else d += 100;
}
namespace FFT2
{
public class pwm
{
public PWM pwm1 = new PWM((PWM.Pin)FEZ_Pin.PWM.Di9);
public PWM pwm2 = new PWM((PWM.Pin)FEZ_Pin.PWM.Di10);
public PWM pwm3 = new PWM((PWM.Pin)FEZ_Pin.PWM.Di8);
public PWM pwm4 = new PWM((PWM.Pin)FEZ_Pin.PWM.Di5);
public PWM pwm5 = new PWM((PWM.Pin)FEZ_Pin.PWM.Di6);
}
}
Agree with Architect, if this method is called from a loop.
By doing this, you’re cutting down on the overhead of instanciating 2 new objects and the work the garbage collector needs to do every time the method is called.
I would go from this:
static public void Frequency(float f,int xstatic public void Frequency(float f, int x, PWM o,PWM j)
{
PWM pwm2 = o;
PWM pwm1 = j;
pwm2.Set(100, 0);
pwm1.Set(100, 0);