Test and Measurement Forum

Generating Sine using PS5000

Post your .Net discussions here

Generating Sine using PS5000

Postby Yariv » Tue Mar 22, 2016 1:23 pm

Hi, I have my PS5000 connected to my PC. I'm using C# to program it.
I need to do a simple test of generating a sine waveform (2 V-p-p, 1KHz, 1vdc offset), then sample the scope (Channel A) to read back the waveform.
I can't find the correct function to import for generating the sine.
Can anyone help me please? Is there an example for this kind of code? Thanks.
Yariv
Newbie
 
Posts: 0
Joined: Tue Mar 22, 2016 1:16 pm

Re: Generating Sine using PS5000

Postby Hitesh » Tue Mar 22, 2016 1:48 pm

Hi Yariv,

Which specific PicoScope 5000 Series device are you using?

Is it the PicoSc ope 5203 or 5204 which use the ps5000 API functions or one of the PicoScope 5000 A/B oscilloscopes which uses the ps5000a API functions?

Regards,
Hitesh

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

Re: Generating Sine using PS5000

Postby Yariv » Wed Mar 23, 2016 11:37 am

Hi,
I was finaly able to generate a sine.
Now, I looped the scope's output back to the input channel and I need to measure the V-p-p and maybe even all of the samples (read into a double[] buffer). Is it possible?
I'm using the ps500a.dll.
Thanks
Yariv
Newbie
 
Posts: 0
Joined: Tue Mar 22, 2016 1:16 pm

Re: Generating Sine using PS5000

Postby Hitesh » Wed Mar 23, 2016 3:06 pm

Hi Yariv,

Yes this is possible.

The Software Development Kit contains examples for Block mode and Streaming mode captures (refer to the Programmer's Guide for further information on these modes) - these should be in the C:\PicoSDK\PS5000A\C# folder.

Once you have set up the channels and trigger, you can call the signal generator function prior to starting the data collection.

How long do you need to capture data for and at what sampling interval?

Regards,
Hitesh

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

Re: Generating Sine using PS5000

Postby Yariv » Thu Mar 24, 2016 11:13 am

I'm using the Block sample to acquire the data. A Pulser waveform is injected via external Function Generator. The results I get are not reasonable (a buffer full of the same values). Can you point out the difference between the streaming and the block?
Yariv
Newbie
 
Posts: 0
Joined: Tue Mar 22, 2016 1:16 pm

Re: Generating Sine using PS5000

Postby Hitesh » Tue Mar 29, 2016 2:26 pm

Hi Yariv,

You can find descriptions for Block and Streaming mode in the PicoScope 5000 Series (A API) Programmer's Guide (see sections 7.1 and 7.4).

You can also find information on these modes of data collection via The A to Z of PC Oscilloscopes.

Block mode is typically used for short captures at fast sample rates while streaming mode is normally used for longer term captures with relatively slower sampling rates.

If you are getting the same values, it might be that your sampling interval is too small for the number of samples that you are collecting.

Could you please indicate the number of samples that you are collecting and the timebase index being used?

As an alternative to posting your code here, you can send it to support@picotech.com

Regards,
Hitesh

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

Re: Generating Sine using PS5000

Postby cmos » Fri May 20, 2016 5:19 pm

Hi
I am trying to generate the sine wave but I do not seen to have access to the signal generator functions as described in the API documentation. I have a PS5000 5244A and I believe my driver is ps5000A.dll (as described in the PS5000AImports.cs file) in my C# project.
I was broswing the provided code and I can find streaming and blocking functions available but I couldn't find neither of the two functions related to the signal generator:

ps5000aSetSinGenBuiltIn(...)
ps5000aSigGenSoftwareControl()

Do I need another driver or should I load or call another dll library?

Thanks for your assistance,

Cristian
cmos
Newbie
 
Posts: 0
Joined: Thu Apr 28, 2016 6:10 am

Re: Generating Sine using PS5000

Postby Hitesh » Mon May 23, 2016 11:09 am

Hello Cristian,

The function calls will need to be defined in the PS5000aImports.cs file using the definition in the ps5000aApi.h header file which is provided in the inc folder of the SDK installation.

Below is an example for the ps3000a driver for the PicoScope 3000 Series which you can use as a basis for your code:

Code: Select all
[DllImport(_DRIVER_FILENAME, EntryPoint = "ps3000aSetSigGenBuiltInV2")]
        public static extern uint SetSigGenBuiltInV2(
                                                        short handle,
                                                        int offsetVoltage,
                                                        uint pkTopk,
                                                        WaveType waveType,
                                                        double startFrequency,
                                                        double stopFrequency,
                                                        double increment,
                                                        double dwellTime,
                                                        SweepType sweepType,
                                                        ExtraOperations operation,
                                                        uint shots,
                                                        uint sweeps,
                                                        SigGenTrigType triggerType,
                                                        SigGenTrigSource triggerSource,
                                                        short extInThreshold);

The enumerations will need to be defined - below are those defined for the ps3000a driver but you can adapt them for the ps5000a driver by renaming them according to the ps5000aApi.h header file:

Code: Select all
        public enum SweepType : int
        {
            PS3000A_UP,
            PS3000A_DOWN,
            PS3000A_UPDOWN,
            PS3000A_DOWNUP,
            PS3000A_MAX_SWEEP_TYPES
        }

        public enum WaveType : int
        {
            PS3000A_SINE,
            PS3000A_SQUARE,
            PS3000A_TRIANGLE,
            PS3000A_RAMP_UP,
            PS3000A_RAMP_DOWN,
            PS3000A_SINC,
            PS3000A_GAUSSIAN,
            PS3000A_HALF_SINE,
            PS3000A_DC_VOLTAGE,
            PS3000A_MAX_WAVE_TYPES
        }

        public enum ExtraOperations : int
        {
            PS3000A_ES_OFF,
            PS3000A_WHITENOISE,
            PS3000A_PRBS // Pseudo-Random Bit Stream
        }

        public enum SigGenTrigType : int
        {
            PS3000A_SIGGEN_RISING,
            PS3000A_SIGGEN_FALLING,
            PS3000A_SIGGEN_GATE_HIGH,
            PS3000A_SIGGEN_GATE_LOW
        }

        public enum SigGenTrigSource : int
        {
            PS3000A_SIGGEN_NONE,
            PS3000A_SIGGEN_SCOPE_TRIG,
            PS3000A_SIGGEN_AUX_IN,
            PS3000A_SIGGEN_EXT_IN,
            PS3000A_SIGGEN_SOFT_TRIG
        }

        public enum IndexMode : int
        {
            PS3000A_SINGLE,
            PS3000A_DUAL,
            PS3000A_QUAD,
            PS3000A_MAX_INDEX_MODES
        }


Hope this helps.
Hitesh

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

Re: Generating Sine using PS5000

Postby cmos » Mon May 23, 2016 10:21 pm

Hi
I am having a hard time finding the ps5000aApi.h file. Where is it located? I tried using windows find engine and looking in the program files directory but I don't seem to find that specific file. Am I missing something?

Thanks for your help,

Cristian
cmos
Newbie
 
Posts: 0
Joined: Thu Apr 28, 2016 6:10 am

Re: Generating Sine using PS5000

Postby Martyn » Tue May 24, 2016 7:12 am

Depending on which SDK you installed it will be in

C:\Program Files (x86)\Pico Technology\SDK\inc

or

C:\Program Files\Pico Technology\SDK\inc
Martyn
Technical Specialist
Martyn
Site Admin
Site Admin
 
Posts: 2287
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: Generating Sine using PS5000

Postby cmos » Tue May 24, 2016 5:22 pm

Great, thanks. I found the header file. I added the function definitions in my Imports file but I do not seem to be able to generate any signal. I have a PS5244A and I used the following call:
Code: Select all
Imports.SetSigGenBuiltInV2(
_handle,
0,  //offsetVoltage
200, //pktopk
Imports.WaveType.PS5000A_Sine,
390000.0, //start freq
410000.0, //stop freq
1000.0, //increment
5.0, //dwell time
Imports.SweeType.PS500A_UP,
Imports.ExtraOperations.PS500A_ES_OFF,  //Only applies to B modules
0,   //number of shots
10, //number of sweeps
Imports.SigGenTrigType.PS500A_SINGEN_RISING,
Imports.SigGenTrigSource.PS5000A_SINGEN_NONE,
25);   //Theshold


I was expecting a signal to be generated everytime I made this call through my interactive GUI. However nothing happens. I am not sure what I am missing. By the way, I have both channels enable for data collection and they are set to 1V range.

Thank you,

Cristian
cmos
Newbie
 
Posts: 0
Joined: Thu Apr 28, 2016 6:10 am

Re: Generating Sine using PS5000

Postby Hitesh » Wed May 25, 2016 8:35 am

Hi Cristian,

How have you defined the function in your PS5000aImports.cs file?

There is no ps5000aSetSigGenBuiltInV2()* function so you should define the ps5000aSetSigGenBuiltIn() function.

Are you looking to use the external trigger to start the sweep?

Regards,

* Edit: See the post below.
Last edited by Hitesh on Wed May 25, 2016 4:21 pm, edited 1 time in total.
Reason: The ps5000aApi.h header file does contain a ps5000aSetSigGenBuiltInV2() function.
Hitesh

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

Re: Generating Sine using PS5000

Postby cmos » Wed May 25, 2016 2:10 pm

Hi
I did try calling both functions, ps5000aSetSigGenBuiltIn() and ps5000aSetSigGenBuiltInV2() as both signatures are present in my include file. I noticed one uses float definitions for its parameters while the other uses double definitions. They are both present in the ps5000aAPI.h file in my SDK/inc folder.

I can forsee activating this function using the software trigger in either generating single shots or continuosly running it. I might use the sweep option after I gain a bit of experience working with the dwell time.

I defined my functions following your example and looking at previous definitions in my import file. However when I call the function, it generates an error:

"A call to PInvoke function 'PS5000ABlockCapture! PS5000A.Imports::SetSigGenBuiltIn' has unbalalnced the stack. This is likely..."


I am not sure what I am doing wrong. Please notice my changes in the import file are enclosed with tags <CM SigGen> and </CM SigGen>.

I await for your response. Thank you,

Cristian
Attachments
main_code_fragment.cs
(2.46 KiB) Downloaded 18 times
PS5000AImports.cs
Definitions in Import file
(16.38 KiB) Downloaded 18 times
cmos
Newbie
 
Posts: 0
Joined: Thu Apr 28, 2016 6:10 am

Re: Generating Sine using PS5000

Postby Hitesh » Wed May 25, 2016 4:19 pm

Hi Cristian,

Apologies, the Programmer's Guide is missing the function so I have requested our Technical Publications team to update this.

With regards to the error I suspect it is down to defining the ps5000aSetSigGenBuiltIn() function with parameters which are double precision rather that using the float data type.

Please try the following:

Code: Select all
        [DllImport(_DRIVER_FILENAME, EntryPoint = "ps5000aSetSigGenBuiltInV2")]
        public static extern short SetSigGenBuiltInV2( 
                                                        short handle,
                                                        int offsetVoltage,
                                                        uint pkTopk,
                                                        WaveType waveType,
                                                        double startFrequency,
                                                        double stopFrequency,
                                                        double increment,
                                                        double dwellTime,
                                                        SweepType sweepType,
                                                        ExtraOperations operation,
                                                        //short whiteNoise,
                                                        uint shots,
                                                        uint sweeps,
                                                        SigGenTrigType triggerType,
                                                        SigGenTrigSource triggerSource,
                                                        short extInThreshold);

Regards,
Hitesh

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

Re: Generating Sine using PS5000

Postby cmos » Thu May 26, 2016 6:16 am

Hi

I did try both ps5000aSetSigGenBuiltIn and ps5000aSetSigGenBuiltInV2 definitions but it did not work. To avoid the float/double definitions, I input the number directly into the functions as you saw in my attached file in my previous post.

I will try again tomorrow and I let you know if I get any changes on my side. Thanks for your assistance.

Cristian
cmos
Newbie
 
Posts: 0
Joined: Thu Apr 28, 2016 6:10 am

Next

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

Who is online

Users browsing this forum: No registered users and 0 guests