Hallo
ich benutze das RN-Controll 1.4 mit dem ATMEGA32 wenn ich nun von allen Ports die Spannung einlese dann schwankt mein Ergebniss ab und zu so stark das es den Meßwert verunstalltet hier ein Beispiel :
Von der RS232 Ausgabe :
;0.93;0.93;0.00;0.93;5.00;5.00;5.00;5.00;0.00;
;0.94;0.93;0.00;0.93;5.00;5.00;5.00;5.00;0.00;
;0.94;0.94;0.00;0.94;5.00;5.00;5.00;5.00;0.00;
;0.94;0.94;0.00;0.94;5.00;5.00;5.00;5.00;0.00;
;0.97;0.97;0.00;151.35.00;5.00;5.00;5.00;5.00;0.00 ; ---> Problem String ist zulang
;1.06;1.06;0.00;1.06;5.00;5.00;5.00;5.00;0.00;
;1.18;1.18;0.00;1.18;5.00;5.00;5.00;5.00;0.00;
;1.18;1.18;0.00;1.18;5.00;5.00;5.00;5.00;0.00;
;1.18;1.18;0.00;1.18;5.00;5.00;5.00;5.00;0.00;
ich weis nicht wie "151.35.00" zustande kommt dieser Meßwert sollte niemals größer werden als wie 4 Zeichen wie im String definiert.
Hier ist der Source Code dazu :
Code:Declare Sub Showporta() Declare Sub Rnlcd_cursor(byval Spalte As Byte , Byval Zeile As Byte) Declare Sub Rnlcd_clr() Declare Sub Rnlcd(byval Text As String) ' ------------- Hier die üblichen RN-Control Anweisungen -------------- $regfile = "m32def.dat" $crystal = 16000000 'Quarzfrequenz $baud = 38400 Config Scl = Portc.0 'Ports fuer IIC-Bus Config Sda = Portc.1 ' ------------- Ende der üblichen RN-Control Anweisungen -------------- Const Rnkeylcd_slaveid_write = &H40 'I2C SlaveAdresse Const Rnkeylcd_slaveid_read = &H41 'Config Adc = Single , Prescaler = Auto 'Für Tastenabfrage und Spannungsmessung Config Adc = Single , Prescaler = Auto , Reference = Avcc Dim I As Byte Do 'Hauptprogramm Dim Stemp As String * 100 Call Showporta ' Zeichen Empfangen und Bestätigung per Beep If Usr.rxc = 1 Then 'Wenn Byte empfangen... I = Udr 'Byte aus UART auslesen Select Case I Case "Befehl1" Sound Portd.7 , 400 , 350 Case "stop_adc" Stop Adc Sound Portd.7 , 400 , 350 Case Else End Select End If 'ende der Schleife Loop Dim Volt_a As Single Dim Volt_b As Single Dim Volt_c As Single Dim Volt_d As Single Dim Volt_e As Single Dim Volt_f As Single Dim Volt_g As Single Dim Volt_h As Single Const Ref = 5 / 1023 'Für Berechnung Sub Showporta() Local A As Word Local B As Word Local C As Word Local D As Word Local E As Word Local F As Word Local G As Word Local H As Word Config Porta = Input ' Port A als Anlogeingang konfigurieren 'Porta.0 = 1 'Interne Pullup Widerstande ein 'Porta.1 = 1 'Porta.2 = 1 'Porta.3 = 1 'Porta.4 = 1 'Porta.5 = 1 'Porta.6 = 1 'Porta.7 = 1 ' Analogport abfragen Start Adc ' A = Getadc(0) B = Getadc(1) C = Getadc(2) D = Getadc(3) E = Getadc(4) F = Getadc(5) G = Getadc(6) H = Getadc(7) 'Bit Auflösung in Volt umrechnen Volt_a = A * Ref Volt_b = B * Ref Volt_c = C * Ref Volt_d = D * Ref Volt_e = E * Ref Volt_f = F * Ref Volt_g = G * Ref Volt_h = H * Ref ' Varible als String mit 6 Zeichen definieren Dim Volt_a_2kommastellen As String * 4 Dim Volt_b_2kommastellen As String * 4 Dim Volt_c_2kommastellen As String * 4 Dim Volt_d_2kommastellen As String * 4 Dim Volt_e_2kommastellen As String * 4 Dim Volt_f_2kommastellen As String * 4 Dim Volt_g_2kommastellen As String * 4 Dim Volt_h_2kommastellen As String * 4 'STR() convert a numeric value into a string Volt_a_2kommastellen = Str(volt_a) Volt_b_2kommastellen = Str(volt_b) Volt_c_2kommastellen = Str(volt_c) Volt_d_2kommastellen = Str(volt_d) Volt_e_2kommastellen = Str(volt_e) Volt_f_2kommastellen = Str(volt_f) Volt_g_2kommastellen = Str(volt_g) Volt_h_2kommastellen = Str(volt_h) ' Fusing minmize to 2 decimal places Volt_a_2kommastellen = Fusing(volt_a , "#.##") Volt_b_2kommastellen = Fusing(volt_b , "#.##") Volt_c_2kommastellen = Fusing(volt_c , "#.##") Volt_d_2kommastellen = Fusing(volt_d , "#.##") Volt_e_2kommastellen = Fusing(volt_e , "#.##") Volt_f_2kommastellen = Fusing(volt_f , "#.##") Volt_g_2kommastellen = Fusing(volt_g , "#.##") Volt_h_2kommastellen = Fusing(volt_h , "#.##") Print ";" ; Volt_a_2kommastellen ; ";" ; Volt_b_2kommastellen ; ";" ; Volt_c_2kommastellen ; ";" ; Volt_d_2kommastellen ; ";" ; Volt_e_2kommastellen ; ";" ; Volt_f_2kommastellen ; ";" ; Volt_g_2kommastellen ; ";" ; Volt_h_2kommastellen ; ";" ; "0.00" ; ";" 'Ausgabe aller 8 Analogausgänge + 1x Dummy da der letzte Wert im Excel durch den Zeilenumbruch nicht bearbeitet wird End Sub
Der Code erlaubt es alle Analogports auszulesen und diese über die Serielle Schnittstelle wieder auszugeben.
Das ganze funktioniert auch ganz gut nur dann kommt das Problem das mit einem Schlag das Meßergebniss durch irgendeine komische Zahl ersetzt die länger als 4 Stellen ist und das obwohl ich extra String * 4 definiert habe.
Versteht ihr das ?
Gruß
Steffen







Zitieren

Lesezeichen