Ejemplo n.º 1
0
        public static void Execute(ref DacChannel channel)
        {
            uint value   = 0;
            bool goingUp = false;
            int  upperValue;

            // get upper value from DAC resolution
            upperValue = (int)Math.Pow(2, Scenario1ConfigureDac.dacResolution);

            // compute a reasonable increment value from the the DAC resolution
            uint increment = (uint)Math.Pow(2, Scenario1ConfigureDac.dacResolution / 2);


            for (; ;)
            {
                if (value == upperValue)
                {
                    // tweak the value so it doesn't overflow the DAC
                    value--;

                    channel.WriteValue((ushort)value);

                    value++;

                    // invert to go down
                    goingUp = false;
                }
                else if (value == 0)
                {
                    channel.WriteValue((ushort)value);

                    // invert to go up
                    goingUp = true;
                }
                else
                {
                    channel.WriteValue((ushort)value);
                }

                if (goingUp)
                {
                    value += increment;
                }
                else
                {
                    value -= increment;
                }

                //Output the current value to console when in debug.
                Debug.WriteLine($"DAC TriangleWave output current value: {value}");

                Thread.Sleep(Scenario1ConfigureDac.s_timeResolution);
            }
        }
        public static void Execute(ref DacChannel channel)
        {
            UInt32 value     = 0;
            uint   increment = 0;
            bool   goingUp   = false;
            int    upperValue;

            // get upper value from DAC resolution
            upperValue = (int)Math.Pow(2, Scenario1ConfigureDac.dacResolution);

            // compute a reasonable increment value from the the DAC resolution
            increment = (uint)Math.Pow(2, (Scenario1ConfigureDac.dacResolution / 2));


            for (; ;)
            {
                if (value == upperValue)
                {
                    // tweak the value so it doesn't overflow the DAC
                    value--;

                    channel.WriteValue((ushort)value);

                    value++;

                    // invert to go down
                    goingUp = false;
                }
                else if (value == 0)
                {
                    channel.WriteValue((ushort)value);

                    // invert to go up
                    goingUp = true;
                }
                else
                {
                    channel.WriteValue((ushort)value);
                }

                if (goingUp)
                {
                    value += increment;
                }
                else
                {
                    value -= increment;
                }

                Thread.Sleep(Scenario1ConfigureDac.s_timeResolution);
            }
        }
Ejemplo n.º 3
0
        public static void Execute(ref DacChannel channel)
        {
            UInt32 value = 0;
            float  increment = 0;
            int    upperValue, midRange;
            float  radian = 0;

            // get upper value from DAC resolution
            upperValue = (int)Math.Pow(2, Scenario1ConfigureDac.dacResolution);

            // compute a reasonable increment value from the resolution
            increment = maxRads / (Scenario1ConfigureDac.dacResolution * 10);
            midRange  = upperValue / 2;

            for (; ;)
            {
                // because the DAC can't output negative values
                // we have to offset the sine wave to half the DAC output range
                value = (uint)((Math.Sin(radian) * (midRange - 1)) + midRange);

                // output to DAC
                channel.WriteValue((ushort)value);

                // increment angle
                radian += increment;

                if (radian >= maxRads)
                {
                    // tweak the value so it doesn't overflow the DAC
                    radian = 0;
                }

                Thread.Sleep(Scenario1ConfigureDac.s_timeResolution);
            }
        }
Ejemplo n.º 4
0
        public static void Execute(ref DacChannel channel)
        {
            int value = 0;
            int upperValue;
            int periodCounter = 0;
            int halfPeriod;

            // get upper value from DAC resolution
            upperValue = (int)Math.Pow(2, Scenario1ConfigureDac.dacResolution);

            // figure out an expedite way to get a more or less square wave from the DAC and time resolution
            halfPeriod = (upperValue / (Scenario1ConfigureDac.s_timeResolution * 10)) / 2;

            for (;;)
            {
                if (periodCounter == halfPeriod)
                {
                    // tweak the value so it doesn't overflow the DAC
                    value = upperValue - 1;
                }
                else if (periodCounter == halfPeriod * 2)
                {
                    value = 0;

                    periodCounter = 0;
                }

                channel.WriteValue((ushort)value);

                Thread.Sleep(Scenario1ConfigureDac.s_timeResolution);

                periodCounter++;
            }
        }