Beispiel #1
0
 public static extern short SetPulseWidthQualifier(
     short handle,
     PwqConditions[] conditions,
     short nConditions,
     ThresholdDirection direction,
     uint lower,
     uint upper,
     PulseWidthType type);
Beispiel #2
0
 public Pwq(PwqConditions[] conditions,
            short nConditions,
            ThresholdDirection direction,
            uint lower, uint upper,
            PulseWidthType type)
 {
     this.conditions  = conditions;
     this.nConditions = nConditions;
     this.direction   = direction;
     this.lower       = lower;
     this.upper       = upper;
     this.type        = type;
 }
 public static extern UInt32 SetPulseWidthQualifierProperties(short handle,
                                                              ThresholdDirection direction,
                                                              uint lower,
                                                              uint upper,
                                                              PulseWidthType type);
Beispiel #4
0
 public static extern short SetPulseWidthQualifier(
     short handle,
     PwqConditions[] conditions,
     short numConditions,
     ThresholdDirection direction,
     uint lower,
     uint upper,
     PulseWidthType type);
Beispiel #5
0
 public static extern StandardDriverStatusCode SetPulseWidthQualifierProperties(
     short handle,
     uint lower,
     uint upper,
     PulseWidthType type);
Beispiel #6
0
    /// <summary>
    /// This function sets up a pulse width trigger on a specified channel. Expecting 2Vpp signal.
    /// </summary>
    public static StandardDriverStatusCode SetTriggerAndPulseWidth(short handle, Channel channel, uint pulseWidthSampleCount, PulseWidthType pulseWidthType, int autoTriggerDelay = 0)
    {
        int hysteresis = 2048;

        var triggerChannelProperty   = new TriggerChannelProperties((short)hysteresis, (ushort)hysteresis, 0, (ushort)hysteresis, channel);
        var triggerChannelProperties = new List <TriggerChannelProperties>()
        {
            triggerChannelProperty
        };
        var status = DriverImports.PS6000a.SetTriggerChannelProperties(handle, triggerChannelProperties.ToArray(),
                                                                       (short)triggerChannelProperties.Count, 0, autoTriggerDelay);

        if (status != StandardDriverStatusCode.Ok)
        {
            return(status);
        }

        var triggerCondition           = new TriggerCondition(channel, TriggerState.True);
        var triggerConditionPulseWidth = new TriggerCondition(Channel.PulseWidthSource, TriggerState.True);
        var triggerConditions          = new List <TriggerCondition>()
        {
            triggerCondition, triggerConditionPulseWidth
        };

        status = DriverImports.PS6000a.SetTriggerChannelConditions(handle, triggerConditions.ToArray(),
                                                                   (short)triggerConditions.Count,
                                                                   DriverImports.Action.PICO_CLEAR_ALL | DriverImports.Action.PICO_ADD);

        if (status != StandardDriverStatusCode.Ok)
        {
            return(status);
        }

        var thresholdDirection  = new ThresholdDirection(channel, TriggerDirection.Falling, ThresholdMode.Level);
        var thresholdDirections = new List <ThresholdDirection>()
        {
            thresholdDirection
        };

        status = DriverImports.PS6000a.SetTriggerChannelDirections(handle, thresholdDirections.ToArray(), (short)thresholdDirections.Count);

        if (status != StandardDriverStatusCode.Ok)
        {
            return(status);
        }

        var pulseCondition  = new TriggerCondition(channel, TriggerState.True);
        var pulseConditions = new List <TriggerCondition>()
        {
            pulseCondition
        };

        status = DriverImports.PS6000a.SetPulseWidthQualifierConditions(handle, pulseConditions.ToArray(),
                                                                        (short)pulseConditions.Count, DriverImports.Action.PICO_CLEAR_ALL | DriverImports.Action.PICO_ADD);

        if (status != StandardDriverStatusCode.Ok)
        {
            return(status);
        }

        var pulseDirection  = new ThresholdDirection(channel, TriggerDirection.Rising, ThresholdMode.Level);
        var pulseDirections = new List <ThresholdDirection> {
            pulseDirection
        };

        status = DriverImports.PS6000a.SetPulseWidthQualifierDirections(handle, pulseDirections.ToArray(),
                                                                        (short)pulseDirections.Count);

        if (status != StandardDriverStatusCode.Ok)
        {
            return(status);
        }

        status = DriverImports.PS6000a.SetPulseWidthQualifierProperties(handle, pulseWidthSampleCount, 0, pulseWidthType);

        if (status != StandardDriverStatusCode.Ok)
        {
            return(status);
        }

        if (status == StandardDriverStatusCode.Ok)
        {
            Console.WriteLine("Trigger has been setup successfully with pulse width. Please input a 2Vpp signal onto channel: " + channel);
        }

        return(status);
    }
        static StandardDriverStatusCode RunPulseWidthTriggerExample(
            short handle, DeviceResolution resolution, int numChannels,
            double awgFrequency, double pulseWidthFrequency, PulseWidthType pulseWidthType, string filename)
        {
            double cycleTime = 1.0 / pulseWidthFrequency;

            // The minimum time in seconds required for the pulse width trigger to hit.
            double pulseWidthPeriodSeconds = 0.5 * cycleTime;

            Console.WriteLine($"Running a pulse width qualifier test with a period of {(float)(1000000.0 * pulseWidthPeriodSeconds) }us.");

            switch (pulseWidthType)
            {
            case PulseWidthType.Greater_Than:
                Console.WriteLine("The AWG frequency is less than the pulse width period.");
                break;

            case PulseWidthType.Less_Than:
                Console.WriteLine("The AWG frequency is greater than the pulse width period.");
                break;
            }

            Console.WriteLine();

            var    channel           = Channel.ChannelA;
            ulong  numSamples        = 1000;
            double idealTimeInterval = 0.0000001; //100ns

            var status = ps6000aDevice.EnableAWGOutput(handle, WaveType.Square, frequency: awgFrequency);

            if (status != StandardDriverStatusCode.Ok)
            {
                return(status);
            }

            status = ps6000aDevice.InitializeChannels(handle, new List <Channel>()
            {
                channel
            }, numChannels);

            if (status != StandardDriverStatusCode.Ok)
            {
                return(status);
            }

            double actualTimeInterval = 0.0;
            uint   timebase           = 0;

            status = DriverImports.PS6000a.NearestSampleIntervalStateless(handle, EnabledChannelsAndPorts.ChannelA,
                                                                          idealTimeInterval, resolution, out timebase, out actualTimeInterval);

            if (status != StandardDriverStatusCode.Ok)
            {
                return(status);
            }

            int   timeIntervalNanoseconds = 0;
            ulong maxSamples = 0;

            status = DriverImports.PS6000a.GetTimebase(handle, timebase, 1, out timeIntervalNanoseconds, out maxSamples, 0);

            if (status != StandardDriverStatusCode.Ok)
            {
                return(status);
            }

            var pulseWidthSampleCount = (uint)Math.Floor(pulseWidthPeriodSeconds / actualTimeInterval);


            status = ps6000aDevice.SetTriggerAndPulseWidth(handle, channel, pulseWidthSampleCount, pulseWidthType);

            if (status != StandardDriverStatusCode.Ok)
            {
                return(status);
            }

            ps6000aDevice.RunBlock(handle, resolution, numSamples, channel, idealTimeInterval);

            if (status != StandardDriverStatusCode.Ok)
            {
                return(status);
            }

            status = ps6000aDevice.WaitForDataToBeCaptured(handle, channel);

            if (status != StandardDriverStatusCode.Ok)
            {
                return(status);
            }

            var      data = new short[numSamples];
            GCHandle gch  = GCHandle.Alloc(data);

            try
            {
                status = ps6000aDevice.ReadDataFromDevice(handle, channel, numSamples, ref data);
                if (status != StandardDriverStatusCode.Ok)
                {
                    return(status);
                }

                ps6000aDevice.WriteDataToFile(data, filename);
            }
            finally
            {
                gch.Free();
            }

            return(status);
        }