P5000A RatioMode.Decimate

Post general discussions on using our drivers to write your own software here
Post Reply
engkhong
Newbie
Posts: 0
Joined: Fri May 15, 2020 6:12 pm

P5000A RatioMode.Decimate

Post by engkhong »

Hi,
Facing issue on using RatioMode.Decimate:
I am using PICO Scope to capture the Sine/Square wave. I need to reduce the process time & using RatioMode.
a) All 4 Channels use to capture signal
b) TimeBase 7 (40nS)
c) Range 5V

Code: Select all

PS5000AImports.MaximumValue(m_handle, out m_maxValue);         // set max. ADC Counts
            PS5000AImports.MinimumValue(m_handle, out m_minValue);
            numSamplePerChannel = inSampleSizePerCH;        // set Sampling coutn per channel

            if (inTriggerMode == 0)       //Trigger by CHA
            {
                ADCThreshold = (short)(inThreshold * m_maxValue * 1000 / (m_inputRanges[(int)m_channelSettings[(int)(PS5000AImports.Channel.ChannelA)].Range]));
                status = (short)PS5000AImports.SetSimpleTrigger(m_handle, 1, PS5000AImports.Channel.ChannelA, ADCThreshold, PS5000AImports.ThresholdDirection.Rising, 0, 0); //no trigger, delay 10*8ns
            }
            else if (inTriggerMode == 2)  //Trigger by CHB/CHZ with LB8001  
            {
                ADCThreshold = (short)(inThreshold * m_maxValue * 1000 / (m_inputRanges[(int)m_channelSettings[(int)(PS5000AImports.Channel.ChannelC)].Range]));
                status = (short)PS5000AImports.SetSimpleTrigger(m_handle, 1, PS5000AImports.Channel.ChannelC, ADCThreshold, PS5000AImports.ThresholdDirection.Rising, 0, 0); //no trigger, delay 10*8ns
            }
            else if (inTriggerMode == 3)   //Trigger by CHZ with LB8002
            {
                ADCThreshold = (short)(inThreshold * m_maxValue * 1000 / (m_inputRanges[(int)m_channelSettings[(int)(PS5000AImports.Channel.ChannelD)].Range]));
                status = (short)PS5000AImports.SetSimpleTrigger(m_handle, 1, PS5000AImports.Channel.ChannelD, ADCThreshold, PS5000AImports.ThresholdDirection.Rising, 0, 0); //no trigger, delay 10*8ns
            }
            else
            {
                status = (short)PS5000AImports.SetSimpleTrigger(m_handle, 0, PS5000AImports.Channel.ChannelA, 1, PS5000AImports.ThresholdDirection.Rising, 0, 0); //no trigger, delay 10*8ns
            }

            m_BlockReady = false;
            m_callbackDelegateBlockReady = BlockCallback;

            minBuffers = new short[NumMaxChannel][];
            maxBuffers = new short[NumMaxChannel][];
            minPinned = new PinnedArray[NumMaxChannel];
            maxPinned = new PinnedArray[NumMaxChannel];
          
            for (ch = 0; ch < NumMaxChannel; ch ++)
            {
                minBuffers[ch] = new short[numSamplePerChannel];
                maxBuffers[ch] = new short[numSamplePerChannel];
                minPinned[ch] = new PinnedArray(minBuffers[ch]);
                maxPinned[ch] = new PinnedArray(maxBuffers[ch]);

                if (ratioMode == PS5000AImports.RatioMode.Decimate)
                {
                    status = (short)PS5000AImports.SetDataBuffers(m_handle, (PS5000AImports.Channel)(ch), maxBuffers[ch], minBuffers[ch], (int)numSamplePerChannel, 0, PS5000AImports.RatioMode.Decimate);
----------------------------------------
"this status return 13" 
----------------------------------------
                }
                else
                {
                    status = (short)PS5000AImports.SetDataBuffers(m_handle, (PS5000AImports.Channel)(ch), maxBuffers[ch], minBuffers[ch], (int)numSamplePerChannel, 0, PS5000AImports.RatioMode.None);
                }
            }

 outTimeInterval = 0;
            while (PS5000AImports.GetTimebase(m_handle, inTimebase, (int)numSamplePerChannel, out outTimeInterval, out numMaxOutSamples, 0) != 0)
            {
                inTimebase++;
            }

            //Start it collecting, then wait for completion
            m_BlockReady = false;
            m_callbackDelegateBlockReady = BlockCallback;

            do
            {
                retry = false;
                 status = (short)PS5000AImports.RunBlock(m_handle, inPreTriggerSample, (int)numSamplePerChannel, inTimebase, out timeIndisposed, 0, m_callbackDelegateBlockReady, IntPtr.Zero);

                if (status == (short)StatusCodes.PICO_POWER_SUPPLY_CONNECTED ||
                    status == (short)StatusCodes.PICO_POWER_SUPPLY_NOT_CONNECTED ||
                    status == (short)StatusCodes.PICO_POWER_SUPPLY_UNDERVOLTAGE)
                {
                    retry = true;
                }
            }
            while (retry);

   

            for (i = 0; i < inTimeout_cycle; i++)
            {
                if (!m_BlockReady)
                {
                    if (i == 999)
                    {
                        return false;
                    }
                    Thread.Sleep(100);
                }
                else
                {
                    break;
                }
            }

            PS5000AImports.Stop(m_handle);

 if (m_BlockReady)
            {
                short overflow;
                if (ratioMode == PS5000AImports.RatioMode.Decimate)
                {
                  //status =              Imports.GetValues (_handle,  0, ref sampleCount,                       5, Imports.RatioMode.Decimate,               0, out overflow);
                    status = (short)PS5000AImports.GetValues(m_handle, 0, ref numSamplePerChannel, downSampleRatio, PS5000AImports.DownSamplingMode.Decimate, 0, out overflow);
                }
                else
                {
                    status = (short)PS5000AImports.GetValues(m_handle, 0, ref numSamplePerChannel, 1, PS5000AImports.DownSamplingMode.None, 0, out overflow);
                }

                outDataArray = new float[numSamplePerChannel][];
                if (status == (short)StatusCodes.PICO_OK)
                {
                    index = 0;
                    for (x = 0; x < numSamplePerChannel; x++)
                    {
                        values = new List();
                        for (ch = 0; ch < NumMaxChannel; ch ++)
                        {
 
                            value = (float)(maxPinned[ch].Target[x] * m_inputRanges[(int)m_channelSettings[ch].Range] / m_maxValue) / 1000;
                            values.Add(value);
                        }
                        outDataArray[index] = values.ToArray();
                        index++;
                    }
                }
                ret = true;
            }
Please help.

Martyn
Site Admin
Site Admin
Posts: 4501
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: P5000A RatioMode.Decimate

Post by Martyn »

What exact issue are you seeing?

If you need to sample at an interval of 40nsecs then you should not use decimate as this ignores many of the samples you collect. For example if you collected 100 samples at your chosen rate of 40nsecs and then for example you decimated by a factor of 10 you would just get samples 1, 11, 21,31, 41 .... 91. You could achieve the same by sampling at 400nsecs.
Martyn
Technical Support Manager

engkhong
Newbie
Posts: 0
Joined: Fri May 15, 2020 6:12 pm

Re: P5000A RatioMode.Decimate

Post by engkhong »

Hi Sir,
Thanks got it.

Post Reply