Test and Measurement Forum

Pico 4000 : Pulse Width Qualifier issues

Post your C and C++ discussions here

Pico 4000 : Pulse Width Qualifier issues

Postby bouttier » Thu Jun 23, 2016 2:20 pm

Hello all !

I'm having some issues to set up a pulse width qualifier on my trigger !

Let's explain the problem :

I have a 100Hz rectangular 0 to 2V signal with 50% duty cycle, and the trigger fires as following :
When i set my pulse width limit around 1 250 000 samples of 8ns each (timebase n=1) , it triggers for 10ms periods (5ms at 0V and 5ms at 2V)

But I don't understand why ! The pulse only last for 5ms so why isn't the trigger firing around a 625 000 samples limit ?

It's important for me because the signals I want to study hasn't a 50% duty cycle ! When i set the duty cycle of my signal to 20% (1 period = 2 ms at 2V and 8ms at 0V) the trigger behave exactly the same : it triggers with 1 250 000 samples of 8ns while the pulse duration is very different ...

I think there's something i don't understand here, so can anyone help me please ?

Martin
bouttier
Newbie
 
Posts: 1
Joined: Thu Jun 23, 2016 1:19 pm

Re: Pico 4000 : Pulse Width Qualifier issues

Postby Hitesh » Thu Jun 23, 2016 3:02 pm

Hi Martin,

The pulse width counter is reset when a rising or falling edge is encountered (depending on how the trigger is setup) and then starts again until the trigger event occurs.

As you are specifying 1,250,000 samples at 8 ns (10 ms) the trigger will fire when the condition is met at 10 ms from the point where the counter was activated.

Does the Pulse Width Trigger work in the PicoScope 6 software? It would be helpful to see a screenshot of the settings.

Please also post the code snippets showing how you set up the trigger in your code. Which version of the ps4000.dll are you using?

Regards,
Hitesh

Technical Specialist
Pico Technology
Hitesh
Site Admin
Site Admin
 
Posts: 2058
Joined: Tue May 31, 2011 3:43 pm
Location: St. Neots, Cambridgeshire

Re: Pico 4000 : Pulse Width Qualifier issues

Postby bouttier » Fri Jun 24, 2016 9:12 am

Hi Hitesh,

Thanks for your reply, so yes the pulse width trigger works perfectly in the soft as you can see on the screenshots.
This is the behaviour i want to reproduce.

My working trigger settings (pulse width between 117500 samples and 1325000 samples = 9 to 11ms periods):

Code: Select all
int16_t   triggerVoltageMax = mv_to_adc(2200,   unit->channelSettings[PS4000_CHANNEL_A].range); // ChannelInfo stores ADC counts
printf("%d", triggerVoltageMax);
int16_t   triggerVoltageMin = mv_to_adc(1800,   unit->channelSettings[PS4000_CHANNEL_A].range); // ChannelInfo stores ADC counts
printf("%d", triggerVoltageMin);




    struct tTriggerChannelProperties sourceDetails = {   triggerVoltageMax,
                                                        256,
                                                        triggerVoltageMin,
                                                        256,
                                                        PS4000_CHANNEL_A,
                                                        WINDOW };

    struct tTriggerConditions conditions = {   CONDITION_TRUE,
                                                CONDITION_DONT_CARE,
                                                CONDITION_DONT_CARE,
                                                CONDITION_DONT_CARE,
                                                CONDITION_DONT_CARE,
                                                CONDITION_DONT_CARE,
                                                CONDITION_TRUE };



    struct tTriggerDirections directions = {   RISING,
                                                NONE,
                                                NONE,
                                                NONE,
                                                NONE,
                                                NONE };

    struct tPwqConditions conditions2 = {       CONDITION_TRUE,
                                                CONDITION_DONT_CARE,
                                                CONDITION_DONT_CARE,
                                                CONDITION_DONT_CARE,
                                                CONDITION_DONT_CARE,
                                                CONDITION_DONT_CARE};

    uint32_t triggerTimeMin = 1175000;
    uint32_t triggerTimeMax = 1325000;

    struct tPwq PulseWidth = {  &conditions2,
                                1,
                                RISING,
                                triggerTimeMin,
                                triggerTimeMax,
                                PW_TYPE_IN_RANGE};


But what I want is setting the pulse width for the 2V pulse duration only, not the entire period of the signal.
For example when I will set my pulse width range to 600 000-650 000 samples, the 50% duty cycle signals will triggers, but if i change the duty cycle to 20%, it will not trigger anymore. How can I do that ?

Thanks for your help !

Martin
Attachments
100hz_duty_cycle_20.png
100 Hz rectangular signal with 20% duty cycle and trigger set at 1 ms pulse width (fires with settings under 2ms)
100hz_duty_cycle_50.png
100 Hz rectangular signal with 50% duty cycle and trigger set at 3 ms pulse width (fires with settings under 5ms)
bouttier
Newbie
 
Posts: 1
Joined: Thu Jun 23, 2016 1:19 pm

Re: Pico 4000 : Pulse Width Qualifier issues

Postby bouttier » Mon Jun 27, 2016 9:21 am

Okay, I solved my problem by setting the direction of the trigger on RISING_OR_FALLING !

Now I have a new issue : I would like to get continuous triggers on streaming mode (currently the streaming is stopped each time a trigger fires).

But I don't understand where the autostop flag is set up to 1 ...

Does anyone know how to trigger, display the triggered index, rearm the trigger and repeat the whole thing in streaming mode ? Should I open a new topic for this issue ?

Regards,
Martin
bouttier
Newbie
 
Posts: 1
Joined: Thu Jun 23, 2016 1:19 pm

Re: Pico 4000 : Pulse Width Qualifier issues

Postby Hitesh » Mon Jun 27, 2016 11:31 am

Hi Martin,

You can open a new topic if you wish.

It would be helpful to know how many samples you need to capture, at what sampling rate and with how many channels. Your images

The autoStop parameter is set in the call to ps4000RunStreaming().

When collecting data in streaming mode, the trigger can only be activated once. If you set autoStop to false, the device will continue to collect data. However, if you need to wait for another trigger event, you will need to stop data collection and start again.

Hope this helps,
Hitesh

Technical Specialist
Pico Technology
Hitesh
Site Admin
Site Admin
 
Posts: 2058
Joined: Tue May 31, 2011 3:43 pm
Location: St. Neots, Cambridgeshire

Re: Pico 4000 : Pulse Width Qualifier issues

Postby bouttier » Mon Jun 27, 2016 11:49 am

Thanks for your quick reply !

So I need to trigger every 10ms (with approx 10% variability), my sampling rate can be around 1 to 10 us/sample.
I tried to call the StreamingDataHandler in a while loop but i get only around 80/1000 triggers for a 10 seconds acquisition...
So I understand it won't be possible in streaming mode, is that right ?

I tried it on block mode, by setting a loop as following :

Code: Select all
    int i = 0;
        while(!_kbhit())
    {
        BlockDataHandler(unit, "10 readings after trigger\n", 0);
        i++;
        printf("%d \n", i);
    }


But when i collect my triggers for 10 seconds, it seems like only 600/1000 impulsions fires a trigger ...

If I set my frequency to 10Hz (instead of 100Hz), the trigger fires for 100/100 impulsions, i think i'm limited by the fact that calling the BlockDataHandler take some time, what can I do to reduce the time between 2 triggers ?

Martin
bouttier
Newbie
 
Posts: 1
Joined: Thu Jun 23, 2016 1:19 pm

Re: Pico 4000 : Pulse Width Qualifier issues

Postby Hitesh » Mon Jun 27, 2016 1:50 pm

Hi Martin,

Please try the rapid block mode of collecting data.

There is an example in the C console example and you will need to segment the memory. Rapid block data collection reduces the time between successive captures (it can be down a few microseconds at the fastest timebases) and then transfers the data to the PC when you call the ps4000GetValuesBulk() function when data collection is complete.

Hope this helps,
Hitesh

Technical Specialist
Pico Technology
Hitesh
Site Admin
Site Admin
 
Posts: 2058
Joined: Tue May 31, 2011 3:43 pm
Location: St. Neots, Cambridgeshire

Re: Pico 4000 : Pulse Width Qualifier issues

Postby bouttier » Tue Jun 28, 2016 9:43 am

Hi Hitesh,

So this is working now : My trigger is functioning and there is no misses of pulses.

But I have a problem : When I use the date of the PC to measure my Period Time, it's not very accurate ... there is an average 20us difference with the reality. As you can see on the screenshots, my application tends to a 9977us average time per period, with periods between 9900 and 10000 us. But when i observe my signal with PicoScope 6, i never see a period under 9999 or over 10001 us

How can I increase the accuracy of my system ? I really need it because I have to report statistics on a signal and I can't allow these statistics to be so poorly accurate.

Thanks again for your help,
Martin
Attachments
triggers.png
Periods between 9914us and 10061us in my application (only 50 triggers -> 0.5s of acquisition)
picoscope6.png
Periods are never under 9999us or over 10001us
(10.41 KiB) Not downloaded yet
bouttier
Newbie
 
Posts: 1
Joined: Thu Jun 23, 2016 1:19 pm

Re: Pico 4000 : Pulse Width Qualifier issues

Postby Hitesh » Wed Jun 29, 2016 12:30 pm

Hi Martin,

How are you calculating the time?

When you call the ps4000RunBlock() function there will be a delay of tens of milliseconds while the device is setup for data collection as well as any subsequent time period while waiting for a trigger, the time for the data collection to complete and the device to indicate that it is ready.

The current PicoScope 3000D and D MSO models support trigger timestamping but are only 8-bit resolution devices compared to the 12-bit resolution of the PicoScope 4000 Series devices.

Regards,
Hitesh

Technical Specialist
Pico Technology
Hitesh
Site Admin
Site Admin
 
Posts: 2058
Joined: Tue May 31, 2011 3:43 pm
Location: St. Neots, Cambridgeshire

Re: Pico 4000 : Pulse Width Qualifier issues

Postby bouttier » Wed Jun 29, 2016 1:23 pm

Hi Hitesh,

Here is my code to calculate the time between two triggers (unfortunately based on the PC CLOCK) :

Code: Select all
     
while(!_kbhit())
        {
        g_ready = FALSE;

        clock_gettime(CLOCK_MONOTONIC, &specInit);

        ps4000RunBlock(unit->handle, 0, sampleCount, timebase, oversample,   &timeIndisposed, 0, CallBackBlock, NULL);
        ps4000GetTriggerTimeOffset(unit->handle, &triggerTimeUpper, &triggerTimeLower, &timeUnit, 0);

        while (!g_ready && !_kbhit())
        {

        }

        if (g_ready)
        {
            ps4000GetValues(unit->handle, 0, (uint32_t*) &sampleCount, 1, RATIO_MODE_NONE, 0, NULL);
        }

        clock_gettime(CLOCK_MONOTONIC, &specCurrent);

        timeMicroSecondInitial = specInit.tv_nsec/1000;
        timeMicroSecondCurrent = specCurrent.tv_nsec/1000 ;
        timeMicroSecondDifference = timeMicroSecondCurrent-timeMicroSecondInitial;

        if(timeMicroSecondDifference < 0)
        {
           timeMicroSecondDifference = 1000000 + timeMicroSecondDifference;
        }


        if(j > 0)
        {
            totalTime += timeMicroSecondDifference;
            moyenne = totalTime/j;

            printf("Trigger %d   Period Time :  %05ld us    Total Time : %ld us     Average Period = %li us\n",j , timeMicroSecondDifference, totalTime, moyenne);
        }

        j++;
}


there will be a delay of tens of milliseconds while the device is setup for data collection

Did you mean tens of MicroSeconds ? Because I don't see such a delay in my calculation ...

One work around might be to trigger the signal generator output every time the input channel is triggered and measure the time between the signals output. There might be a few milliseconds delay though.

Please tell me you meant MicroSeconds as well ? If not I will have to tell my tutor the equipment he gave me cannot be used for our purpose ...

Thanks again for your help !
Martin
bouttier
Newbie
 
Posts: 1
Joined: Thu Jun 23, 2016 1:19 pm

Re: Pico 4000 : Pulse Width Qualifier issues

Postby Martyn » Tue Jul 05, 2016 9:28 am

ps4000GetTriggerTimeOffset does not provide the time between two adjacent triggers, it gives the jitter between the the true trigger point that may lie between two ADC samples with the ADC sample that is tagged as the trigger.. The values will often be 0 or very small, and always be smaller than the actual sample interval being used. The purpose of the function is to adjust screen drawing of the trace in PicoScope 6 so that the trace does not jump about.

It is not possible to time difference between adjacent triggers with the 4000 series devices.

Can you explain what you are trying to measure ? Is it the pulse width of the trigger event ?
Martyn
Technical Specialist
Martyn
Site Admin
Site Admin
 
Posts: 2346
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: Pico 4000 : Pulse Width Qualifier issues

Postby bouttier » Tue Jul 19, 2016 9:58 am

Hi Martyn,

I am trying (and succeeding) to precisely measure time periods, and I want my program to fire triggers when periods are out of selected range, but I can't afford to miss one if two periods in a row are out of range, so I need a continuous acquisition and datation (for 3 to 30 days tests).

I eventually came to use the streaming mode and I made up some manual trigger in my program, which doesn't need the trigger of the picoscope. For those who would like to see my solution, you can find it in my next topic (which highlight a sampling Interval issue).

Sorry for the answer delay,
Martin
bouttier
Newbie
 
Posts: 1
Joined: Thu Jun 23, 2016 1:19 pm


Return to C and C++

Who is online

Users browsing this forum: No registered users and 0 guests