How to sample at 1 KHz rate in VB6?

Legacy support with Phidget21
borisg
Phidgetly
Posts: 38
Joined: Tue Jun 21, 2011 11:25 pm
Location: chaos
Contact:

Re: How to sample at 1 KHz rate in VB6?

Postby borisg » Wed Jul 06, 2011 4:32 pm

Just tried out your code and the counter increments at 125 Hz. It seems the default rate for the 8/8/8 board is 125 Hz. When I set DataRate for a channel to 1 it reads back as 1 but values are returned only every 8 msec. Is it a hardware problem with the 8/8/8 board?

borisg
Phidgetly
Posts: 38
Joined: Tue Jun 21, 2011 11:25 pm
Location: chaos
Contact:

Re: How to sample at 1 KHz rate in VB6?

Postby borisg » Thu Jul 07, 2011 4:02 am

Patrick, I'm assuming that the 8/8/8 board I've been using may be defective. As you've gotten 1 KHz sampling using VB6, I'm also assuming that I should be able to get it with a new 8/8/8 board and have ordered 3 of them hoping that at least one of them should be able to sample at 1 KHz. Hopefully this isn't an expensive mistake but I've only got the weekend to finish up my project.

User avatar
Patrick
Lead Developer
Posts: 3105
Joined: Mon Jun 20, 2005 8:46 am
Location: Canada
Contact:

Re: How to sample at 1 KHz rate in VB6?

Postby Patrick » Thu Jul 07, 2011 9:52 am

It's very unlikely that this could be a firmware/hardware issue. If you would like, you can send me your VB6.0 project and I can confirm whether it is a software issue.

What is the firmware version of your 8/8/8?
Are you running the latest libraries?

-Patrick

dtimer

Re: How to sample at 1 KHz rate in VB6?

Postby dtimer » Fri Jul 08, 2011 9:28 pm

you know, i think i am having a similar problem but in java

my understanding is that after 8ms, the event fires 8 times. with the accelerometer example that i mentioned, the 8 samples are sent as an array in 1 event.

now unlike this guy, I am getting 1000 events per second but sensorvalue and sensorrawvalue respectively output the same values 8 times. Patrick mentioned that sensorrawvalue updates every 8ms - what then is the point in raising the event 8 times if the actual sample is not updated for 8ms? Does this mean that true 1ms sampling is not possible with the interfacekit api? Returning to the original poster's question, how do you access the other 7 1ms samples?

borisg
Phidgetly
Posts: 38
Joined: Tue Jun 21, 2011 11:25 pm
Location: chaos
Contact:

Re: How to sample at 1 KHz rate in VB6?

Postby borisg » Fri Jul 08, 2011 11:44 pm

Success!! :D That's the good news. The bad news is that either I've got 3 very oddball computers or Phidgets21.dll is broken (or the ActiveX version is).

Normally one would assume that if:
PhidgetsIFK.DataRateMax(chan) = 1 then
PhidgetsIFK.DataRate(chan) = 1 should setup 1 KHz sampling.

What I did to finally sort out this problem was to copy Patrick's example exactly into a VB form (except I had to add:
Set PhidgetsIFK = new PhidgetInterfaceKit
before I could open the device. Once I changed the code from:
PhidgetsIFK.DataRate(chan) = 1
to
PhidgetsIFK.DataRate(chan) = PhidgetsIFK.DataRateMax(chan)
I got 1 KHz sampling. It's impossible (at least in the 3 systems that I've tried these programs) to sample at 500 Hz or 250 Hz as this would mean setting DataRate(chan) to either 2 or 4 which doesn't work. For me that isn't a problem as all the applications I have in mind use a 1 KHz data rate.

What I've also noticed is that one often has to add the Phidgets library either as a component or reference it and often the program won't run until I've unchecked component or vice-versa. Let's just say that the problem is one of the most bizarre I've encountered in 20 years that I've been programming in VB.

Unlike dtimer, I'm getting different values for all of the samples when I hit the FSR which I'm using as the input device for my finger tapping quantification program. So my gut feeling to order 3 more of the 8/8/8 modules was correct as I've got some more physiologic sampling projects to use those for. Finally can record EKG data cheaply!

Thanks to everyone who gave advice regarding this problem. I have one suggestion that might make Phidgets modules a bit easier to use and that would be to release the source for Phidget21.dll. My impression of looking at the code license is that it is essentially open source and having a lot more people look at it could probably solve issues like the one I ran into. Sounds like the Java 1 Khz sampling could use a bit of work also.

borisg
Phidgetly
Posts: 38
Joined: Tue Jun 21, 2011 11:25 pm
Location: chaos
Contact:

Re: How to sample at 1 KHz rate in VB6?

Postby borisg » Sat Jul 09, 2011 12:53 am

I forgot to add that I'm using the latest version of Phidgets21.dll on all 3 machines that I've tried. One runs XP, the other two run W7 and one is 32 bit W7 and the other 64 bit W7. On the two W7 machines, Phidgets21.dll was the only version installed but I've still got Phidgets20.dll on my XP laptop which is my primary development environment.

borisg
Phidgetly
Posts: 38
Joined: Tue Jun 21, 2011 11:25 pm
Location: chaos
Contact:

Re: How to sample at 1 KHz rate in VB6?

Postby borisg » Sat Jul 09, 2011 2:06 am

Ignore my previous 2 posts as I didn't explore all of the permutations of what might be wrong and got a little too excited when the 8/8/8 board worked as I'd hoped. :(

Found out the problem is actually that have to change the 8/8/8 board variables in the proper sequence ie:
PhidgetsIFK.SensorChangeTrigger(chan) = 0
PhidgetsIFK.DataRate(chan) = 1

I was calling them in reverse order which results in DataRate being set to 125 Hz. The documentation for the 8/8/8 board doesn't specifically state that one has to set the variables in this order. It does say that the data rate is superseded by SensorChangeTrigger if a constant data rate is required. It doesn't say that changing SensorChangeTrigger after setting DataRate will change DataRate to 125 Hz. So, I guess Phidgets21.dll is OK after all but the documentation for the 8/8/8 board needs to be clarified. Now can set all of the specified data rates.

What would also be nice would be a section where Phidgets users could post their code, especially if there are quirks like this that they've found.

User avatar
Patrick
Lead Developer
Posts: 3105
Joined: Mon Jun 20, 2005 8:46 am
Location: Canada
Contact:

Re: How to sample at 1 KHz rate in VB6?

Postby Patrick » Mon Jul 11, 2011 2:54 pm

Hi,

That behavior is admittedly unexpected. The problem here is that once a sensor change trigger is set, the library goes into 'EVENTMODE_CHANGETRIGGER' - which simply outputs data at the 8ms rate if it's changed from last time - data rate is not used at all. I had forgotten about this behavior to be honest.

I'm going to change the library so that setting a sensor change trigger of 0 will not change the 'event mode' - if data rate was set, it will stay in data rate mode.

I will also update the manuals. Sorry for the confusion!

As for the source code - phidget21.dll source is available via the linux download - the code is common for all OSes that we support. The COM library source isn't available (phidget21COM.dll), but it's just a wrapper around phidget21.dll anyways.

-Patrick

borisg
Phidgetly
Posts: 38
Joined: Tue Jun 21, 2011 11:25 pm
Location: chaos
Contact:

Re: How to sample at 1 KHz rate in VB6?

Postby borisg » Wed Jul 13, 2011 1:41 am

Thanks Patrick, it will help other people although I've got enough commenting in my VB program to make sure I won't forget about it. Interesting how I missed the order of the statements in your test program and the reason probably goes back to my PDP-11 programming days where one always set sample frequency first before enabling A/D sampling.

Now that I've done some low-level poking around looking at Phidgets USB packets I'm curious if there's any reason to transmit just 64 bytes every 8 msec? This seems like a low data rate or is the small packet size a result of the limited RAM in the 8/8/8 CPU? I've got no problems getting the 4 channels at 1 KHz which is what I need, but a friend of mine was asking about doing an application requiring a higher data rate/channel so I was just curious about the possibility of tweaking the 8/8/8 board, or perhaps I should just wait for the next version of the board to come out. I use a sound card for high AC coupled data rates now.

User avatar
Patrick
Lead Developer
Posts: 3105
Joined: Mon Jun 20, 2005 8:46 am
Location: Canada
Contact:

Re: How to sample at 1 KHz rate in VB6?

Postby Patrick » Wed Jul 13, 2011 11:36 am

Interrupt packets on full-speed devices are limited to 64 bytes. We could increase data rate by moving to a high-speed USB processor, or by sending data out more often then 8ms, but 8ms is a good compromise, as faster data rates can tax systems like our embedded SBC especially with multiple Phidgets attached.

-Patrick


Return to “VB 6.0”

Who is online

Users browsing this forum: No registered users and 1 guest