Unexpected behavior of timebase

Post your .Net discussions here
Post Reply
mzeeshan
Newbie
Posts: 0
Joined: Wed Jun 28, 2017 7:26 am

Unexpected behavior of timebase

Post by mzeeshan »

Hello,

I'm working with PicoScope 5242A for a project and I'm using the test signal from the builtin signal generator.

My first goal was to observe the signal in a chart and change its timebase for adjusting the number of sine waves in the block. I setup the builtin signal generator (I just use the example you supplied to make a sine wave of 13.56MHz) and continuously requested for a new block in a loop. I can see the sine wave at first but as I change the timebase during the loop, I expect the x-axis to kind of zoom-in or zoom-out as I increase of decrease the timebase in realtime. However, here is what I actually observe:

1. The minimum timebase for my case (3) displays almost 20 sine waves in the block.

2. As I increase the timebase from 3, the number of sinewaves seem to be rather random. They seem to inrease but then suddenly I can see like 10 sinewaves and then back to almost like 100s of them.

3. Also when I set the timebase so that the interval is 8ns. The block data signal does not match the signal (for the same input and sample interval) in PicoScope software.

Could you please check my code and point out what am I doing wrong here.

Thank you.

Code: Select all

 public void getBlockData()
        {
            uint status;

            //-------------------------------------------------------------------------------------------------------------------------
            //****************************           Initialize signal gen           *************************************************
            //------------------------------------------------------------------------------------------------------------------------

            try
            {
                startFreq = Convert.ToDouble("13560000");
                pkToPk = Convert.ToUInt32("2000") * 1000;
                offset = Convert.ToInt32("0");

            }
            catch
            {
                MessageBox.Show("Error with start frequency, offset and/or pktopk", "INVALID VALUES", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }


            stopFreq = startFreq;
            increment = 0;
            dwellTime = 0;
            sweeptype = Imports.SweepType.PS5000A_UP;

            Imports.WaveType wavetype = Imports.WaveType.PS5000A_SINE;


            if (wavetype == Imports.WaveType.PS5000A_DC_VOLTAGE)
            {
                pkToPk = 0;
            }



            status = Imports.SetSigGenBuiltInV2(_handle, offset, pkToPk, wavetype, startFreq, stopFreq, increment, dwellTime, sweeptype,
                                                    operations, shots, sweeps, triggertype, triggersource, extinthreshold);

            if (status != StatusCodes.PICO_OK)
            {
                MessageBox.Show("Error SetSigGenBuiltInV2 error code :" + status.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

            }

            //----------------------------------------------------------------------------------------------------------------------------




            status = Imports.SetChannel(_handle, Imports.Channel.ChannelA, 1, Imports.Coupling.PS5000A_DC, Imports.Range.Range_10V, 0);
            status = Imports.SetChannel(_handle, Imports.Channel.ChannelB, 0, Imports.Coupling.PS5000A_DC, Imports.Range.Range_10V, 0);
            //status = Imports.SetChannel(_handle, Imports.Channel.ChannelC, 0, Imports.Coupling.PS5000A_DC, Imports.Range.Range_10V, 0);
            //status = Imports.SetChannel(_handle, Imports.Channel.ChannelD, 0, Imports.Coupling.PS5000A_DC, Imports.Range.Range_10V, 0);

            short enable = 0;
            uint delay = 0;
            short threshold = 25000;
            short auto = 0;

            status = Imports.SetSimpleTrigger(_handle, enable, Imports.Channel.ChannelA, threshold, Imports.ThresholdDirection.Rising, delay, auto);

            _ready = false;
            _callbackDelegate = BlockCallback;
            _channelCount = 4;
            string data;
            int x;

            //textMessage.Clear();
            //textData.Clear();

            bool retry;
            uint sampleCount = 1024;
            PinnedArray[] minPinned = new PinnedArray[_channelCount];
            PinnedArray[] maxPinned = new PinnedArray[_channelCount];

            int timeIndisposed;
            short[] minBuffers = new short[sampleCount];
            short[] maxBuffers = new short[sampleCount];
            minPinned[0] = new PinnedArray(minBuffers);
            maxPinned[0] = new PinnedArray(maxBuffers);
            status = Imports.SetDataBuffers(_handle, Imports.Channel.ChannelA, maxBuffers, minBuffers, (int)sampleCount, 0, Imports.RatioMode.None);
            //textMessage.AppendText("BlockData\n");

            /*  find the maximum number of samples, the time interval (in timeUnits),
             *		 the most suitable time units, and the maximum _oversample at the current _timebase*/
            int timeInterval;
            int maxSamples;
            while (Imports.GetTimebase(_handle, _timebase, (int)sampleCount, out timeInterval, out maxSamples, 0) != 0)
            {
                //textMessage.AppendText("Timebase selection\n");
                _timebase++;

            }
            //textMessage.AppendText("Timebase Set\n");

            /* Start it collecting, then wait for completion*/
            _ready = false;
            _callbackDelegate = BlockCallback;
            // _timebase = 3;
            while (true)
            {
                do
                {
                    retry = false;
                    status = Imports.RunBlock(_handle, 0, (int)sampleCount, _timebase, out timeIndisposed, 0, _callbackDelegate, 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)
                    {
                        status = Imports.ChangePowerSource(_handle, status);
                        retry = true;
                    }
                    else
                    {
                        //textMessage.AppendText("Run Block Called\n");
                    }
                }
                while (retry);

                //textMessage.AppendText("Waiting for Data\n");

                while (!_ready)
                {
                    Thread.Sleep(100);
                }

                Imports.Stop(_handle);

                if (_ready)
                {
                    short overflow;
                    status = Imports.GetValues(_handle, 0, ref sampleCount, 1, Imports.DownSamplingMode.None, 0, out overflow);
                    if (status == (short)StatusCodes.PICO_OK)
                    {
                        //textMessage.AppendText("Have Data\n");
                        double chRange = 20;
                        int chResolution = 14;
                        listCh1RawData.Clear();
                        for (int i = 0; i < maxBuffers.Length; i++)
                        {
                            listCh1RawData.Add(i, (double)maxBuffers[i] * chRange / (2 ^ chResolution));
                        }
                        this.Invoke((MethodInvoker)delegate
                        {
                            zedGraphControlOscView.AxisChange();
                            zedGraphControlOscView.Invalidate();
                            zedGraphControlOscView.Refresh();
                        });
                        //for (x = 0; x < sampleCount; x++)
                        //{
                        //    data = maxBuffers[x].ToString();

                        //    //textData.AppendText(data);
                        //    //textData.AppendText("\n");
                        //}


                    }
                    else
                    {
                        //textMessage.AppendText("No Data\n");

                    }
                }
                else
                {
                    //textMessage.AppendText("data collection aborted\n");
                }

                Imports.Stop(_handle);
                Thread.Sleep(500);
            }
            foreach (PinnedArray p in minPinned)
            {
                if (p != null)
                    p.Dispose();
            }
            foreach (PinnedArray p in maxPinned)
            {
                if (p != null)
                    p.Dispose();
            }

        }

        private void numericUpDown1_ValueChanged(object sender, EventArgs e)
        {
            _timebase = (uint)numericUpDown1.Value;
            int intervalTmp = 0;
            int maxSamplesTmp = 0;
            Imports.GetTimebase(_handle, _timebase, 1024, out intervalTmp, out maxSamplesTmp, 0);
            kryptonLabelSampleInterbal.Text = intervalTmp.ToString() + " ns";            
        }

Hitesh

Re: Unexpected behavior of timebase

Post by Hitesh »

Hi mzeeshan,

The 'change' in the number of cycles may be down to using a sampling frequency that is a multiple of the signal generator frequency.

It might be useful to see a psdata file from PicoScope 6 so that we can see the settings and the waveform captured.

Regards,

mzeeshan
Newbie
Posts: 0
Joined: Wed Jun 28, 2017 7:26 am

Re: Unexpected behavior of timebase

Post by mzeeshan »

Thank you Hitesh for the reply.

I have been using the PicoScope software for sometime now but I have not really paid attention to the sample interval and the number of samples on the screen until now. I believed
1. when we set the number of samples to some number k, then that is fixed and
2. each time we change the x-axis resolution in terms of time/div, we change the sample interval.

But I just noticed that
1. Even though we have fixed the time number of data points to some number k, the actual number of data points collected can be much lower than that (probably depending on the time/div setting). Moreover, as I wondered how could the PicoScope software receive such a nicely shaped sine wave with just a few data points, I spotted the interpolation setting in the Preferences which enable that. However, with that feature turned off, the signal looks choppy and toothy.
2. Changing the x-axis resolution doesn't always change the sample interval (that means your software does not really change the timebase for every change in time/div). Instead, the number of data points actually received are varied to adjust the signal on the new resolution setting.

Now I can replicate the PicoScope screen easily, I did not notice these things before. But I wonder why I can't get more data points for the same sample interval to get a smoother signal? (Or are you already using the maximum number of data points that the hardware can provide at a given sample rate? Sorry I have not done the calculations yet. For example, for a 13.56 MHz signal how many maximum data points can be plotted for a single sine wave? )

Regards,

Zeeshan

Hitesh

Re: Unexpected behavior of timebase

Post by Hitesh »

Hi Zeeshan,

You may find this post useful.

When you set the collection time and the number of samples, the application will determine the fastest possible possible sampling rate and the number of samples will be adjusted according to that and the time across the screen.

I do not have a PicoScope 5000 Series device to test with at the time of writing, but the maximum number of points will depend on the resolution set and the number of channels enabled as this determines the maximum sampling rate e.g. at 8-bit resolution with 2 channels enabled, the maximum sampling rate is 500 MS/s.

I hope that this helps,

Post Reply