VB arbitrary waveform signal generation problom

Post your .Net discussions here
yangzhaoshu
Newbie
Posts: 0
Joined: Sat Jan 05, 2013 12:46 pm

VB arbitrary waveform signal generation problom

Post by yangzhaoshu »

Hi
I have recently acquired a PicoScope 2203 Oscilloscope for the purpose of using the AWG to output a waveform signal in arbitrary form in VB.
According to the Programmer’s Guide, I call the function of ‘ps2000_set_sig_gen_arbitrary’, and a window pop up writing ‘error49, DLL Calling convention error’ I guess the error may be accrued in the parameter of ‘arbitrarywaveform’, but I fail to figure it out.
I am posting the code I am using at the moment to turn on the generator. Can someone shine his or her light onproblems, please?
The calling code in main program

Code: Select all

Private Sub arbgen()
Dim ok As Integer
ok = 1
offsetvoltage = Int(Val(Text2(0).Text) * 1000)
pktopk = Int(Val(Text2(1).Text) * 1000)
startdeltaphase = Int(Val(Text2(2).Text))
stopdeltaphase = Int(Val(Text2(3).Text))
deltaphaseincrement = Int(Val(Text2(4).Text))
dwellcount = Val((Text2(5).Text))
Open "D:\Documents\Waveforms\y11.csv" For Input As #2
Do While Not EOF(2)
Line Input #2, S
Loop
arbitrarywaveform = S
arbitrarywavesize = 501
Select Case arbstype.Text
   Case "Up": sweeptype = 0
   Case "Down": sweeptype = 1
   Case "UpDown": sweeptype = 2
   Case "Downup": sweeptype = 3
End Select
sweeps = Int(Val(Text2(6).Text))
If ps2000_handle Then
  ok = ps2000_set_sig_gen_arbitrary(ps2000_handle, offsetvoltage, pktopk, startdeltaphase, stopdeltaphase, _
  deltaphaseincrement, dwellcount, arbitrarywaveform, arbitrarywavesize, sweeptype, sweeps)
End If
End Sub
The declaration code in module

Code: Select all

Declare Function ps2000_set_sig_gen_arbitrary Lib "ps2000.dll" _
(ByVal handle As Integer, _
ByVal offsetvoltage As Long, _
ByVal pktopk As Long, _
ByVal startdeltaphase As Long, _
ByVal stopdeltaphase As Long, _
ByVal deltaphaseincrement As Long, _
ByVal dwellcount As Long, _
ByVal arbitrarywaveform As Variant, _
ByVal arbitrarywavesize As Long, _
ByVal sweeptype As Integer, _
ByVal sweeps As Long) As Integer

Hitesh

Re: VB arbitrary waveform signal generation problom

Post by Hitesh »

Hi,

What version of VB are you using?

I notice that you have the following in the declaration:

Code: Select all

ByVal arbitrarywaveform As Variant, _
Are you able to define this as a a String? Are your data values for the generator in the range 0 - 255?

Regards,

yangzhaoshu
Newbie
Posts: 0
Joined: Sat Jan 05, 2013 12:46 pm

Re: VB arbitrary waveform signal generation problom

Post by yangzhaoshu »

Hi
thank you for your help, I've refined my program acording to your suggestion, and the problem was finally worked out. now I have sth new to ask, that is: is there a lower limit of pktopk voltage in the function of ps2000SetSigGenBuiltIn, because once I set my pktopk voltage below 500mV (more or less), and connected the Ports of SIGNALOUT and CHA, I can get nothing but noise, when I set the pktopk voltage above 800mV, the output in channal A matched the output signal very well.
大恩未敢言谢
(which means: your help is too precious for me to say thank you!)

Hitesh

Re: VB arbitrary waveform signal generation problom

Post by Hitesh »

Hi yangzhaoshu,

The specification for the PicoScope 2203 AWG is:
Output range ±250 mV to ±2 V pk–pk with ±1 V offset
The minimum value for pkToPk would be 500.

I hope this helps.

yangzhaoshu
Newbie
Posts: 0
Joined: Sat Jan 05, 2013 12:46 pm

Re: VB arbitrary waveform signal generation problom

Post by yangzhaoshu »

thank you for your help but as I referred to my manual, I cannot find the details of the signal generator as your quote, coud you do me a favor to tell me where to get a more detailed one
thank you for helping me

yangzhaoshu
Newbie
Posts: 0
Joined: Sat Jan 05, 2013 12:46 pm

Re: VB arbitrary waveform signal generation problom

Post by yangzhaoshu »

ysquare.csv
the sequense to generate a waveform
(770 Bytes) Downloaded 8357 times
Hi Hitesh
I have encountered another problem when I use ps2203 to generate a arbitrary signal, the waveform of the signal is successfully generated by the sequence stored in buffer, but the pktopk voltage generated by AWG cannot meet the set pktopk value in AWG function parameter, as I set the pktopk voltage as 800mV, while the output pktopk voltage is just 40mv measured by the Voltmeter, the code is shown as below, please do me a faver to solve the problem.

Code: Select all

Private Sub arbgen()
Dim ok As Integer
ok = 1
offsetvoltage = Int(Val(Text2(0).Text) * 1000)
pktopk = Int(Val(Text2(1).Text) * 1000)
startdeltaphase = Val(Text2(2).Text)
stopdeltaphase = Val(Text2(3).Text)
deltaphaseincrement = Val(Text2(4).Text)
dwellcount = Val((Text2(5).Text))
Open "D:\Documents\Waveforms\ysquare.csv" For Input As #2
Do While Not EOF(2)
Line Input #2, S
Loop
arbitrarywaveform = S
arbitrarywavesize = 256
Select Case arbstype.Text
   Case "Up": sweeptype = 0
   Case "Down": sweeptype = 1
   Case "UpDown": sweeptype = 2
   Case "Downup": sweeptype = 3
End Select
sweeps = Int(Val(Text2(6).Text))
If ps2000_handle Then
  ok = ps2000_set_sig_gen_arbitrary(ps2000_handle, offsetvoltage, pktopk, startdeltaphase, stopdeltaphase, _
  deltaphaseincrement, dwellcount, arbitrarywaveform, arbitrarywavesize, sweeptype, sweeps)
  Close #2
End If
End Sub
and the sequence is attached with this email
我对你的敬佩犹如滔滔江水延绵不绝
(which means: My admiration for you is like a surging river stretches without a break)
yangzhaoshu

Hitesh

Re: VB arbitrary waveform signal generation problom

Post by Hitesh »

Hi yangzhaoshu,

The specification can be found here:

http://www.picotech.com/discontinued/PicoScope2203.html

You need to make sure that your values for the AWG are integers in the range 0 -> 255 where

0 corresponds to -1
127 should correspond to 0
255 corresponds to +1

When you then set pkToPk to 800mV - you should find you get a waveform in the range +/- 400mV

I hope this helps.

Ps. Here's some quotes for you - I hope you like them :)

帮助曾经伤害过不要 - Help Ever, Hurt Never
这条河的努力,渴望和斗争合并的海从它的 - The river strives, yearns and struggles to merge with the sea from which it originates.

yangzhaoshu
Newbie
Posts: 0
Joined: Sat Jan 05, 2013 12:46 pm

Re: VB arbitrary waveform signal generation problom

Post by yangzhaoshu »

Hi Hitesh
thanks for your help and your quotes, as it was said 'help ever, hurts never', helpful as you are, I guess, will never be hurted.
yangzhaoshu

yangzhaoshu
Newbie
Posts: 0
Joined: Sat Jan 05, 2013 12:46 pm

Re: VB arbitrary waveform signal generation problom

Post by yangzhaoshu »

Hi Hitesh
I have tried to refine my programs by the solution you told, setting all the values in waveform buffer as integers between 0 and 255, unfortunately, the output signal still fail to meet the pktopk voltage set in the AWG function, there may be sth wrong in other parameters in the function, which are listed as follow
offset voltage(mv) 0
pktopk voltage(mv) 800
start delta phase 0
stop delta phase 60
delta incremet 1
dwellcount 1
arbitrarywaveformsize 256
And the refined waveform sequence is attached with this email.
Could you please do me a faver to chack the parameters and programs again, because an effctive arbitrary signal output is crucial to my subject, and that's why I trust Pico Technoledgy.
yangzhaoshu

yangzhaoshu
Newbie
Posts: 0
Joined: Sat Jan 05, 2013 12:46 pm

Re: VB arbitrary waveform signal generation problom

Post by yangzhaoshu »

the refined waveform sequence attachment
Attachments
ysquare1.csv
refined sequence
(852 Bytes) Downloaded 8399 times

Hitesh

Re: VB arbitrary waveform signal generation problom

Post by Hitesh »

Hi yangzhaoshu,

Looking at your parameters, I can see the following:

offset voltage(mv) 0 - This is in microvolts
pktopk voltage(mv) 800 - This is in microvolts and so should be 800000

When you read the values into 'arbitrarywaveform', what values appear in the array? Are you able to put a breakpoint and then verify the data values are as expected?

Regards,

Hitesh

Re: VB arbitrary waveform signal generation problom

Post by Hitesh »

One further tip suggested by a colleague - try using

Code: Select all

Val(Convert.ToByte(string))
to ensure the values read in are correct.

It's probably better to have your values in a column and read them in line by line.

yangzhaoshu
Newbie
Posts: 0
Joined: Sat Jan 05, 2013 12:46 pm

Re: VB arbitrary waveform signal generation problom

Post by yangzhaoshu »

Hi Hitesh
the offset voltage and the pktopkvoltage set are right because in my code the both parameters are multiplied by 1000 shown as below

Code: Select all

offsetvoltage = Int(Val(Text2(0).Text) * 1000)
pktopk = Int(Val(Text2(1).Text) * 1000)
As a breakpoit was put in the programs, I found the values in the buffer had succesfully flown in to the parameter of waveform
I have capture the screenshots about the problem in the attachment, and the signal reception parts of the program is detected by the build in signal output, proving its well-functioning, which means the problem should happen in the part of signal generating. could you please help me to solve the problem, Almighty Hitesh.
many thanks
yangzhaoshu
Attachments
screenshot.rar
the screenshot about the function problem
(59.66 KiB) Downloaded 9054 times

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

Re: VB arbitrary waveform signal generation problom

Post by Martyn »

Can you try with the attached modification of your file
Attachments
ysquare1.txt
Changed to text
(852 Bytes) Downloaded 8697 times
Martyn
Technical Support Manager

yangzhaoshu
Newbie
Posts: 0
Joined: Sat Jan 05, 2013 12:46 pm

Re: VB arbitrary waveform signal generation problom

Post by yangzhaoshu »

I tried and the pktopk reach to 147mv with a 800mv pktopk set, so it still cannot reach my expection

Post Reply