Greetings Gurus! I envisage an application (VB6, or VBA macro in Excel; VBA in Excel 2000 also seems to be VB6) using one USBADC11/10 converter. Readings will be collected, but also control output implemented in the form of changes in settings (on or off) of the two Digital Outputs, DO1 and DO2. I want to effect on either DO a sequence from on to off then off to on, or vice versa, with a short interval of a few ms between. Alternatively, a sequence DO1 on or off, then DO2 on or off, with similar interval between. I have not succeeded in finding a timing mechanism for such short interval in the VBA.
But the USBADC11 convertor itself requires time to operate. To utilise this, I tried following code:
handle = UsbAdc11OpenUnit()
opened = handle <> 0
If opened Then ' Prepare for Run: take readings from channel 1 to 11 incl
...
sampleInterval = UsbAdc11SetInterval(handle, 500, 1, channels(0), 11)
' gives sampleInterval of about 550us. Hence:
Debug.Print Timer ' and for delay:
For j = 0 To 999
ok = UsbAdc11Run(handle, 1, 0)
Do While Ready = 0
Ready = UsbAdc11Ready(handle)
Loop
Next j
newTime = Timer
Debug.Print newTime; j
Call UsbAdc11CloseUnit(handle) ' Close the unit when finished to drop the driver
End If
Output in the immediate window was:
39002.48
39006.54 1000
ie 4.06s with 1000 loops.
And with j=99, output was:
39629.51
39629.95 100
ie 0.44s with 100 loops.
So it seems that a single sequence:
ok = UsbAdc11Run(handle, 1, 0)
....
Loop
is taking around 4ms, even tho sampleInterval is only 550us. Am I right in thinking that the apparent increase as j (the number of loops) diminishes has to do with the mediocre resolution of the VBA function Timer? Which is about 55ms, I understand, therefore I haven't tried directly to measure the duration of a single loop.
Results were similar when the number of samples was 3 instead of 1; that didn't seem significantly to increase the time with j=999, or 99.
So, can I run that sequence just once for a serviceable means of effecting a delay of about 4ms?
Is there any risk in this of damaging the USBADC11 converter, notably if done 10 or 15 times in quick succession?
Thanks in anticipation for valued responses.
Cart


