Zur Übersicht - INFO - Neueste 50 Beiträge - Neuer Beitrag - Suchen - Zum C-Control-I-Forum - Zum C-Control-II-Forum

Programm stürzt ab Kategorie: Programmierung Basic (von Sebastian - 20.02.2010 3:16)
Ich nutze:
C-Control Pro Mega128, CC-Pro 128 Application Board
Ich bin relativ neu im Thema und Rätsele im Moment warum mein Programm dauernd abstürzt
hier mal der Code den ich zusammen gebaut habe (manches ist noch nicht Fertig oder mit Test Code
Versehen.
Datei1

'Programm zur Steuerung des Pannels mit Regelung (Lichtnachführung)
'
'---Hauptprogramm---
'
'--I2C-Adressen--
   #define Motor1 &HC4
   #define Motor2 &HC2
   #define Motor3 &HC0
'--Konstanten--
'   #define Constante1 1
'   #define Constante2 2
'   #define Constante3 3
'--Variablen--
    Dim ConfigTest As Byte      'Konfigurationsstatus
    Dim S1 As Single            'Wert Sensor 1
    Dim S2 As Single            'Wert Senosr 2
    Dim S3 As Single            'Wert Sensor 3
    Dim S4 As Single            'Wert Sensor 4
    Dim Auswertung As Byte      'Wert der Sensor-Auswertung
'
'--Hauptprogramm--
'
Sub main()
'--Initialisierung--
ConfigTest = 0                  'Kofiguration auf nicht getestet setzen
I2C_Init(I2C_100kHz)            'Konfiguration des I2C-Bussystems
LCDstart()                      'LCD Löschen
Do While True                   'Hauptschleife Anfang
                                'Ã?berprüfen der Konfiguration des Pannels
    If ConfigTest = 0 Then      'Pannel ist nich Konfiguriert
        Pannelconfig()          'Aufruf des Konfigprogramms
    ElseIf ConfigTest = 1 Then  'Wenn Konfiguration in Ordnung dan Programm ausführen
        S1 = Sensor(1)          'Sensor 1 Abfragen
        S2 = Sensor(2)          'Sensor 2 Abfragen
        S3 = Sensor(3)          'Sensor 3 Abfragen
        S4 = Sensor(4)          'Sensor 4 Abfragen
'
'Sensoren Auswerten und Ergebnis speichern
'
        Auswertung = Sensorauswertung(S1, S2, S3, S4)

        If Auswertung <> 9 Then
'
'Motor Steuerung
'
            motorcontrol(Auswertung)
        End If
    End If
End While               'Ende der Hauptschleife
End Sub


Datei 2


'LCD Starten
Sub LCDstart()
    LCD_Init()
    LCD_CursorOff()
    LCD_ClearLCD()
End Sub


Datei 3 (Hier habe ich das meiste Ausergefecht gesetzt würde das aber mit dem Entsprechendem Code
Versehen gehen?)  


'Herstellen der Grundconfiguration des Pannels
'/Erzeugen einer Deffinierten Lage/Position
'
'Variablen für Prüfung
'
Dim Data01 As Byte
Dim Data02 As Byte
Dim Data03 As Byte
Dim Data04 As Byte
Dim Data05 As Byte
Dim Data06 As Byte
Dim Data07 As Byte
Dim Data08 As Byte
Dim Data09 As Byte
Dim Data10 As Byte
Dim Data11 As Byte
Dim Data12 As Byte
Dim Data13 As Byte
Dim Data14 As Byte
Dim Data15 As Byte
Dim Data16 As Byte
Dim Data17 As Byte
Dim Data18 As Byte
Dim Data19 As Byte
Dim Data20 As Byte
Dim Data21 As Byte
Dim Data22 As Byte
Dim Data23 As Byte
Dim Data24 As Byte
Dim Data25 As Byte
Dim Data26 As Byte
Dim Data27 As Byte
Dim Data28 As Byte
Dim Data29 As Byte
Dim Data30 As Byte
Dim Data31 As Byte
Dim Data32 As Byte
Dim Data33 As Byte
Dim Data34 As Byte
Dim Data35 As Byte
Dim Data36 As Byte
Dim Data37 As Byte
Dim Data38 As Byte
Dim Data39 As Byte
Dim Data40 As Byte
Dim Data41 As Byte
Dim Data42 As Byte
Dim Data43 As Byte
Dim Data44 As Byte
Dim Data45 As Byte
Dim Data46 As Byte
Dim Data47 As Byte
Dim Data48 As Byte
'
'Pannelkonfigurations Programm
'
Sub Pannelconfig()
    '
    'Config für Testzwecke auÃ?ergefecht gesetzt
    '
    Goto Test
    I2C_Start()
    I2C_Write(Motor1)
    I2C_Write(1)
    I2C_Write(2)
    I2C_Write(3)
    I2C_Write(4)
    I2C_Write(5)
    I2C_Stop()

    AbsDelay(100)

    I2C_Start()
    I2C_Write(Motor2)
    I2C_Write(1)
    I2C_Write(2)
    I2C_Write(3)
    I2C_Write(4)
    I2C_Write(5)
    I2C_Stop()

    AbsDelay(100)

    I2C_Start()
    I2C_Write(Motor3)
    I2C_Write(1)
    I2C_Write(2)
    I2C_Write(3)
    I2C_Write(4)
    I2C_Write(5)
    I2C_Stop()

    AbsDelay(100)
'
'Prüfung
'
'Motor1 - Teil 1
'
    I2C_Start()
    I2C_Write(Motor1)
    I2C_Write(&H81)
    I2C_Stop()

    I2C_Start()
    I2C_Write(Motor1+1)
    Data01 = I2C_Read_ACK()
    Data02 = I2C_Read_ACK()
    Data03 = I2C_Read_ACK()
    Data04 = I2C_Read_ACK()
    Data05 = I2C_Read_ACK()
    Data06 = I2C_Read_ACK()
    Data07 = I2C_Read_ACK()
    Data08 = I2C_Read_NACK()
    I2C_Stop()
'
'Motor1 - Teil 2
'
    I2C_Start()
    I2C_Write(Motor1)
    I2C_Write(&HFC)
    I2C_Stop()

    I2C_Start()
    I2C_Write(Motor1+1)
    Data09 = I2C_Read_ACK()
    Data10 = I2C_Read_ACK()
    Data11 = I2C_Read_ACK()
    Data12 = I2C_Read_ACK()
    Data13 = I2C_Read_ACK()
    Data14 = I2C_Read_ACK()
    Data15 = I2C_Read_ACK()
    Data16 = I2C_Read_NACK()
    I2C_Stop()
'
'Motor2 - Teil 1
'
    I2C_Start()
    I2C_Write(Motor2)
    I2C_Write(&H81)
    I2C_Stop()

    I2C_Start()
    I2C_Write(Motor2+1)
    Data17 = I2C_Read_ACK()
    Data18 = I2C_Read_ACK()
    Data19 = I2C_Read_ACK()
    Data20 = I2C_Read_ACK()
    Data21 = I2C_Read_ACK()
    Data22 = I2C_Read_ACK()
    Data23 = I2C_Read_ACK()
    Data24 = I2C_Read_NACK()
    I2C_Stop()
'
'Motor2 - Teil 2
'
    I2C_Start()
    I2C_Write(Motor2)
    I2C_Write(&HFC)
    I2C_Stop()

    I2C_Start()
    I2C_Write(Motor2+1)
    Data25 = I2C_Read_ACK()
    Data26 = I2C_Read_ACK()
    Data27 = I2C_Read_ACK()
    Data28 = I2C_Read_ACK()
    Data29 = I2C_Read_ACK()
    Data30 = I2C_Read_ACK()
    Data31 = I2C_Read_ACK()
    Data32 = I2C_Read_NACK()
    I2C_Stop()
'
'Motor3 - Teil 1
'
    I2C_Start()
    I2C_Write(Motor3)
    I2C_Write(&H81)
    I2C_Stop()

    I2C_Start()
    I2C_Write(Motor3+1)
    Data33 = I2C_Read_ACK()
    Data34 = I2C_Read_ACK()
    Data35 = I2C_Read_ACK()
    Data36 = I2C_Read_ACK()
    Data37 = I2C_Read_ACK()
    Data38 = I2C_Read_ACK()
    Data39 = I2C_Read_ACK()
    Data40 = I2C_Read_NACK()
    I2C_Stop()
'
'Motor3 - Teil 2
'
    I2C_Start()
    I2C_Write(Motor3)
    I2C_Write(&HFC)
    I2C_Stop()

    I2C_Start()
    I2C_Write(Motor3+1)
    Data41 = I2C_Read_ACK()
    Data42 = I2C_Read_ACK()
    Data43 = I2C_Read_ACK()
    Data44 = I2C_Read_ACK()
    Data45 = I2C_Read_ACK()
    Data46 = I2C_Read_ACK()
    Data47 = I2C_Read_ACK()
    Data48 = I2C_Read_NACK()
    I2C_Stop()
'
'Konfiguration Testen und Einstellen der ConfigTest Variable
'
    If Data01 = &H02 And Data02 = &H00 And Data03 = &H00 And Data04 = &H00 And Data05 = &H00
And Data06 = &H00 And Data07 = &H00 And Data08 = &H00 Then
        If Data09 = &H02 And Data10 = &H00 And Data11 = &H00 And Data12 = &H00 And Data13 = &H00
And Data14 = &H00 And Data15 = &H00 And Data16 = &H00 Then
            If Data17 = &H01 And Data18 = &H00 And Data19 = &H00 And Data20 = &H00 And Data21 = &H00
And Data22 = &H00 And Data23 = &H00 And Data24 = &H00 Then
                If Data25 = &H01 And Data26 = &H00 And Data27 = &H00 And Data28 = &H00 And
Data29 = &H00 And Data30 = &H00 And Data31 = &H00 And Data32 = &H00 Then
                    If Data33 = &H00 And Data34 = &H00 And Data35 = &H00 And Data36 = &H00 And
Data37 = &H00 And Data38 = &H00 And Data39 = &H00 And Data40 = &H00 Then
                        If Data41 = &H00 And Data42 = &H00 And Data43 = &H00 And Data44 = &H00 And
Data45 = &H00 And Data46 = &H00 And Data47 = &H00 And Data48 = &H00 Then
                            Lab Test
                            ConfigTest = 1
                            Goto Test2
                        End If
                    End If
                End If
            End If
        End If
    End If
    Lab Test2
End Sub


Datei 4 (Hier will die Auswertung der Ergebnisse nicht so recht kommen in einem Dunkelen Raum
die Ersten vier Werte die letzen 4 und der 9 überhaupt nicht mir Fällt aber keine Alternative zu
"If" Ein)
 

'Abfragen der Sensoren
'
Sub Sensor(snr As Byte) As Single
    Dim Sensorwert As Single
'    Dim Sensorrueck As Single   'Sensorrückgabewert
    snr = snr - 1
    Sensorwert = Read_Volt(snr)
    Return Sensorwert
End Sub
'
'
'
Sub Read_Volt(snrrv As Byte) As Single
    Dim ADC_RAW As Word
    Dim Ref As Single
    Dim Volt As Single
    Ref = 5.0/1023.0
    ADC_RAW = GetAdc(snrrv)
    Volt = ADC_RAW * Ref
    Return Volt
End Sub
'
'
'
Sub GetAdc(Channel As Byte) As Word
    ADC_Set(ADC_VREF_VCC,Channel)
    ADC_Read()
    Return ADC_Read()
End Sub
'
'Auswertung der Sensoren
'
Sub Sensorauswertung(sa1 As Single, sa2 As Single, sa3 As Single, sa4 As Single)As Byte
    Dim Rechnen As Single
    Dim Rechnen2 As Single
    Dim Ergebnis As Byte
'
'Berechnen des Durchschnitts der Sensorwerte
'
    Rechnen = sa1*sa2*sa3*sa4
    Rechnen2 = Rechnen/4
'
'Auswerten des Ergebnises
'
'Einzelsensoren
'
    If sa1 < sa2 And sa1 < sa3 And sa1 < sa4 Then
        Ergebnis = 1

    ElseIf sa2 < sa1 And sa2 < sa3 And sa2 < sa4 Then
        Ergebnis = 2

    ElseIf sa3 < sa1 And sa3 < sa2 And sa3 < sa4 Then
        Ergebnis = 3

    ElseIf sa4 < sa1 And sa4 < sa2 And sa4 < sa3 Then
        Ergebnis = 4
'
'Zwei Sensoren
'
    ElseIf sa1 < Rechnen2 And sa2 < Rechnen2 And sa3 > Rechnen2 And sa4 > Rechnen2 Then
        Ergebnis = 5

    ElseIf sa3 < Rechnen2 And sa4 < Rechnen2 And sa1 > Rechnen2 And sa2 > Rechnen2 Then
        Ergebnis = 6

    ElseIf sa1 < Rechnen2 And sa3 < Rechnen2 And sa2 > Rechnen2 And sa4 > Rechnen2 Then
        Ergebnis = 7

    ElseIf sa2 < Rechnen2 And sa4 < Rechnen2 And sa1 > Rechnen2 And sa3 > Rechnen2 Then
        Ergebnis = 8

    Else
        Ergebnis = 9    'Nichtstun

    End If
'
'Rückgabe des Bytecodes für Fahranweisung an Motor
'
    Return Ergebnis
End Sub


Datei 5 (Das hier dient nur zum Testen der Sensorergebnisse, Stürzt aber manchmal bei
Msg_WriteChar(13) ab, danach muss immer die C-Controll Resete werden)


Sub motorcontrol (anweisung As Byte)
    'Test Code
    Msg_WriteHex(anweisung)
    anweisung = 0
    Msg_WriteChar(13)     'Hier stürzt das Programm glaube ich ab
    AbsDelay(50)
End Sub


Das Programm soll ein Pannel mit Vier helligkeitssensoren Steuern (über Stepper und den TMC222
angesteuert). Ich muss die Abstürze los werden an sonsten brauche ich ja garnicht weiter zu machen.
Andereseits wäre ich auch für Tipps wie ich die Sensor Auswertung Verbessern könnte dankbar.


    Antwort schreiben


Antworten:

Re: Programm stürzt ab (von erzgebirgler47 - 20.02.2010 10:11)
    Re: Programm stürzt ab (von Sebastian - 21.02.2010 20:49)
Re: Programm stürzt ab (von Sebastian - 20.02.2010 3:18)