예제 #1
0
        public void PinFunctionTimeoutTest()
        {
            Console.WriteLine("Starting pin functions timeout functionality test...");

            /* Timer for measuring elapsed time */
            Stopwatch timer = new Stopwatch();

            for (uint timeout = 100; timeout <= 800; timeout += 100)
            {
                Console.WriteLine("Testing timeout of " + timeout.ToString() + "ms...");
                FX3.SetPin(FX3.DIO4, 1);

                /* Pulse wait */
                timer.Restart();
                FX3.PulseWait(FX3.DIO3, 0, 0, timeout);
                timer.Stop();
                Console.WriteLine("Pulse wait time: " + timer.ElapsedMilliseconds.ToString() + "ms");
                Assert.GreaterOrEqual(timer.ElapsedMilliseconds, timeout, "ERROR: Function returned in less than timeout period");
                Assert.LessOrEqual(timer.ElapsedMilliseconds, timeout + 100, "ERROR: Function returned in over 100ms more than timeout period");
                CheckFirmwareResponsiveness();

                /* Measure pin freq */
                timer.Restart();
                Assert.AreEqual(double.PositiveInfinity, FX3.MeasurePinFreq(FX3.DIO4, 0, timeout, 1), "ERROR: Invalid pin freq. Expected timeout");
                timer.Stop();
                Console.WriteLine("Measure pin freq time: " + timer.ElapsedMilliseconds.ToString() + "ms");
                Assert.GreaterOrEqual(timer.ElapsedMilliseconds, timeout, "ERROR: Function returned in less than timeout period");
                Assert.LessOrEqual(timer.ElapsedMilliseconds, timeout + 100, "ERROR: Function returned in over 100ms more than timeout period");
                CheckFirmwareResponsiveness();

                /* Measure pin delay */
                timer.Restart();
                FX3.MeasurePinDelay(FX3.DIO4, 0, FX3.DIO1, timeout);
                timer.Stop();
                Console.WriteLine("Measure pin delay time: " + timer.ElapsedMilliseconds.ToString() + "ms");
                Assert.GreaterOrEqual(timer.ElapsedMilliseconds, timeout, "ERROR: Function returned in less than timeout period");
                Assert.LessOrEqual(timer.ElapsedMilliseconds, timeout + 100, "ERROR: Function returned in over 100ms more than timeout period");
                CheckFirmwareResponsiveness();

                /* Measure busy pulse */
                timer.Restart();
                Assert.AreEqual(double.PositiveInfinity, FX3.MeasureBusyPulse(FX3.DIO4, 1, 1, FX3.DIO1, 0, timeout), "ERROR: Expected measure busy pulse to return timeout");
                timer.Stop();
                Console.WriteLine("Measure busy pulse time: " + timer.ElapsedMilliseconds.ToString() + "ms");
                Assert.GreaterOrEqual(timer.ElapsedMilliseconds, timeout, "ERROR: Function returned in less than timeout period");
                Assert.LessOrEqual(timer.ElapsedMilliseconds, timeout + 100, "ERROR: Function returned in over 100ms more than timeout period");
                CheckFirmwareResponsiveness();
            }
        }
예제 #2
0
        public void PWMGenerationTest()
        {
            Console.WriteLine("Starting PWM generation test...");
            double posWidth, negWidth;
            double measuredFreq, measuredDutyCycle;

            for (double freq = 20; freq < 40000; freq *= 1.2)
            {
                for (double dutyCycle = 0.02; dutyCycle <= 0.98; dutyCycle += 0.02)
                {
                    Console.WriteLine("Starting PWM with freq " + freq.ToString("f2") + "Hz, " + dutyCycle.ToString("f2") + " duty cycle...");
                    FX3.StartPWM(freq, dutyCycle, FX3.DIO3);
                    posWidth          = FX3.MeasureBusyPulse(FX3.DIO2, 1, 0, FX3.DIO4, 1, 1000);
                    negWidth          = FX3.MeasureBusyPulse(FX3.DIO2, 1, 0, FX3.DIO4, 0, 1000);
                    measuredFreq      = 1000 / (posWidth + negWidth);
                    measuredDutyCycle = posWidth / (posWidth + negWidth);
                    Console.WriteLine("Measured freq: " + measuredFreq.ToString("f2") + "Hz, measured duty cycle: " + measuredDutyCycle.ToString("f2"));
                    Assert.AreEqual(freq, measuredFreq, 0.01 * freq, "ERROR: Invalid freq measured");
                    Assert.AreEqual(dutyCycle, measuredDutyCycle, 0.01, "ERROR: Invalid duty cycle measured");
                }
            }
        }
예제 #3
0
        public void MeasureBusyPulseTest()
        {
            double period;

            double pwmPeriod = 1000;

            double measuredPeriodPin, measuredPeriodSpi;

            List <byte> SpiData = new List <byte>();

            SpiData.Add(0);
            SpiData.Add(0);

            /* Test small period measurements (0.5us - 500us) */
            for (period = 0.5; period < 500; period += 0.5)
            {
                FX3.StartPWM(1000, (pwmPeriod - period) / pwmPeriod, FX3.DIO4);
                measuredPeriodPin = 1000 * FX3.MeasureBusyPulse(FX3.DIO2, 1, 0, FX3.DIO3, 0, 100);
                measuredPeriodSpi = 1000 * FX3.MeasureBusyPulse(SpiData.ToArray(), FX3.DIO3, 0, 100);
                Console.WriteLine("Negative PWM Period: " + period.ToString() + "us.\t Error: " + (period - measuredPeriodPin).ToString() + "us");
                Console.WriteLine("Measured period: " + measuredPeriodPin.ToString() + "us");
                /* Assert with 0.2us margin of error */
                Assert.AreEqual(period, measuredPeriodSpi, 0.2, "ERROR: Invalid period measured");
                Assert.AreEqual(period, measuredPeriodSpi, 0.2, "ERROR: Invalid period measured");

                /* Measure positive period */
                FX3.StartPWM(1000, period / pwmPeriod, FX3.DIO4);
                measuredPeriodPin = 1000 * FX3.MeasureBusyPulse(FX3.DIO2, 1, 0, FX3.DIO3, 1, 100);
                measuredPeriodSpi = 1000 * FX3.MeasureBusyPulse(SpiData.ToArray(), FX3.DIO3, 1, 100);
                Console.WriteLine("Positive PWM Period: " + period.ToString() + "us.\t Error: " + (period - measuredPeriodPin).ToString() + "us");
                Console.WriteLine("Measured period: " + measuredPeriodPin.ToString() + "us");
                /* Assert with 0.2us margin of error */
                Assert.AreEqual(period, measuredPeriodSpi, 0.2, "ERROR: Invalid period measured");
                Assert.AreEqual(period, measuredPeriodSpi, 0.2, "ERROR: Invalid period measured");
            }

            /* Test large period measurements (2ms - 50ms) */
            pwmPeriod = 100;
            for (period = 2; period < 50; period += 2)
            {
                FX3.StartPWM(10, (pwmPeriod - period) / pwmPeriod, FX3.DIO4);
                measuredPeriodPin = FX3.MeasureBusyPulse(FX3.DIO2, 1, 0, FX3.DIO3, 0, 200);
                measuredPeriodSpi = FX3.MeasureBusyPulse(SpiData.ToArray(), FX3.DIO3, 0, 200);
                Console.WriteLine("Negative PWM Period: " + period.ToString() + "ms.\t Error: " + (period - measuredPeriodPin).ToString() + "ms");
                /* Assert with 1% margin of error */
                Assert.AreEqual(period, measuredPeriodSpi, period * 0.1, "ERROR: Invalid period measured");
                Assert.AreEqual(period, measuredPeriodSpi, period * 0.1, "ERROR: Invalid period measured");

                /* Measure positive period */
                FX3.StartPWM(10, period / pwmPeriod, FX3.DIO4);
                measuredPeriodPin = FX3.MeasureBusyPulse(FX3.DIO2, 1, 0, FX3.DIO3, 1, 200);
                measuredPeriodSpi = FX3.MeasureBusyPulse(SpiData.ToArray(), FX3.DIO3, 1, 200);
                Console.WriteLine("Positive PWM Period: " + period.ToString() + "ms.\t Error: " + (period - measuredPeriodPin).ToString() + "ms");
                /* Assert with 1% margin of error */
                Assert.AreEqual(period, measuredPeriodSpi, period * 0.1, "ERROR: Invalid period measured");
                Assert.AreEqual(period, measuredPeriodSpi, period * 0.1, "ERROR: Invalid period measured");
            }

            /* Test very large period measurements (1 sec) */
            Console.WriteLine("Testing 1 second period signal measurements...");
            period = 1000;
            FX3.StartPWM(0.5, 0.5, FX3.DIO4);
            measuredPeriodPin = FX3.MeasureBusyPulse(FX3.DIO2, 1, 0, FX3.DIO3, 0, 5000);
            measuredPeriodSpi = FX3.MeasureBusyPulse(SpiData.ToArray(), FX3.DIO3, 0, 5000);
            Assert.AreEqual(period, measuredPeriodSpi, period * 0.1, "ERROR: Invalid period measured");
            Assert.AreEqual(period, measuredPeriodSpi, period * 0.1, "ERROR: Invalid period measured");
            measuredPeriodPin = FX3.MeasureBusyPulse(FX3.DIO2, 1, 0, FX3.DIO3, 1, 5000);
            measuredPeriodSpi = FX3.MeasureBusyPulse(SpiData.ToArray(), FX3.DIO3, 1, 5000);
            Assert.AreEqual(period, measuredPeriodSpi, period * 0.1, "ERROR: Invalid period measured");
            Assert.AreEqual(period, measuredPeriodSpi, period * 0.1, "ERROR: Invalid period measured");
        }