SetPulseWidthQualifier - no triggering

Post your .Net discussions here
Post Reply
BlahaK
Newbie
Posts: 0
Joined: Mon Sep 03, 2018 12:48 pm

SetPulseWidthQualifier - no triggering

Post by BlahaK »

Hi, please, help me, I am trying more than 6 hour different sequences of commands and parameters without success.
PicoScope: 3404D
Language: C#.NET (VS2013, .NET Framework 4 Client Profile)
File: "PS3000AImports.cs", last notice in History section: "23Nov11 CPY Modified for PS3000A"

What is OK:
1. finding PicoScope:

Code: Select all

     initOsciloStatus = Imports.OpenUnit(out osciloHandle, null);
     if (initOsciloStatus == 0)
     {
        Imports.SetChannel(osciloHandle, Imports.Channel.ChannelA, 1, 0, Imports.Range.Range_5V, 0);
        Imports.SetChannel(osciloHandle, Imports.Channel.ChannelB, 1, 0, Imports.Range.Range_5V, 0);
        Imports.SetChannel(osciloHandle, Imports.Channel.ChannelC, 1, 0, Imports.Range.Range_5V, 0);
        Imports.SetChannel(osciloHandle, Imports.Channel.ChannelD, 1, 0, Imports.Range.Range_5V, 0);
        Imports.MemorySegments(osciloHandle, 1, out maxSamples);
        //MessageBox.Show("Maximum of samples: " + maxSamples.ToString());
     }
     short sbCap = 20; short sbCap2 = 0;
     StringBuilder sb = new StringBuilder(sbCap);
     res = Imports.GetUnitInfo(osciloHandle, sb, sbCap, out sbCap2, 4); // 4 = PICO_BATCH_AND_SERIAL
     if (res == 0)
     {
        oscSerialNo = sb.ToString();
        MessageBox.Show("SN: " + oscSerialNo.
     }
2. setting Level or Windows trigger:

Code: Select all

   if (osciloHandle > -1)
   {
      Imports.SetTriggerChannelDirections(osciloHandle, Imports.ThresholdDirection.Rising,      Imports.ThresholdDirection.Rising, Imports.ThresholdDirection.Rising, Imports.ThresholdDirection.Rising, Imports.ThresholdDirection.Rising, Imports.ThresholdDirection.Rising);
      
      Imports.TriggerConditions[] myCond = new Imports.TriggerConditions[1];
      myCond[0].ChannelA = Imports.TriggerState.True;
      Imports.SetTriggerChannelConditions(osciloHandle, myCond, 1);
 
     Imports.TriggerChannelProperties[] myProp = new Imports.TriggerChannelProperties[1];
     myProp[0].HysteresisMajor = hysteresis_Major;
     myProp[0].HysteresisMinor = hysteresis_Minor;
     myProp[0].Channel = Imports.Channel.ChannelA;
     myProp[0].ThresholdMajor = threshold_Major;
     myProp[0].ThresholdMinor = threshold_Minor;
     //myProp[0].ThresholdMode = Imports.ThresholdMode.Level;
     myProp[0].ThresholdMode = Imports.ThresholdMode.Window;
     Imports.SetTriggerChannelProperties(osciloHandle, myProp, 1, 0, 0);
   }
3. starting measurement and reading triggered values:

Code: Select all

   if (osciloHandle > -1)
   {
      short result;
      int indisposedTime;
      _callbackDelegate = DataInputCallback;
      BUFFER_SIZE = 5000; // 5000 samples, timebase = 110;
      result = Imports.RunBlock(osciloHandle, 200, BUFFER_SIZE - 200, timeBase, 1, out indisposedTime, 0, _callbackDelegate, IntPtr.Zero);
      if (result != 0) MessageBox.Show("Starting measurement failed.");
   }

Now I want to add pulse-width trigger. I changed the code in part /2/:

Code: Select all

       Imports.SetTriggerChannelDirections(osciloHandle, Imports.ThresholdDirection.Rising, Imports.ThresholdDirection.Rising, Imports.ThresholdDirection.Rising, Imports.ThresholdDirection.Rising, Imports.ThresholdDirection.Rising, Imports.ThresholdDirection.Rising); // OLD
             
       Imports.TriggerConditions[] myCond = new Imports.TriggerConditions[1]; // OLD
       myCond[0].ChannelA = Imports.TriggerState.True; // OLD
       myCond[0].ChannelB = Imports.TriggerState.DontCare; // NEW
       myCond[0].ChannelC = Imports.TriggerState.DontCare; // NEW
       myCond[0].ChannelD = Imports.TriggerState.DontCare; // NEW
       myCond[0].Pwq = Imports.TriggerState.True; // NEW
       myCond[0].External = Imports.TriggerState.DontCare; // NEW
       Imports.SetTriggerChannelConditions(osciloHandle, myCond, 1); // OLD

       Imports.PwqConditions[] pwq = new Imports.PwqConditions[1]; // NEW
       pwq[0].ChannelA = Imports.TriggerState.True; // NEW
       pwq[0].ChannelB = Imports.TriggerState.DontCare; // NEW
       pwq[0].ChannelC = Imports.TriggerState.DontCare; // NEW
       pwq[0].ChannelD = Imports.TriggerState.DontCare; // NEW
       pwq[0].External = Imports.TriggerState.DontCare; // NEW
       Imports.SetPulseWidthQualifier(osciloHandle, pwq, 1, Imports.ThresholdDirection.PositiveRunt, 10, 0, Imports.PulseWidthType.GreaterThan); // NEW

       Imports.TriggerChannelProperties[] myProp = new Imports.TriggerChannelProperties[1]; // OLD
      // myProp[0].HysteresisMajor = hysteresis_Major; // REMOVED
      // myProp[0].HysteresisMinor = hysteresis_Minor; // REMOVED
       myProp[0].Channel = Imports.Channel.ChannelA; // OLD
       myProp[0].ThresholdMajor = threshold_Major; // OLD
       myProp[0].ThresholdMinor = threshold_Minor; // OLD
       myProp[0].ThresholdMode = Imports.ThresholdMode.Window; // OLD
       Imports.SetTriggerChannelProperties(osciloHandle, myProp, 1, 0, 0); // OLD
Can anybody tell me what is wrong?

I only want to make this type of trigger to work: download/file.php?id=2887&mode=view (but with "possitive pulse" and 10 samples width).

Thanks a lot.

P.S. Two notes:
1. every method returns '0' => setting of trigger is successfull.
2. same setting in PicoScope software (Pulse Width Trigger, Source A, Treshold 4V, Positive pulse, Greater then, Time 10 - 50 microseconds) works perfectly. The problem is only in C# code - same signal is not catched.

Hitesh

Re: SetPulseWidthQualifier - no triggering

Post by Hitesh »

Hi BlahaK,

For a pulse width trigger you need to combine the pulse width qualifier with a level trigger (as opposed to a Window trigger), so please change the following for the :

Code: Select all

myProp[0].ThresholdMode = Imports.ThresholdMode.Level; 
For a negative pulse, the pulse width counter needs to reset on a falling edge so please try Imports.ThresholdDirection.Falling or Imports.ThresholdDirection.FallingLower for the direction when calling the Imports.SetPulseWidthQualifier() function.

If these are not defined in your version of PS3000AImports.cs, you can find them in the latest version in our GitHub repository.

Hope this helps,

BlahaK
Newbie
Posts: 0
Joined: Mon Sep 03, 2018 12:48 pm

Re: SetPulseWidthQualifier - no triggering

Post by BlahaK »

Hi Hitesh,
Thanks a lot for advices. After three hours I am still not successfull.

I attached a file with settings and second with curves that I need to catch in my app. Is anybody able to convert pssetting file into sequence of commands with adequate parameters?

Thank you.
Attachments
20180904-0001-5V - record.png
20180904-0001-5V.pssettings
(3.41 KiB) Downloaded 406 times

Hitesh

Re: SetPulseWidthQualifier - no triggering

Post by Hitesh »

Hi BlahaK,

Please try the following source code - it is a modification of the console example.

[The extension cs has been deactivated and can no longer be displayed.]

Regards,

BlahaK
Newbie
Posts: 0
Joined: Mon Sep 03, 2018 12:48 pm

Re: SetPulseWidthQualifier - no triggering

Post by BlahaK »

Hi Hitesh,
thank you very much, example works very well. I ported it successfully into my source code.

My code (for those who do not want parse the file with example):

Code: Select all

 void SetTrigger()
 {
          short threshold_Major  = 19507; //(4 volts on 5 V scale)
          string results = "";

          uint status = 0;
          int timeIntervalNanoseconds = 0;
          int maxSamples = 0;
          do
          {
              status = Imports.GetTimebase(osciloHandle, timeBase, BUFFER_SIZE, out timeIntervalNanoseconds, overSample, out maxSamples, 0);

              if (status == StatusCodes.PICO_INVALID_TIMEBASE)
              {
                  timeBase++;
              }
          }
          while (status != StatusCodes.PICO_OK);

          Imports.TriggerChannelProperties[] sourceDetails = new Imports.TriggerChannelProperties[] { new Imports.TriggerChannelProperties(threshold_Major, 256, threshold_Major, 256, Imports.Channel.ChannelA, Imports.ThresholdMode.Level) };

          Imports.TriggerConditions[] conditions = new Imports.TriggerConditions[] { new Imports.TriggerConditions(Imports.TriggerState.True, Imports.TriggerState.DontCare, Imports.TriggerState.DontCare, Imports.TriggerState.DontCare, Imports.TriggerState.DontCare, Imports.TriggerState.DontCare, Imports.TriggerState.True) };

          Imports.PwqConditions[] pwqConditions = new Imports.PwqConditions[] { new Imports.PwqConditions(Imports.TriggerState.True, Imports.TriggerState.DontCare, Imports.TriggerState.DontCare, Imports.TriggerState.DontCare, Imports.TriggerState.DontCare, Imports.TriggerState.DontCare) };


          results += "SetTriggerChannelProperties: [";
          results += Imports.SetTriggerChannelProperties(osciloHandle, sourceDetails, 1, 0, 0).ToString();
          results += "]\r\n";

          results += "SetTriggerChannelConditions: [";
          results += Imports.SetTriggerChannelConditions(osciloHandle, conditions, 1).ToString();
          results += "]\r\n";

          results += "SetTriggerChannelDirections: [";
          results += Imports.SetTriggerChannelDirections(osciloHandle, Imports.ThresholdDirection.FallingLower, Imports.ThresholdDirection.None, Imports.ThresholdDirection.None, Imports.ThresholdDirection.None, Imports.ThresholdDirection.None, Imports.ThresholdDirection.None).ToString();
          results += "]\r\n";

          results += "SetTriggerDelay: [";
          results += Imports.SetTriggerDelay(osciloHandle, 0).ToString();
          results += "]\r\n";

          results += "SetPulseWidthQualifier: [";
          results += Imports.SetPulseWidthQualifier(osciloHandle, pwqConditions, 1, Imports.ThresholdDirection.Rising, 10, 0, Imports.PulseWidthType.GreaterThan).ToString();
          results += "]\r\n";  // 10 samples width of pulse


          results += "threshold_Major = " + threshold_Major.ToString() + "\r\n";
          results += "Sample length = " + timeIntervalNanoseconds.ToString() + " ns\r\n";
          results += "Maximum of samples = " + maxSamples.ToString() + " ns\r\n";
          MessageBox.Show(results);

          StartMeasurement();
 }

//-----------------------------------------------------------------------------------
  void StartMeasurement()
  {
      if (osciloHandle > -1 && initOsciloStatus==0)
      {
          short result;
          int indisposedTime;

          _callbackDelegate = DataInputCallback;
          result = (short)Imports.RunBlock(osciloHandle, 200, BUFFER_SIZE - 200, timeBase, overSample, out indisposedTime, 0, _callbackDelegate, IntPtr.Zero);
          if (result != 0)
          {
             MessageBox.Show("Cannot measure.\r\nError code: " + result.ToString(), generalTexts.msgLabel, MessageBoxButtons.OK, MessageBoxIcon.Error);
          }
      }
  }

//-----------------------------------------------------------------------------------
  void DataInputCallback(short handle, short status, IntPtr pVoid)
  {
      // flag to say done reading data
      if (status != (short)StatusCodes.PICO_CANCELLED)
      {
          dataSaved = true;
      }      
  }

Hitesh

Re: SetPulseWidthQualifier - no triggering

Post by Hitesh »

Hi BlahaK,

Thank you for confirming that the code now works! :D

Regards,

Post Reply