Wrong Read

Post your .Net discussions here
Post Reply
mosine
Newbie
Posts: 0
Joined: Thu Feb 09, 2017 2:03 pm

Wrong Read

Post by mosine »

Hi,
I'm developing a c# application with PicoScope3204 and I have a read problem.
I read correctly until 5V (amplitude signal from external board). If I set 7V on external board, I continue to read 5V.
I set range: 20V for channel A and B.

This is my code:

Code: Select all

timebase = 20000;
CollectBlockImmediate(timebase, 1000, channel);

----
public void CollectBlockImmediate(uint timebase, uint samples, int channel)
        {
            try
            {
                SetDefaults();
                SetTrigger(null, 0, null, 0, null, null, 0, 0, 0);
                _timebase = timebase;
                BlockDataHandler(0, samples, 2, channel); //is the same on SDK example.
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(ex.Message);
            }
        }

What's my problem??
If I want to set 1 second of timebase, how can I set number of samples?

THANKS IN ADVANCE

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

Re: Wrong Read

Post by Martyn »

Can you post more of your code, or even the project ?
Martyn
Technical Support Manager

mosine
Newbie
Posts: 0
Joined: Thu Feb 09, 2017 2:03 pm

Re: Wrong Read

Post by mosine »

Hi Martin,
Thank you for reply. This problem is very strange, because if I set range:5V and set probe:x10, my application read correctly. I can't set probe x10 for my scope.
This is my code:

Code: Select all

timebase = 20000;
 _channelSettings[0].range = Imports.Range.Range_20V;
CollectBlockImmediate(timebase, 100, 0);

---

 public void CollectBlockImmediate(uint timebase, uint samples, int channel)
        {
            try
            {
                SetDefaults();
                SetTrigger(null, 0, null, 0, null, null, 0, 0, 0);
                _timebase = timebase;
                BlockDataHandler(0, samples, 2, channel);
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(ex.Message);
            }
        }

 void BlockDataHandler(int offset, uint samples, int type, int channel)
        {
            uint status;
            uint sampleCount = samples;
            ushort segmentIndex = 0;
            int i = 0;
            PinnedArray[] minPinned = new PinnedArray[_channelCount];
            PinnedArray[] maxPinned = new PinnedArray[_channelCount];
            int timeIndisposed;

            short[] minBuffers = new short[sampleCount];
            short[] maxBuffers = new short[sampleCount];
            minPinned[channel] = new PinnedArray(minBuffers);
            maxPinned[channel] = new PinnedArray(maxBuffers);


            try
            {

                //status = Imports.SetDataBuffers(_handle, (Imports.Channel)channel, maxBuffers, minBuffers, (int)sampleCount, segmentIndex, Imports.RatioMode.Average);
                status = Imports.SetDataBuffers(handle, (Imports.Channel)channel, maxBuffers, minBuffers, (int)sampleCount, segmentIndex, Imports.RatioMode.None);
                if (status != Imports.PICO_OK)
                {
                }


                int maxSamples;
                while (Imports.GetTimebase(handle, _timebase, (int)sampleCount, out timeInterval, _oversample, out maxSamples, 0) != 0)
                {
                    _timebase++;
                }

                /* Start it collecting, then wait for completion*/
                _ready = false;
                _callbackDelegate = BlockCallback;

                
                status = Imports.RunBlock(handle, 0, (int)sampleCount, _timebase, _oversample, out timeIndisposed, 0, _callbackDelegate, IntPtr.Zero);
                Thread.Sleep(300);

                
                int countRetry = 0;

                while ((!_ready) && (countRetry < 10))
                {
                    Thread.Sleep(1);
                    countRetry++;
                }

                Imports.Stop(handle);

                if (_ready)
                {

                    short overflow;
                    uint startIndex = 0;
                    uint downSampleRatio = 0;
                    int numR = 0;
                    status = 10;
                    long sumValueVoltage = 0;

                    while ((status != 0) && (numR < 3))
                    {
                        Application.DoEvents();
                        status = Imports.GetValues(handle, startIndex, ref sampleCount, downSampleRatio, Imports.RatioMode.None, segmentIndex, out overflow);
                        numR++;
                    }
                    
                    if (status == (short)Imports.PICO_OK)
                    {
                        try
                        {
                            if (type == 0)
                            {
                                for (i = 0; i < sampleCount; i++)
                                {
                                    mVReadPeriod[i] = adc_to_mv(maxPinned[channel].Target[i], (int)_channelSettings[(int)(channel)].range);
                                    minVoltageRead = mVReadPeriod.Min();
                                    maxVoltageRead = mVReadPeriod.Max();
                                }
                            }
                            if (type == 1)
                            {
                                for (i = 0; i < sampleCount; i++)
                                {
                                    mVReadTFallTRis[i] = adc_to_mv(maxPinned[channel].Target[i], (int)_channelSettings[(int)(channel)].range);
                                    
                                }
                            }
                            if (type == 2)
                            {
                                for (i = 0; i < sampleCount; i++)
                                {
                                    mVReadPeriod[i] = adc_to_mv(maxPinned[channel].Target[i], (int)_channelSettings[(int)(channel)].range);
                                    sumValueVoltage += adc_to_mv(maxPinned[channel].Target[i], (int)_channelSettings[(int)(channel)].range);
                                }
                                averageVoltageValue = (int)(sumValueVoltage / sampleCount);
                            }
                        }
                        catch (Exception ex)
                        {
                            System.Console.WriteLine(ex.Message);

                        }
                    }
                }

                Imports.Stop(handle);
                foreach (PinnedArray p in minPinned)
                {
                    if (p != null)
                        p.Dispose();
                }
                foreach (PinnedArray p in maxPinned)
                {
                    if (p != null)
                        p.Dispose();
                }
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(ex.Message);
            }
        }

Thanks

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

Re: Wrong Read

Post by Martyn »

I am using a phone so not easy to read, I would suggest looking at what

Code: Select all

SetDefaults();
does
Martyn
Technical Support Manager

mosine
Newbie
Posts: 0
Joined: Thu Feb 09, 2017 2:03 pm

Re: Wrong Read

Post by mosine »

Hi Martin,
I try your suggest and I don't resolve.
If I set Range_5V: read 2.5V .
If I set Range_10V: read 5V
If I set Range_20V: read 10V

I must read 7.5-7.7 V.

Thanks

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

Re: Wrong Read

Post by Martyn »

Can you post the raw ADC counts for the 100 samples you are collecting, the data in the PinnedArray, and let me know what the input signal is, level and type.
Martyn
Technical Support Manager

mosine
Newbie
Posts: 0
Joined: Thu Feb 09, 2017 2:03 pm

Re: Wrong Read

Post by mosine »

Hi Martin,
I attach the files.
Attachments
collect_20V.txt
(5.45 KiB) Downloaded 457 times
collect_10V.txt
(5.46 KiB) Downloaded 500 times
collect_5V.txt
(5.47 KiB) Downloaded 496 times

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

Re: Wrong Read

Post by Martyn »

I would be very suspicious of the data coming back as identical for every value. I would suggest that you break on entry to BlockDataHandler and then step through your code making sure that the status return codes are OK for all calls, and at each step check what data is present in the buffers.
Martyn
Technical Support Manager

mosine
Newbie
Posts: 0
Joined: Thu Feb 09, 2017 2:03 pm

Re: Wrong Read

Post by mosine »

Hi Martin,
I followed your suggestion and I verified that all calls return PICO_OK.
PicoScope software read the same value.

mosine
Newbie
Posts: 0
Joined: Thu Feb 09, 2017 2:03 pm

Re: Wrong Read

Post by mosine »

Hi Martin,
I check the situation by example console of SDK: same read.

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

Re: Wrong Read

Post by Martyn »

With value reading the same for different ranges then that would suggest the range is not being changed. I am back on the phone so not easy to check code

What signal are you applying to the scope?
Martyn
Technical Support Manager

mosine
Newbie
Posts: 0
Joined: Thu Feb 09, 2017 2:03 pm

Re: Wrong Read

Post by mosine »

Hi Martin,
yesterday we checked the problem is hardware problem.
Thank you for your patience.

Have a nice day.

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

Re: Wrong Read

Post by Martyn »

Thanks for letting us know :)
Martyn
Technical Support Manager

Post Reply