Test and Measurement Forum

Wrong Read

Post your .Net discussions here

Wrong Read

Postby mosine » Mon Apr 03, 2017 3:43 pm

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
mosine
Newbie
 
Posts: 0
Joined: Thu Feb 09, 2017 2:03 pm

Re: Wrong Read

Postby Martyn » Tue Apr 04, 2017 10:55 am

Can you post more of your code, or even the project ?
Martyn
Technical Support Manager
Martyn
Site Admin
Site Admin
 
Posts: 2667
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: Wrong Read

Postby mosine » Tue Apr 04, 2017 3:38 pm

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<short>[] minPinned = new PinnedArray<short>[_channelCount];
            PinnedArray<short>[] maxPinned = new PinnedArray<short>[_channelCount];
            int timeIndisposed;

            short[] minBuffers = new short[sampleCount];
            short[] maxBuffers = new short[sampleCount];
            minPinned[channel] = new PinnedArray<short>(minBuffers);
            maxPinned[channel] = new PinnedArray<short>(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<short> p in minPinned)
                {
                    if (p != null)
                        p.Dispose();
                }
                foreach (PinnedArray<short> p in maxPinned)
                {
                    if (p != null)
                        p.Dispose();
                }
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(ex.Message);
            }
        }



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

Re: Wrong Read

Postby Martyn » Tue Apr 04, 2017 8:04 pm

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
Martyn
Site Admin
Site Admin
 
Posts: 2667
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: Wrong Read

Postby mosine » Wed Apr 05, 2017 11:19 am

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
mosine
Newbie
 
Posts: 0
Joined: Thu Feb 09, 2017 2:03 pm

Re: Wrong Read

Postby Martyn » Wed Apr 05, 2017 12:23 pm

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
Martyn
Site Admin
Site Admin
 
Posts: 2667
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: Wrong Read

Postby mosine » Wed Apr 05, 2017 12:52 pm

Hi Martin,
I attach the files.
Attachments
collect_20V.txt
(5.45 KiB) Downloaded 8 times
collect_10V.txt
(5.46 KiB) Downloaded 8 times
collect_5V.txt
(5.47 KiB) Downloaded 7 times
mosine
Newbie
 
Posts: 0
Joined: Thu Feb 09, 2017 2:03 pm

Re: Wrong Read

Postby Martyn » Wed Apr 05, 2017 1:40 pm

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
Martyn
Site Admin
Site Admin
 
Posts: 2667
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: Wrong Read

Postby mosine » Wed Apr 05, 2017 2:03 pm

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

Postby mosine » Wed Apr 05, 2017 2:23 pm

Hi Martin,
I check the situation by example console of SDK: same read.
mosine
Newbie
 
Posts: 0
Joined: Thu Feb 09, 2017 2:03 pm

Re: Wrong Read

Postby Martyn » Wed Apr 05, 2017 5:37 pm

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
Martyn
Site Admin
Site Admin
 
Posts: 2667
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: Wrong Read

Postby mosine » Thu Apr 06, 2017 6:28 am

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

Have a nice day.
mosine
Newbie
 
Posts: 0
Joined: Thu Feb 09, 2017 2:03 pm

Re: Wrong Read

Postby Martyn » Thu Apr 06, 2017 8:26 am

Thanks for letting us know :)
Martyn
Technical Support Manager
Martyn
Site Admin
Site Admin
 
Posts: 2667
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots


Return to .Net Languages (C#, VB.Net, .)

Who is online

Users browsing this forum: No registered users and 0 guests