robbifan
17.05.2007, 12:52
hallo, ich habe das angebenen programm auf dem avrboard2 um einen motor zusteuern am roboter. beim int2 muss ich zusätzlich print text eingeben, ansonsten empfängt er nicht vom 1. avrboard den text.
was ist das für ein komisches zusammenspiel?
also so funktioniert das programm einwandfrei, vor,links,rechts,zurück fährt der roboter, bloss wenn ich print text rausnehme fährt er nicht mehr.
verbindung board 2 zu board 1 : pinb.2 zu pind.6, pind.6 zu pinb.2
rx und tx der beiden boards sind nicht beschaltet und es hängt auch nichts dran.
mfg
empfangsprogramm avrboard 2.
$Regfile = "M32def.dat"
$Crystal = 8000000
$HWStack = 32
$SWStack = 32
$FrameSize = 64
$Baud = 19200
Dim M_wert_a As Byte , M_wert_b As Byte
Dim Text As String * 16
Declare Sub Robby_vor()
Declare Sub Robby_zurueck()
Declare Sub Robby_links()
Declare Sub Robby_rechts()
Declare Sub Robby_links_drehen()
Declare Sub Robby_rechts_drehen()
Declare Sub Robby_aus()
Declare Sub L293_pin()
declare sub empfang()
Config Timer1 = Pwm , Pwm = 8 , Compare A Pwm = Clear Up , Compare B Pwm = Clear Up , Prescale = 256
Start Timer1
config int2=rising
On Int2 Int2_int
Enable Interrupts
Enable Int2
Open "comb.2:9600,8,n,1" For Input As #1
Open "comd.6:9600,8,n,1" For Output As #2
M_wert_a = 100
M_wert_b = 100
Call L293_pin()
do
waitms 300
loop
End
Int2_int:
Disable Int2
Enable Interrupts
input #1, text
print text
call empfang()
enable int2
Return
sub empfang()
If Text = "vor" Then
Call Robby_vor()
End If
If Text = "zurueck" Then
Call Robby_zurueck()
End If
If Text = "links" Then
Call Robby_links()
End If
If Text = "rechts" Then
Call Robby_rechts()
End If
If Text = "stop" Then
Call Robby_aus()
End If
end sub
Sub L293_pin()
Ddrc.2 = 1
Ddrc.3 = 1
Ddrc.4 = 1
Ddrc.5 = 1
Ddrd.4 = 1
Ddrd.5 = 1
End Sub
Sub Robby_vor()
Portc.2 = 0
Portc.3 = 1
Portd.5 = 1
Portc.4 = 0
Portc.5 = 1
Portd.4 = 1
Pwm1a = M_wert_a
Pwm1b = M_wert_b
End Sub
Sub Robby_zurueck()
Portc.2 = 1
Portc.3 = 0
Portd.5 = 1
Portc.4 = 1
Portc.5 = 0
Portd.4 = 1
Pwm1a = M_wert_a
Pwm1b = M_wert_b
End Sub
Sub Robby_links()
Portc.2 = 0
Portc.3 = 1
Portd.5 = 1
Portc.4 = 0
Portc.5 = 0
Portd.4 = 0
Pwm1a = M_wert_a
Pwm1b = 0
End Sub
Sub Robby_rechts()
Portc.2 = 0
Portc.3 = 0
Portd.5 = 0
Portc.4 = 0
Portc.5 = 1
Portd.4 = 1
Pwm1a = 0
Pwm1b = M_wert_b
End Sub
Sub Robby_aus()
Portc.2 = 0
Portc.3 = 0
Portd.4 = 0
Portc.4 = 0
Portc.5 = 0
Portd.5 = 0
Pwm1a = 0
Pwm1b = 0
End Sub
Sub Robby_rechts_drehen()
Portc.2 = 1
Portc.3 = 0
Portd.5 = 1
Portc.4 = 0
Portc.5 = 1
Portd.4 = 1
Pwm1a = M_wert_a
Pwm1b = M_wert_b
End Sub
Sub Robby_links_drehen()
Portc.2 = 0
Portc.3 = 1
Portd.5 = 1
Portc.4 = 1
Portc.5 = 0
Portd.4 = 1
Pwm1a = M_wert_a
Pwm1b = M_wert_b
End Sub
sendeprogamm avrboard 1
$Regfile = "M32def.dat"
$Crystal = 8000000
$HWStack = 32
$SWStack = 32
$FrameSize = 64
$Baud = 19200
Dim Adcergebnis As Word
Dim zaehler_encoder As Word
Dim Toggle_rad As Byte
Dim eingabe_encoder As Word
Dim encoder_l_r As Byte
Dim adc_pin As Byte
declare Sub readadc(byval adc_pin as byte)
Config Adc = Single , Prescaler = Auto
Start Adc
Open "comb.2:9600,8,n,1" For Input As #1
Open "comd.6:9600,8,n,1" For Output As #2
waitms 500
Toggle_rad=1
eingabe_encoder=100
adc_pin=0
print #2,"vor"
call readadc(adc_pin)
print #2,"stop"
wait 2
eingabe_encoder=30
adc_pin=1
print #2,"links"
call readadc(adc_pin)
print #2,"stop"
wait 1
eingabe_encoder=30
adc_pin=0
print #2,"rechts"
call readadc(adc_pin)
print #2,"stop"
wait 1
eingabe_encoder=100
adc_pin=1
print #2,"zurueck"
call readadc(adc_pin)
print #2,"stop"
end
sub readadc(byval adc_pin as byte)
zaehler_encoder=0
while zaehler_encoder < eingabe_encoder
Adcergebnis=Getadc(adc_pin)
If Adcergebnis > 500 And Toggle_rad = 1 Then
Incr zaehler_encoder
Toggle_rad = 0
End If
If Adcergebnis < 300 And Toggle_rad = 0 Then
Incr zaehler_encoder
Toggle_rad = 1
End If
wend
end sub
was ist das für ein komisches zusammenspiel?
also so funktioniert das programm einwandfrei, vor,links,rechts,zurück fährt der roboter, bloss wenn ich print text rausnehme fährt er nicht mehr.
verbindung board 2 zu board 1 : pinb.2 zu pind.6, pind.6 zu pinb.2
rx und tx der beiden boards sind nicht beschaltet und es hängt auch nichts dran.
mfg
empfangsprogramm avrboard 2.
$Regfile = "M32def.dat"
$Crystal = 8000000
$HWStack = 32
$SWStack = 32
$FrameSize = 64
$Baud = 19200
Dim M_wert_a As Byte , M_wert_b As Byte
Dim Text As String * 16
Declare Sub Robby_vor()
Declare Sub Robby_zurueck()
Declare Sub Robby_links()
Declare Sub Robby_rechts()
Declare Sub Robby_links_drehen()
Declare Sub Robby_rechts_drehen()
Declare Sub Robby_aus()
Declare Sub L293_pin()
declare sub empfang()
Config Timer1 = Pwm , Pwm = 8 , Compare A Pwm = Clear Up , Compare B Pwm = Clear Up , Prescale = 256
Start Timer1
config int2=rising
On Int2 Int2_int
Enable Interrupts
Enable Int2
Open "comb.2:9600,8,n,1" For Input As #1
Open "comd.6:9600,8,n,1" For Output As #2
M_wert_a = 100
M_wert_b = 100
Call L293_pin()
do
waitms 300
loop
End
Int2_int:
Disable Int2
Enable Interrupts
input #1, text
print text
call empfang()
enable int2
Return
sub empfang()
If Text = "vor" Then
Call Robby_vor()
End If
If Text = "zurueck" Then
Call Robby_zurueck()
End If
If Text = "links" Then
Call Robby_links()
End If
If Text = "rechts" Then
Call Robby_rechts()
End If
If Text = "stop" Then
Call Robby_aus()
End If
end sub
Sub L293_pin()
Ddrc.2 = 1
Ddrc.3 = 1
Ddrc.4 = 1
Ddrc.5 = 1
Ddrd.4 = 1
Ddrd.5 = 1
End Sub
Sub Robby_vor()
Portc.2 = 0
Portc.3 = 1
Portd.5 = 1
Portc.4 = 0
Portc.5 = 1
Portd.4 = 1
Pwm1a = M_wert_a
Pwm1b = M_wert_b
End Sub
Sub Robby_zurueck()
Portc.2 = 1
Portc.3 = 0
Portd.5 = 1
Portc.4 = 1
Portc.5 = 0
Portd.4 = 1
Pwm1a = M_wert_a
Pwm1b = M_wert_b
End Sub
Sub Robby_links()
Portc.2 = 0
Portc.3 = 1
Portd.5 = 1
Portc.4 = 0
Portc.5 = 0
Portd.4 = 0
Pwm1a = M_wert_a
Pwm1b = 0
End Sub
Sub Robby_rechts()
Portc.2 = 0
Portc.3 = 0
Portd.5 = 0
Portc.4 = 0
Portc.5 = 1
Portd.4 = 1
Pwm1a = 0
Pwm1b = M_wert_b
End Sub
Sub Robby_aus()
Portc.2 = 0
Portc.3 = 0
Portd.4 = 0
Portc.4 = 0
Portc.5 = 0
Portd.5 = 0
Pwm1a = 0
Pwm1b = 0
End Sub
Sub Robby_rechts_drehen()
Portc.2 = 1
Portc.3 = 0
Portd.5 = 1
Portc.4 = 0
Portc.5 = 1
Portd.4 = 1
Pwm1a = M_wert_a
Pwm1b = M_wert_b
End Sub
Sub Robby_links_drehen()
Portc.2 = 0
Portc.3 = 1
Portd.5 = 1
Portc.4 = 1
Portc.5 = 0
Portd.4 = 1
Pwm1a = M_wert_a
Pwm1b = M_wert_b
End Sub
sendeprogamm avrboard 1
$Regfile = "M32def.dat"
$Crystal = 8000000
$HWStack = 32
$SWStack = 32
$FrameSize = 64
$Baud = 19200
Dim Adcergebnis As Word
Dim zaehler_encoder As Word
Dim Toggle_rad As Byte
Dim eingabe_encoder As Word
Dim encoder_l_r As Byte
Dim adc_pin As Byte
declare Sub readadc(byval adc_pin as byte)
Config Adc = Single , Prescaler = Auto
Start Adc
Open "comb.2:9600,8,n,1" For Input As #1
Open "comd.6:9600,8,n,1" For Output As #2
waitms 500
Toggle_rad=1
eingabe_encoder=100
adc_pin=0
print #2,"vor"
call readadc(adc_pin)
print #2,"stop"
wait 2
eingabe_encoder=30
adc_pin=1
print #2,"links"
call readadc(adc_pin)
print #2,"stop"
wait 1
eingabe_encoder=30
adc_pin=0
print #2,"rechts"
call readadc(adc_pin)
print #2,"stop"
wait 1
eingabe_encoder=100
adc_pin=1
print #2,"zurueck"
call readadc(adc_pin)
print #2,"stop"
end
sub readadc(byval adc_pin as byte)
zaehler_encoder=0
while zaehler_encoder < eingabe_encoder
Adcergebnis=Getadc(adc_pin)
If Adcergebnis > 500 And Toggle_rad = 1 Then
Incr zaehler_encoder
Toggle_rad = 0
End If
If Adcergebnis < 300 And Toggle_rad = 0 Then
Incr zaehler_encoder
Toggle_rad = 1
End If
wend
end sub