Hier mal der Code, der nicht funktioniert:
Code:
$crystal = 8000000
$baud = 9600
Declare Sub Stepper_move(byval Stepper_goto_pos As Word)
Declare Sub Shoulder_move(byval Shoulder_goto_pos As Integer)
Declare Sub Elbow_move(byval Elbow_goto_pos As Integer)
Const Writepowerport_adr = &H72 'I2C Adr PCF 2
Const Readpowerport_adr = &H73 'I2C Adr PCF 2
Dim I2cdaten As Byte 'Datenbyte aus PCF8574
Dim I As Integer
$crystal = 8000000 'Quarzfrequenz
Config Scl = Portc.0 'Ports fuer IIC-Bus
Config Sda = Portc.1
I2cinit
Config Pind.6 = Output 'Schrittmotoren Ein/Aus
Config Pinc.5 = Output 'Schrittmotor Links Richtung
Config Pinc.3 = Output 'Schrittmotor Links Step
Config Pinc.4 = Output 'Schrittmotor Rechts Richtung
Config Pinc.2 = Output 'Schrittmotor Rechts Step
Portd.6 = 0 'Schrittmotoren ausschalten
Dim Stepper_curr_pos As Integer
Stepper_curr_pos = 0
Dim Shoulder_curr_pos As Integer
Shoulder_curr_pos = 127
Dim Elbow_curr_pos As Integer
Elbow_curr_pos = 127
Dim Temp As Byte
Hauptschleife:
Call Elbow_move(0)
Wait 1
Call Shoulder_move(255)
Wait 1
Goto Hauptschleife
Sub Shoulder_move(byval Shoulder_goto_pos As Integer)
Local Schritt As Integer
If Shoulder_curr_pos < Shoulder_goto_pos Then
Schritt = 1
Elseif Shoulder_curr_pos > Shoulder_goto_pos Then
Schritt = -1
Elseif Shoulder_curr_pos = Shoulder_goto_pos Then
Exit Sub
End If
Open "comd.7:9600,8,n,1" For Output As #2
For Shoulder_curr_pos = Shoulder_curr_pos To Shoulder_goto_pos Step Schritt
Temp = Shoulder_curr_pos
Print #2 , "#s" ; Chr(1) ; Chr(temp)
Print #2 , "#s" ; Chr(2) ; Chr(temp)
Print "SHOULDER: " ; "Schritt: " ; Schritt ; " CURR: " ; Temp ; " GOTO: " ; Shoulder_goto_pos
Next Shoulder_curr_pos
Close #2
Shoulder_curr_pos = Shoulder_goto_pos
End Sub
Sub Elbow_move(byval Elbow_goto_pos As Integer)
Local Schritt As Integer
If Elbow_curr_pos < Elbow_goto_pos Then
Schritt = 1
Elseif Elbow_curr_pos > Elbow_goto_pos Then
Schritt = -1
Elseif Elbow_curr_pos = Elbow_goto_pos Then
Exit Sub
End If
Print "elbow"
Open "comd.7:9600,8,n,1" For Output As #2
For Elbow_curr_pos = Elbow_curr_pos To Elbow_goto_pos Step Schritt
Temp = Elbow_curr_pos
Print #2 , "#s" ; Chr(3) ; Chr(temp)
Print "ELBOW: " ; "Schritt: " ; Schritt ; " CURR: " ; Temp ; " GOTO: " ; Elbow_goto_pos
Next Elbow_curr_pos
Close #2
Elbow_curr_pos = Elbow_goto_pos
End Sub
Sub Stepper_move(byval Stepper_goto_pos As Intgeger)
Local Betrag As Integer
If Stepper_goto_pos > Stepper_curr_pos Then
Betrag = Stepper_goto_pos - Stepper_curr_pos
Portc.5 = 0 'Richtung
Portc.3 = 0
For I = 0 To Betrag Step 1
Portc.3 = 0
Waitms 5
Portc.3 = 1
Waitms 30
Next I
Stepper_curr_pos = Stepper_goto_pos
Print Stepper_curr_pos
Elseif Stepper_goto_pos < Stepper_curr_pos Then
Betrag = Stepper_curr_pos - Stepper_goto_pos
Portc.5 = 1 'Richtung
Portc.3 = 0
For I = 0 To Betrag Step 1
Portc.3 = 0
Waitms 5
Portc.3 = 1
Waitms 30
Next I
Stepper_curr_pos = Stepper_goto_pos
Print Stepper_curr_pos
End If
End Sub
End
Das seltsame ist, dass diese Hauptschleife funktioniert:
Code:
Hauptschleife:
Call Shoulder_move(255)
Wait 1
Call Elbow_move(0)
Wait 1
Goto Hauptschleife
diese aber nicht:
Code:
Hauptschleife:
Call Elbow_move(0)
Wait 1
Call Shoulder_move(255)
Wait 1
Goto Hauptschleife
hier bewegt sich die Schulter nach ewiger Zeit auf 255, dannach passiert nichts mehr, egal wie lange ich warte.
mfg
jagdfalke
Lesezeichen