PICOHRDL.dll: Frozen Excel and 100% CPU usage

Post your VB and VBA discussions here
Post Reply
SineOfLight
Newbie
Posts: 0
Joined: Fri Mar 06, 2020 9:17 am

PICOHRDL.dll: Frozen Excel and 100% CPU usage

Post by SineOfLight »

Hi all,

I have an Excel / VBA application that reads data with the help of PicoHRDL.dll.

The problem is that CPU usage is always at 100% once I start the macro, and Excel is barely useable anymore.

Imports look like this (not all are used... this is not my own program)

-------
Declare Function HRDLOpenUnit Lib "c:\Program Files\Pico Technology\Pico Full\PicoHRDL.dll" () As Integer
Declare Function HRDLOpenUnitAsync Lib "c:\Program Files\Pico Technology\Pico Full\PicoHRDL.dll" () As Integer
Declare Function HRDLOpenUnitProgress Lib "c:\Program Files\Pico Technology\Pico Full\PicoHRDL.dll" (ByRef handle As Integer, ByRef progress As Integer) As Integer
Declare Function HRDLGetUnitInfo Lib "c:\Program Files\Pico Technology\Pico Full\PicoHRDL.dll" (ByVal handle As Integer, ByVal str As String, ByVal stringLength As Integer, ByVal info As Integer) As Integer
Declare Function HRDLCloseUnit Lib "c:\Program Files\Pico Technology\Pico Full\PicoHRDL.dll" (ByVal handle As Integer) As Integer
Declare Function HRDLGetMinMaxAdcCounts Lib "c:\Program Files\Pico Technology\Pico Full\PicoHRDL.dll" (ByVal handle As Integer, ByRef minAdc As Integer, ByRef maxAdc As Integer, ByVal channel As Integer) As Integer
Declare Function HRDLSetAnalogInChannel Lib "c:\Program Files\Pico Technology\Pico Full\PicoHRDL.dll" (ByVal handle As Integer, ByVal channel As Integer, ByVal enabled As Integer, ByVal range As Integer, ByVal singleEnded As Integer) As Integer
Declare Function HRDLSetDigitalIOChannel Lib "c:\Program Files\Pico Technology\Pico Full\PicoHRDL.dll" (ByVal handle As Integer, ByVal directionOut As Integer, ByVal digitalOutPinState As Integer, ByVal enabledDigitalIn As Integer) As Integer
Declare Function HRDLSetInterval Lib "c:\Program Files\Pico Technology\Pico Full\PicoHRDL.dll" (ByVal handle As Integer, ByVal sampleInterval_ms As Long, ByVal conversionTime As Integer) As Integer
Declare Function HRDLRun Lib "c:\Program Files\Pico Technology\Pico Full\PicoHRDL.dll" (ByVal handle As Integer, ByVal nValues As Long, ByVal method As Integer) As Integer
Declare Function HRDLReady Lib "c:\Program Files\Pico Technology\Pico Full\PicoHRDL.dll" (ByVal handle As Integer) As Integer
Declare Function HRDLGetValues Lib "c:\Program Files\Pico Technology\Pico Full\PicoHRDL.dll" (ByVal handle As Integer, ByRef values As Long, ByRef overflow As Integer, ByVal no_of_values As Long) As Long
Declare Function HRDLGetTimesAndValues Lib "c:\Program Files\Pico Technology\Pico Full\PicoHRDL.dll" (ByVal handle As Integer, times As Long, values As Long, ByRef overflow As Integer, ByVal noOfValues As Long) As Long
Declare Function HRDLGetSingleValue Lib "c:\Program Files\Pico Technology\Pico Full\PicoHRDL.dll" (ByVal handle As Integer, ByVal channel As Integer, ByVal range As Integer, ByVal conversionTime As Integer, ByVal singleEnded As Integer, ByRef overflow As Integer, value As Long) As Integer
Declare Function HRDLCollectSingleValueAsync Lib "c:\Program Files\Pico Technology\Pico Full\PicoHRDL.dll" (ByVal handle As Integer, ByVal channel As Integer, ByVal range As Integer, ByVal conversionTime As Integer, ByVal singleEnded As Integer) As Integer
Declare Function HRDLGetSingleValueAsync Lib "c:\Program Files\Pico Technology\Pico Full\PicoHRDL.dll" (ByVal handle As Integer, ByRef value As Long, ByRef overflow As Integer) As Integer
Declare Function HRDLSetMains Lib "c:\Program Files\Pico Technology\Pico Full\PicoHRDL.dll" (ByVal handle As Integer, ByVal sixtyHertz As Integer) As Integer
Declare Function HRDLGetNumberOfEnabledChannels Lib "c:\Program Files\Pico Technology\Pico Full\PicoHRDL.dll" (ByVal handle As Integer, ByRef nEnabledChannels As Integer) As Integer
Declare Sub HRDLStop Lib "c:\Program Files\Pico Technology\Pico Full\PicoHRDL.dll" (ByVal handle As Integer)
-------

The basics of the code itself are:

-------
handle = HRDLOpenUnit()
' disable all channels
For i = 0 To 16
Call HRDLSetAnalogInChannel(handle, i, 0, 0, 0)
Next i
Call HRDLSetAnalogInChannel(handle, 3, 1, 0, 0) `etc, open 4 more channels
' set interval between conversion starts to 1000 ms
Call HRDLSetInterval(handle, 1000, 2)
Do
Call HRDLRun(handle, 5, 0)

Do While (HRDLReady(handle) = 0)
Application.Wait(now + TimeValue("00:00:01"))
Loop

Call HRDLGetTimesAndValues(handle, times(0), values(0), 0, 10)

' Copy the data into the spreadsheet
For i = 0 To 4
Cells(i + 40, "A").value = times(i)
Cells(i + 40, "B").value = adc2mV(values(4 * i))
Cells(i + 40, "C").value = adc2mV(values(4 * i + 1))
Cells(i + 40, "D").value = adc2mV(values(4 * i + 2))
Cells(i + 40, "E").value = adc2mV(values(4 * i + 3))
Next i
q = q + 1
Cells(60 + q, "A").value = Date
Cells(60 + q, "B").value = Time
Cells(60 + q, "C").value = Cells(16, "C")
Cells(60 + q, "D").value = Cells(17, "C")
Cells(60 + q, "E").value = Cells(18, "C")
Cells(60 + q, "F").value = Cells(10, "C")
Cells(60 + q, "G").value = Cells(11, "C")
Cells(60 + q, "H").value = Cells(16, "E")
Cells(60 + q, "I").value = Cells(17, "E")
Cells(60 + q, "J").value = Cells(18, "E")
Cells(60 + q, "K").value = Cells(10, "E")
Cells(60 + q, "L").value = Cells(11, "E")
DoE = DoEvents
Loop
-------

The computer is a Core 2 Duo E8400 cpu.

Does anyone know how to improve the performance? Any help is really appreciated. Is this a known issue, or?

It's not my own code that is causing the CPU usage, I have put a breakpoint and stuff and then still it's at 50% (something in the DLL?)

Post Reply