public void PWMPinInfoTest() { Console.WriteLine("Starting pin PWM info test..."); int exCount; PinPWMInfo info; Console.WriteLine("Testing default PWM pin info for each pin..."); foreach (PropertyInfo prop in FX3.GetType().GetProperties()) { if (prop.PropertyType == typeof(AdisApi.IPinObject)) { Assert.AreEqual(0, FX3.GetPinPWMInfo((AdisApi.IPinObject)prop.GetValue(FX3)).IdealFrequency, "ERROR: Expected PWM pins to be disabled for all pins initially"); } } Console.WriteLine("Testing PWM pin info for each pin..."); foreach (PropertyInfo prop in FX3.GetType().GetProperties()) { if (prop.PropertyType == typeof(AdisApi.IPinObject)) { if (((AdisApi.IPinObject)prop.GetValue(FX3)).pinConfig % 8 != 0) { FX3.StartPWM(2000, 0.5, (AdisApi.IPinObject)prop.GetValue(FX3)); info = FX3.GetPinPWMInfo((AdisApi.IPinObject)prop.GetValue(FX3)); Assert.AreEqual(((AdisApi.IPinObject)prop.GetValue(FX3)).pinConfig, info.FX3GPIONumber, "ERROR: Invalid GPIO Number"); Assert.AreEqual(info.FX3GPIONumber % 8, info.FX3TimerBlock, "ERROR: Invalid FX3 timer block"); Assert.AreEqual(2000, info.IdealFrequency, "ERROR: Invalid frequency"); Assert.AreEqual(0.5, info.IdealDutyCycle, "ERROR: Invalid duty cycle"); FX3.StopPWM((AdisApi.IPinObject)prop.GetValue(FX3)); } else { exCount = 0; try { FX3.StartPWM(2000, 0.5, (AdisApi.IPinObject)prop.GetValue(FX3)); } catch (Exception e) { Console.WriteLine(e.Message); exCount = 1; } Assert.AreEqual(1, exCount, "ERROR: Expected exception to be thrown for pins which cannot run PWM"); } } } Console.WriteLine("Sweeping PWM freq..."); { for (double freq = 0.5; freq < 100000; freq = freq * 1.1) { FX3.StartPWM(freq, 0.5, FX3.DIO1); Assert.AreEqual(freq, FX3.GetPinPWMInfo(FX3.DIO1).IdealFrequency, "ERROR: Invalid IdealFrequency"); Assert.AreEqual(freq, FX3.GetPinPWMInfo(FX3.DIO1).RealFrequency, 0.001 * freq, "ERROR: Invalid RealFrequency"); } } Console.WriteLine("Sweeping PWM duty cycle at 1KHz..."); for (double dutyCycle = 0.01; dutyCycle < 1.0; dutyCycle += 0.01) { FX3.StartPWM(1000, dutyCycle, FX3.DIO1); Assert.AreEqual(dutyCycle, FX3.GetPinPWMInfo(FX3.DIO1).IdealDutyCycle, "ERROR: Invalid ideal duty cycle"); Assert.AreEqual(dutyCycle, FX3.GetPinPWMInfo(FX3.DIO1).RealDutyCycle, 0.001 * dutyCycle, "ERROR: Invalid real duty cycle"); } }