Hallo,
also ich bin mit meinem Latein am Ende. Das Board sollte eigentlich genug Saft bekommen. Mittlerweile kann ich sagen, das es sich bei dem Phänomen tatsächlich um ein Reset handelt.
Vielleicht fällt ja jemand was an dem Code auf :
Für jeden Hinweis dankbar,Code:Declare Sub Batteriespannung() Declare Sub Fahrprogramm() Declare Sub Kopfausrichtung(grad As Integer) Declare Function Scanneumgebung() As Integer $regfile = "m32def.dat" $framesize = 32 $swstack = 32 $hwstack = 32 Dim I As Integer Dim N As Integer Dim Ton As Integer Dim Neuergrad As Integer Dim Volt As Single Dim Taste As Byte Dim S20_adress As Integer Dim Aktakt As Integer $crystal = 16000000 'Quarzfrequenz $baud = 9600 Config Adc = Single , Prescaler = Auto 'Für Tastenabfrage und Spannungsmessung Sound Portd.7 , 400 , 450 'BEEP Sound Portd.7 , 400 , 250 'BEEP Sound Portd.7 , 400 , 450 'BEEP Sound Portd.7 , 400 , 450 'BEEP Sound Portd.7 , 400 , 250 'BEEP Sound Portd.7 , 400 , 450 'BEEP Const Ref = 5 / 1023 'Für Batteriespannungsberechnung Config Portc = Output '** I2C Zeuchs Config Scl = Portc.0 Config Sda = Portc.1 S20_adress = 194 Aktakt = 0 ' Für Motoren 'Ports für linken Motor Config Pinc.6 = Output 'Linker Motor Kanal 1 Config Pinc.7 = Output 'Linker Motor Kanal 2 Config Pind.4 = Output 'Linker Motor PWM 'Ports für rechten Motor Config Pinb.0 = Output 'Rechter Motor Kanal 1 Config Pinb.1 = Output 'Rechter Motor Kanal 2 Config Pind.5 = Output 'Rechter Motor PWM Config Timer1 = Pwm , Pwm = 10 , Compare A Pwm = Clear Down , Compare B Pwm = Clear Down Pwm1a = 0 Pwm1b = 0 Tccr1b = Tccr1b Or &H02 'Prescaler = 8 '** Beide Motoren vorwärts Portc.6 = 1 Portc.7 = 0 Portb.0 = 0 Portb.1 = 1 '** I2C-Test Neuergrad = 0 Call Kopfausrichtung(neuergrad) Waitms 300 Fahrprogramm '** Losfahren... Sub Fahrprogramm() Local Irr As Word Local Irl As Word Local Irk As Word Local Letzterkontakt As Integer Local Ausweichrichtung As Integer Letzterkontakt = 0 Do Start Adc Irl = Getadc(0) Irr = Getadc(1) Irk = Getadc(2) '* Daten an RS232 ausgeben Volt = Irl * Ref Print "Kopf = " ; Irk '* Kurs korrigieren nach rechts (Hindernis links) If Irl > 120 And Irr < 120 And Irk < 480 Then Aktakt = 0 Portc.6 = 1 Portc.7 = 0 Portb.0 = 0 Portb.1 = 1 Pwm1b = 500 Letzterkontakt = 0 End If '* Kurs korrigieren nach links (Hindernis rechts) If Irr > 120 And Irl < 120 And Irk < 480 Then Aktakt = 0 Portc.6 = 1 Portc.7 = 0 Portb.0 = 0 Portb.1 = 1 Pwm1a = 500 Letzterkontakt = 1 End If '* Keine Hindernisse -> Volle Fahrt If Irr < 120 And Irl < 120 And Irk < 480 Then Aktakt = 0 Neuergrad = 0 Call Kopfausrichtung(neuergrad) Portc.6 = 1 Portc.7 = 0 Portb.0 = 0 Portb.1 = 1 Pwm1a = 1023 Pwm1b = 1023 End If '* Direkt vor Hindernis If Irr > 300 Or Irl > 300 Or Irk > 480 Then Pwm1a = 0 Pwm1b = 0 If Aktakt = 0 Then Ausweichrichtung = Scanneumgebung() Aktakt = 1 End If If Ausweichrichtung = 0 Then Portc.6 = 0 Portc.7 = 1 Portb.0 = 0 Portb.1 = 1 Pwm1a = 1023 Pwm1b = 1023 End If If Ausweichrichtung = 1 Then Portc.6 = 1 Portc.7 = 0 Portb.0 = 1 Portb.1 = 0 Pwm1a = 1023 Pwm1b = 1023 End If End If Waitms 100 Loop End Sub 'Umgebung scannen Function Scanneumgebung() As Integer Local Rentfernung As Word Local Lentfernung As Word Local Aentfernung As Word Local Temp As Word Local Ngrad As Integer Rentfernung = 0 Lentfernung = 0 Aentfernung = 0 Ngrad = 0 Temp = 0 For Ngrad = 0 To 90 Step 10 Call Kopfausrichtung(ngrad) Aentfernung = Getadc(2) Waitms 50 If Aentfernung > Temp Then Temp = Aentfernung Next Ngrad Rentfernung = Aentfernung Ngrad = 0 Call Kopfausrichtung(ngrad) Waitms 150 Temp = 0 Aentfernung = 0 For Ngrad = 0 To -90 Step -10 Call Kopfausrichtung(ngrad) Aentfernung = Getadc(2) Waitms 50 If Aentfernung > Temp Then Temp = Aentfernung Next Ngrad Lentfernung = Aentfernung Ngrad = 0 Call Kopfausrichtung(ngrad) If Lentfernung > Rentfernung Then Scanneumgebung = 0 If Rentfernung > Lentfernung Then Scanneumgebung = 1 End Function 'Ausrichten des IR-Kopfsensors Sub Kopfausrichtung(grad As Integer) Local Position As Integer Position = 105 + Grad If Position > 200 Then Position = 200 If Position < 20 Then Position = 20 I2cstart I2cwbyte S20_adress I2cwbyte 71 I2cwbyte Position I2cstop Waitms 50 End Sub Sub Batteriespannung() Local W As Word Start Adc W = Getadc(6) Volt = W * Ref Volt = Volt * 5.2941 Print "Die aktuelle Spannung beträgt: " ; Volt ; " Volt" End Sub End
Robin







Zitieren

Lesezeichen