Test and Measurement Forum

VBA/Excel question

Post general discussions on using our drivers to write your own software here

VBA/Excel question

Postby buonviri » Tue Oct 11, 2005 2:49 pm

Any idea what's wrong with my Visual Basic for Applications (Excel) code?

Code: Select all
Sub SignalGeneratorTest()
ps3000_handle = ps3000_open_unit()
Call ps3000_set_trigger(ps3000_handle, 5, 0, 0, 0, 0)
Call ps3000_set_siggen(ps3000_handle, 1, 1000, 1000, 0, 0, 0, 0)
Call ps3000_flash_led(1)
Call ps3000_flash_led(1)
Call ps3000_flash_led(1)
Call ps3000_flash_led(1)
Call ps3000_flash_led(1)
Call ps3000_flash_led(1)
ps3000_stop (ps3000_handle)
End Sub


I put the LED flashes in there to make sure it was actually doing something, and pause while I check the output with another scope. I am trying to disable the trigger in line 3, and enable the generator in line 4, a 1kHz square wave. But nothing happens. If I run the picoscope program and enable the signal generator that way, it works fine, but the code above does not enable the signal generator feature.
buonviri
User
User
 
Posts: 2
Joined: Tue Oct 04, 2005 11:59 pm

Postby Michael » Thu Oct 13, 2005 3:16 pm

Hello,

I have tried your code and found no problem in this standard form.
The Signal generator exists outside the trigger and sampling functions therefore needs to be disabled in the way it is enabled, using ps3000_Stop will not work!

Here is the altered code to show how i did it. We added the OK's to watch the output and pass to an If statement to track any errors.

Sub SignalGeneratorTest()

Dim trigok As Integer
Dim sigok As Integer

ps3000_handle = ps3000_open_unit()
'trigok = ps3000_set_trigger(ps3000_handle, 5, 0, 0, 0, 0)
'Removed trigger as not required for this
sigok = ps3000_set_siggen(ps3000_handle, 2, 1000, 1000, 0, 0, 0, 0)
'sigok should come back with the frequency of 1000
Call ps3000_flash_led(1) 'Flash the light a couple times
Call ps3000_flash_led(1)
Call ps3000_flash_led(1)
Call ps3000_flash_led(1)
Call ps3000_flash_led(1)
'Call ps3000_stop(ps3000_handle) 'doesn't work with siggen
Call ps3000_close_unit(ps3000_handle) 'close unit completely

End Sub


If it still does not work, try downloading the latest drivers from the internet.

Best regards,
Michael - Tech Support
Michael - Tech Support
Pico Technology
Web Support Forum
Michael
Zen Master
Zen Master
 
Posts: 656
Joined: Thu Jul 07, 2005 12:41 pm
Location: St Neots, Cambridgeshire

Works Now

Postby buonviri » Thu Oct 13, 2005 8:36 pm

I'm not sure why it didn't work for me before, but it seems to be working now. Maybe Excel had crashed one too many times yesterday.

Two things I found out: don't add MsgBox status indicators while the scope is open (even if it's idle) because the Picoscope display that freezes Excel won't let you click OK to dismiss the box. And more importantly, for those of us that can't use the defines in the header files, the section of the manual that says "PS3000_SINE (0), PS3000_SQUARE (1) or PS3000_TRIANGLE (2)" is wrong. 0 is square, 1 is triangle, and 2 is sine (at least in VBA it is).
buonviri
User
User
 
Posts: 2
Joined: Tue Oct 04, 2005 11:59 pm


Return to General Software Discussions

Who is online

Users browsing this forum: No registered users and 0 guests