zon
Electrical
- Mar 14, 2006
- 2
we have a AD-converter (type tlc549cp) .
the code for reading this ADC in Visual Basic.Net is:
private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim i As Integer
i = OPENCOM("COM1,1200,N,8,1")
If i = 0 Then MsgBox("COM1 niet beschikbaar")
Timer1.Interval = 1000
End Sub
Public Function AD()
Dim i, bitwaarde, bitpositie, meting As Integer
RTS(1)
DELAYUS(10)
RTS(0)
DELAYUS(50)
meting = 0
bitwaarde = 128
For bitpositie = 1 To 8
If DSR = 1 Then meting = meting + bitwaarde
DTR(1)
DELAYUS(10)
DTR(0)
DELAYUS(10)
bitwaarde = bitwaarde / 2
Next bitpositie
AD = meting
End Function
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim spanning As Double
spanning = AD() / 255 * 5
'spanning word in textvak gezet
Text1.Text = CStr(spanning & " V ")
end sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Timer1.Enabled = True
End Sub
i have created a program in LabVIEW, it looks exactly the same, but it doesn't works, it gives constantly the same voltage.
the code for reading this ADC in Visual Basic.Net is:
private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim i As Integer
i = OPENCOM("COM1,1200,N,8,1")
If i = 0 Then MsgBox("COM1 niet beschikbaar")
Timer1.Interval = 1000
End Sub
Public Function AD()
Dim i, bitwaarde, bitpositie, meting As Integer
RTS(1)
DELAYUS(10)
RTS(0)
DELAYUS(50)
meting = 0
bitwaarde = 128
For bitpositie = 1 To 8
If DSR = 1 Then meting = meting + bitwaarde
DTR(1)
DELAYUS(10)
DTR(0)
DELAYUS(10)
bitwaarde = bitwaarde / 2
Next bitpositie
AD = meting
End Function
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim spanning As Double
spanning = AD() / 255 * 5
'spanning word in textvak gezet
Text1.Text = CStr(spanning & " V ")
end sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Timer1.Enabled = True
End Sub
i have created a program in LabVIEW, it looks exactly the same, but it doesn't works, it gives constantly the same voltage.