Hallo,

Ich versuche nun schon sein Tagen meine Tropfensteuerung zu programmieren. Komme aber nicht weiter.
Habe zwei taste als Eingänge und zwei Relais als Ausgänge, ein für Kamera und das andere für das Ventil.
Zwei Potis zum einstellen der Zeit.

Nun zu meinen Problemen:
1 Die Poti Zeiteinstellung soll nur verändert werden wenn ich auch am Poti drehe und wenn nicht gedreht wird soll der alte wert weiter stehen? da weiß ich noch nicht wie ich das realiesiere?

2. Problem und das was mich am meisten stört. Wenn ich die Tropfensteuerung starte, soll ein Interrupt gestartet werden der nach einer bestimmten voreingestellte Zeit die Kamera aus löst?
in der zwischen zeit sollen zwei Tropfen ausgelöst werden.
Das Programm verhält sich so, das manchmal nur ein tropfen kommt und der Controller neu startet? ich weiß aber nicht warum. Da wenn ich die selben Zeiten nehme geht es manch mal, aber manchmal nicht.

Ich hoffe mir kann jemand helfen oder vorschlage zur Verbesserung geben. das ich Programmierung nur mir etwas angelernt habe.


Code:
$regfile = "m8def.dat"
$crystal = 3686400
$hwstack = 128
$swstack = 128
$framesize = 128


' LCD Einstellen
Config Lcd = 16 * 2
Config Lcdpin = Pin , Db4 = Portd.4 , Db5 = Portd.5 , Db6 = Portd.6 , Db7 = Portd.7 , E = Portd.3 , Rs = Portd.2

' Eingänge einstellen Poti


'eingange Taster
Config Pinb.4 = Input
Config Pinb.5 = Input
Taster1 Alias Pinb.4
Taster2 Alias Pinb.5
Portb.4 = 1
Portb.5 = 1

'Ausgang LED                       Led1= Rot , LED2 = Gelb
Config Portb.3 = Output
Config Portb.2 = Output
Led1 Alias Portb.2
Led2 Alias Portb.3

' Ralias Ventil                    Ventil , Nikon
Config Portb.0 = Output
Config Portb.1 = Output
Ventil Alias Portb.1
Nikon Alias Portb.0


'variabeln
Dim Ausloesen As Integer

Dim Tropfen1 As Integer
Dim Tropfen1_zeit As Word

Dim Tropfen2 As Integer
Dim Tropfen2_zeit As Word

Dim Tat As Integer
Dim Tat_zeit As Word

Dim Poti1 As Integer
Dim Poti1_1 As Integer
Dim Poti1_1min As Integer
Dim Poti1_1max As Integer
Dim Poti1_roh As Integer
Dim Poti1_roh1 As Integer
Dim Poit1_last As Integer

Dim Poti2 As Integer
Dim Poti2_1 As Integer
Dim Poti2_1min As Integer
Dim Poti2_1max As Integer
Dim Poti2_roh As Integer
Dim Poti2_roh1 As Integer
Dim Poti2_last As Integer
Const Teiler = 10

Dim Kamera As Integer
Dim Kamera_1 As Integer
Dim Kamera_roh As Integer
Dim Kamera_timer_2 As Integer
Dim Kamera_last As Integer
Dim Kamera_timer As Integer

Poti1_roh1 = 60
Poti2_roh1 = 100

Config Timer1 = Timer , Prescale = 256
Enable Timer1
Stop Timer1
Enable Interrupts
Timer1 = 0

Config Adc = Single , Prescaler = Auto , Reference = Avcc
Start Adc

Anfang:   '-------------------------------------------------------------Anfang


Cursor Off
Cls
Locate 1 , 1
Lcd "Erstellt von"
Locate 2 , 1
Lcd "SHP-ART.de"
Wait 1
Cls
Locate 1 , 1
Lcd "Wassertropfen"
Locate 2 , 1
Lcd "Generator V.2.0"
Led1 = 1
Led2 = 1
Waitms 250
Led2 = 0
Waitms 250
Led1 = 0
Waitms 250

Programm1:       '-------------------------------------------------------Programm1

Led1 = 0
Led2 = 0
Cls
Locate 1 , 1
Lcd "Taste1=Start"
Locate 2 , 1
Lcd "Taste2=entlüften"


Do

   If Taster1 = 0 Then
   Waitms 50
      If Taster1 = 0 Then
      Led1 = 1
      Wait 1
      Gosub Ventilzeit
      Led1 = 0
      End If
   End If


   If Taster2 = 0 Then
   Waitms 50
      If Taster2 = 0 Then
      Led2 = 1
      Wait 1
      Gosub Entlueften
      End If
   End If

Loop

Programm2:       '------------------------------------------------------Programm2
Led1 = 1
Led2 = 0
Cls
Locate 1 , 1
Lcd "Taste1=Nochmal"
Locate 2 , 1
Lcd "Taste2=Einstellen"


Do
Nikon = 0
   If Taster1 = 0 Then
   Waitms 50
      If Taster1 = 0 Then
      Led1 = 1
      Wait 1
      Gosub Start_tat
      Led1 = 0
      End If
   End If


   If Taster2 = 0 Then
   Waitms 50
      If Taster2 = 0 Then
      Led2 = 1
      Wait 1
      Gosub Ventilzeit
      End If
   End If

Loop




Ventilzeit:       '-----------------------------------------------------------------------Ventil abfragen Zeit einstellen

Cls
Locate 1 , 1
Lcd "Zeit einstellen"
Locate 2 , 1
Lcd "Ventil 1"
Wait 1
Locate 1 , 1
Lcd "Taste1 weiter"
Locate 2 , 1
Lcd "Taste2 abbrechen"
Wait 1

Einstellen:       '---------------------------------------------------------------einstellen
Cls
Locate 1 , 5
Lcd "Tropfen zeit"
Locate 2 , 5
Lcd "TaT Zeit"
Poti1_1 = Getadc(1)
Poti2_1 = Getadc(0)

Do


Poti1 = Getadc(1)
Poti2 = Getadc(0)

Poti1_1max = Poti1_roh + Teiler
Poti1_1min = Poti1_roh - Teiler
Poti2_1max = Poti2_roh + Teiler
Poti2_1min = Poti2_roh - Teiler


If Poti1_1max < Poti1 Or Poti1_1min > Poti1 Then
    Poti1_roh = Poti1
    Poit1_last = Poti1_roh / 2
    Poti1_roh1 = Poti1_roh / 2
    Locate 1 , 1
    Lcd "   "
    Locate 1 , 1
    Lcd Poit1_last
Else
    If Poti1 = Poti1_1 Then
      Poit1_last = Poti1_roh1
      Locate 1 , 1
      Lcd "   "
      Locate 1 , 1
      Lcd Poit1_last
    End If
End If


If Poti2_1max < Poti2 Or Poti2_1min > Poti2 Then
       Poti2_roh = Poti2
       Poti2_last = Poti2_roh / 2
       Poti2_roh1 = Poti2_roh / 2
       Locate 2 , 1
       Lcd "   "
       Locate 2 , 1
       Lcd Poti2_last
Else
       If Poti2 = Poti2_1 Then
         Poti2_last = Poti2_roh1
         Locate 2 , 1
         Lcd "   "
         Locate 2 , 1
         Lcd Poti2_last
       End If
End If



'Tasterabfrage-----------------------------------------------------------------

   If Taster1 = 0 Then
   Waitms 50
      If Taster1 = 0 Then
      Led1 = 1
      Wait 1
      Cls
      Locate 1 , 1
      Lcd "weiter"
      Waitms 500
      Gosub Kamera
      End If
   End If


   If Taster2 = 0 Then
   Waitms 50
      If Taster2 = 0 Then
      Led2 = 1
      Wait 1
      Cls
      Locate 1 , 1
      Lcd "Abbrechen"
      Wait 1
      Gosub Anfang
      End If
   End If



Loop

Kamera:   '--------------------------------------------------Kamera zeiteinstellen
Kamera_1 = Getadc(1)

Cls
Locate 1 , 1
Lcd "Kamera auslösezeit"
Locate 2 , 1
Lcd "Einstellen"
Wait 1
Cls
Locate 1 , 5
Lcd "Auslösung"
Locate 2 , 1
Lcd "in ms"
Waitms 250

Do

Kamera = Getadc(1)

        If Kamera_1 = Kamera Then
         Kamera_timer = Kamera_timer_2
         Locate 2 , 1
         Lcd "   "
         Locate 2 , 1
         Lcd Kamera_timer
        Else
            If Kamera <> Kamera_last Then
              Kamera_last = Kamera
              Kamera_timer = Kamera_last * 14
              Kamera_timer_2 = Kamera_timer
              Locate 1 , 1
              Lcd "   "
              Locate 1 , 1
              Lcd Kamera_last
              Locate 2 , 7
              Lcd "     "
              Lcd Kamera_timer
            End If
        End If

'Taster abfragen

   If Taster1 = 0 Then
     Waitms 50
      If Taster1 = 0 Then
         Led1 = 1
         Cls
         Locate 1 , 1
         Lcd "weiter"
         Waitms 250
         Gosub Start_tat
      End If
   End If


   If Taster2 = 0 Then
     Waitms 50
      If Taster2 = 0 Then
         Led2 = 1
         Wait 1
         Cls
         Locate 1 , 1
         Lcd "Abbrechen"
         Wait 1
         Gosub Anfang
      End If
   End If

Loop
'##############################################################################


Start_tat:

Cls
Locate 1 , 1
Lcd "Start"
Waitms 250
Cls
Locate 1 , 1
Lcd "Tropfenzeit"
Locate 2 , 1
Lcd Poit1_last
Locate 2 , 5
Lcd "ms"
Waitms 500
Cls
Locate 1 , 1
Lcd "TaT zeit"
Locate 2 , 1
Lcd Poti2_last
Locate 2 , 5
Lcd "ms"
Waitms 500
Cls
Locate 1 , 1
Lcd "Kamera auslösung"
Locate 2 , 1
Lcd Kamera_last
Locate 2 , 5
Lcd "ms"
'--------------------------------------Variablen setzen
Tropfen1_zeit = Poit1_last
Tropfen2_zeit = Tropfen1_zeit
Tat_zeit = Poti2_last

'Wartezeit Ventil
'Wassertropen 1
'-------------------------------------Timer einstellen
Load Timer1 , Kamera_timer
On Timer1 Foto
Start Timer1
Waitms 1
'------------------------------------Ventile auslösen
Ventil = 1
Waitms Tropfen1_zeit
Ventil = 0

Waitms Tat_zeit

Ventil = 1
Waitms Tropfen2_zeit
Ventil = 0

Cls
Locate 1 , 1
Lcd "Fertig"
Wait 2

'Tropfen2_zeit = 0
'Tropfen2_zeit = 0
'Tat_zeit = 0
'Kamera_timer = 0

Goto Programm2       '###########################################################   Anfang


Entlueften:
                                                 '------------------------------------------------------- programm enfüften
Cls
Locate 1 , 1
Lcd "entlüften"
Locate 2 , 1
Lcd " gedrückt haten"
Waitms 250

Offen:
Do
Ventil = 1
If Taster2 = 0 Then
     Waitms 50
      If Taster2 = 0 Then
         Gosub Offen
      End If
     Else
     Ventil = 0
     Goto Programm1
End If
Loop
'Goto Programm1       '##############################################################   Anfang


Foto: '----------------------------- Kamera auslösen
Nikon = 1
Stop Timer1
Timer1 = 0

Return