Der ATtiny13 bietet sich als universelles Messgerät an, wobei die Auflösung von 10 Bit den Spannungsbereich zwischen 0 V und 5 V in 1023 Stufen teilt. Das hier vorgestellte Anwenderprogramm ermöglicht zugleich die Ausgabe eines PWM-Signals, das in 255 Stufen aufgelöst ist.
Private Sub Command1_Click()
OpenString = "COM" + Text1.Text + ":9600,N,8,1"
i = OPENCOM(OpenString)
If i = 0 Then MsgBox ("Schnittstelle nicht verfügbar")
TIMEOUTS 300
TIMEINIT
RTS 0
DELAY 100
RTS 1
DELAY 100
SENDBYTE 17
SENDBYTE 1
DELAY 2
SENDBYTE 18
End Sub
Function ADC2()
SENDBYTE 56
hi = READBYTE
lo = READBYTE
ADC2 = 256 * hi + lo
End Function
Function ADC3()
SENDBYTE 57
hi = READBYTE
lo = READBYTE
ADC3 = 256 * hi + lo
End Function
Sub PWM(D)
SENDBYTE 64
SENDBYTE D
End Sub
Private Sub HScroll1_Change()
D = HScroll1.Value
PWM D
End Sub
Private Sub Timer1_Timer()
CLEARBUFFER
Uref = Val(Text4.Text)
U = ADC2() / 1023 * Uref
Text2.Text = " " + Format(U, "0.00") + " V "
U = ADC3() / 1023 * Uref
Text3.Text = " " + Format(U, "0.00") + " V "
End Sub
Private Sub HScroll1_Change()
Label1.Caption = Str$(Int(HScroll1.Value * 100 / 255)) + "%"
Dat = HScroll1.Value
SENDBYTE 64
SENDBYTE Dat
End Sub
Private Sub Timer1_Timer()
t = t + 1
HScroll1.Value = 128 + Int(127 * (Sin(t / 50)))
End Sub
Private Sub VScroll1_Change()
SENDBYTE 64
D = VScroll1.Value
SENDBYTE D
U1 = 5 / 255 * D 'U1 Eingangsspannung
Text2.Text = "U1 = " + Str(Int(U1 * 100) / 100) + " V"
End Sub
Private Sub Timer1_Timer()
U2 = 0 'U2 = Ube
For n = 1 To 10
SENDBYTE 56
DELAY 10
D = 256 * READBYTE
D = D + READBYTE
U2 = U2 + D
DELAY 5
Next n
U2 = U2 / 10230 * 5
Text3.Text = "Ube = " + Str(Int(U2 * 100) / 100)
+ " V"
U3 = 0 'U3 = Uce
For n = 1 To 10
SENDBYTE 57
DELAY 10
D = 256 * READBYTE
D = D + READBYTE
U3 = U3 + D
DELAY 5
Next n
U3 = U3 / 10230 * 5
Text4.Text = "Uce = " + Str(Int(U3 * 100) / 100)
+ " V"
I1 = (U1 - U2) / 0.11 'I1 = Ib
If I1 < 0 Then I1 = 0
Text5.Text = "Ib = " + Str(Int(I1 * 100) / 100)
+ " µA"
I2 = 5 - U3 'I2 = Ic
If I2 < 0 Then I2 = 0
Text6.Text = "Ic = " + Str(Int(I2 * 100) / 100)
+ " mA"
If I1 > 0 Then
V = 1000 * I2 / I1 'V = Ice / Ib
Else
V = 0
End If
Text7.Text = "Ic/Ib = " + Str(Int(V))
End Sub
Private Sub Timer1_Timer()
n = n + 1
If n = 500 Then Timer1.Enabled = False
x = n + 24
SENDBYTE 48
d = READBYTE
Plotneu = 275 - d
If n > 1 Then Picture1.Line (x, Plotalt)-(x + 1, Plotneu)
Plotalt = Plotneu
End Sub