First please download and extract the “K8055N software pack” from:
velleman.eu/support/download … 055n&type=
There in the folder \Examples\K8055NDemoExcel open the K8055DemoExcel.xls in Excel.
Press Alt + F11 and then add the following lines to the timer procedure “Sub TimerProc …”: OutputAnalogChannel 1, ActiveSheet.Cells(9, 2)
OutputAnalogChannel 2, ActiveSheet.Cells(10, 2)
Now you can output from DAC1/PWM1 and DAC2/PWM2 the values written to cells B9 and B10.
Here’s the complete modified Excel macro[size=85]:[code]Option Explicit
Private Declare Function Version Lib “k8055d.dll” () As Long
Private Declare Function SearchDevices Lib “k8055d.dll” () As Long
Private Declare Function SetCurrentDevice Lib “k8055d.dll” (ByVal CardAddress As Long) As Long
Private Declare Function OpenDevice Lib “k8055d.dll” (ByVal CardAddress As Long) As Long
Private Declare Sub CloseDevice Lib “k8055d.dll” ()
Private Declare Function ReadAnalogChannel Lib “k8055d.dll” (ByVal Channel As Long) As Long
Private Declare Sub ReadAllAnalog Lib “k8055d.dll” (Data1 As Long, Data2 As Long)
Private Declare Sub OutputAnalogChannel Lib “k8055d.dll” (ByVal Channel As Long, ByVal Data As Long)
Private Declare Sub OutputAllAnalog Lib “k8055d.dll” (ByVal Data1 As Long, ByVal Data2 As Long)
Private Declare Sub ClearAnalogChannel Lib “k8055d.dll” (ByVal Channel As Long)
Private Declare Sub SetAllAnalog Lib “k8055d.dll” ()
Private Declare Sub ClearAllAnalog Lib “k8055d.dll” ()
Private Declare Sub SetAnalogChannel Lib “k8055d.dll” (ByVal Channel As Long)
Private Declare Sub WriteAllDigital Lib “k8055d.dll” (ByVal Data As Long)
Private Declare Sub ClearDigitalChannel Lib “k8055d.dll” (ByVal Channel As Long)
Private Declare Sub ClearAllDigital Lib “k8055d.dll” ()
Private Declare Sub SetDigitalChannel Lib “k8055d.dll” (ByVal Channel As Long)
Private Declare Sub SetAllDigital Lib “k8055d.dll” ()
Private Declare Function ReadDigitalChannel Lib “k8055d.dll” (ByVal Channel As Long) As Boolean
Private Declare Function ReadAllDigital Lib “k8055d.dll” () As Long
Private Declare Function ReadCounter Lib “k8055d.dll” (ByVal CounterNr As Long) As Long
Private Declare Sub ResetCounter Lib “k8055d.dll” (ByVal CounterNr As Long)
Private Declare Sub SetCounterDebounceTime Lib “k8055d.dll” (ByVal CounterNr As Long, ByVal DebounceTime As Long)
Private Declare Function SetTimer Lib “user32” ( _
ByVal HWnd As Long, ByVal nIDEvent As Long, _
ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Private Declare Function KillTimer Lib “user32” ( _
ByVal HWnd As Long, ByVal nIDEvent As Long) As Long
Dim TimerID As Long
Dim TimerSeconds As Single
Dim CardAddress As Long
Dim n As Long
Sub Button1_Click()
Dim h As Long
n = 0
h = OpenDevice(0)
If h = 0 Then
ActiveSheet.Cells(1, 4) = “Card 0 Connected”
TimerSeconds = 1 ’ the timer interval is now 1 sec.
TimerID = SetTimer(0&, 0&, TimerSeconds * 1000&, AddressOf TimerProc)
Else
ActiveSheet.Cells(1, 4) = “Card 0 Not Found”
End If
End Sub
Sub TimerProc(ByVal HWnd As Long, ByVal uMsg As Long, ByVal nIDEvent As Long, ByVal dwTimer As Long)
On Error Resume Next
Dim Data1 As Long
Dim Data2 As Long
Dim i As Long
ReadAllAnalog Data1, Data2
ActiveSheet.Cells(2, 2) = Data1
ActiveSheet.Cells(3, 2) = Data2
WriteAllDigital n
ActiveSheet.Cells(5, 2) = n
n = n + 1
If n = 32 Then n = 0
i = ReadAllDigital
ActiveSheet.Cells(7, 2) = i
OutputAnalogChannel 1, ActiveSheet.Cells(9, 2)
OutputAnalogChannel 2, ActiveSheet.Cells(10, 2)
End Sub
Sub Button3_Click()
KillTimer 0&, TimerID
CloseDevice
ActiveSheet.Cells(1, 4) = “Card 0 Closed”
End Sub [/code][/size]