rocketman123
27.01.2008, 15:12
Hallo,
ich hab gerade zwei servos bekommen und möchte einen kleinen Roboterarm basteln. ich hab jetzt ein Programm geschrieben mit dem ich die Position der Arme mit dem Poti über den analogeingang des atmega8 steuern kann.
leider bringt mir bascom eine Fehlermeldung. weiss jemand eine lösung???
Wenn ich die hälfte des Programms des zweiten servos lösche funktionierts.
Gibts da ne andere möglichkeit sowas zu programmieren
AD1 erster Servo, AD zweiter Servo
Unterteilung der 180° in ca.5°
$regfile "m8def.dat"
$crystal = 1000000
Dim Ad As Word
Dim Ad1 As Word
Config Portb = Output
Config Adc = Single , Prescaler = Auto , Reference = Avcc
Start Adc
Do
Ad1 = Getadc(1)
If Ad1 <= 32 Then
Portb.1 = 1
Waitus 600
PortB.1 = 0
Waitus 20000
Elseif Ad1 > 32 And Ad1 <= 64 Then
PortB.1 = 1
Waitus 656
PortB.1 = 0
Waitus 20000
Elseif Ad1 > 64 And Ad1 <= 96 Then
PortB.1 = 1
Waitus 712
PortB.1 = 0
Waitus 20000
Elseif Ad1 > 96 And Ad1 <= 128 Then
PortB.1 = 1
Waitus 768
PortB.1 = 0
Waitus 20000
Elseif Ad1 > 128 And Ad1 <= 160 Then
PortB.1 = 1
Waitus 824
PortB.1 = 0
Waitus 20000
Elseif Ad1 > 160 And Ad1 <= 192 Then
PortB.1 = 1
Waitus 880
PortB.1 = 0
Waitus 20000
Elseif Ad1 > 192 And Ad1 <= 224 Then
PortB.1 = 1
Waitus 936
PortB.1 = 0
Waitus 20000
Elseif Ad1 > 224 And Ad1 <= 256 Then
PortB.1 = 1
Waitus 992
PortB.1 = 0
Waitus 20000
Elseif Ad1 > 256 And Ad1 <= 288 Then
PortB.1 = 1
Waitus 1048
PortB.1 = 0
Waitus 20000
Elseif Ad1 > 288 And Ad1 <= 320 Then
PortB.1 = 1
Waitus 1104
PortB.1 = 0
Waitus 20000
Elseif Ad1 > 320 And Ad1 <= 352 Then
PortB.1 = 1
Waitus 1160
PortB.1 = 0
Waitus 20000
Elseif Ad1 > 352 And Ad1 <= 384 Then
PortB.1 = 1
Waitus 1216
PortB.1 = 0
Waitus 20000
Elseif Ad1 > 384 And Ad1 <= 416 Then
PortB.1 = 1
Waitus 1272
PortB.1 = 0
Waitus 20000
Elseif Ad1 > 416 And Ad1 <= 448 Then
PortB.1 = 1
Waitus 1328
PortB.1 = 0
Waitus 20000
Elseif Ad1 > 448 And Ad1 <= 480 Then
PortB.1 = 1
Waitus 1384
PortB.1 = 0
Waitus 20000
Elseif Ad1 > 480 And Ad1 <= 512 Then
PortB.1 = 1
Waitus 1440
PortB.1 = 0
Waitus 20000
Elseif Ad1 > 512 And Ad1 <= 544 Then
PortB.1 = 1
Waitus 1496
PortB.1 = 0
Waitus 20000
Elseif Ad1 > 544 And Ad1 <= 576 Then
PortB.1 = 1
Waitus 1552
PortB.1 = 0
Waitus 20000
Elseif Ad1 > 576 And Ad1 <= 608 Then
PortB.1 = 1
Waitus 1608
PortB.1 = 0
Waitus 20000
Elseif Ad1 > 608 And Ad1 <= 640 Then
PortB.1 = 1
Waitus 1664
PortB.1 = 0
Waitus 20000
Elseif Ad1 > 640 And Ad1 <= 672 Then
PortB.1 = 1
Waitus 1720
PortB.1 = 0
Waitus 20000
Elseif Ad1 > 672 And Ad1 <= 704 Then
PortB.1 = 1
Waitus 1776
PortB.1 = 0
Waitus 20000
Elseif Ad1 > 704 And Ad1 <= 736 Then
PortB.1 = 1
Waitus 1832
PortB.1 = 0
Waitus 20000
Elseif Ad1 > 736 And Ad1 <= 768 Then
PortB.1 = 1
Waitus 1888
PortB.1 = 0
Waitus 20000
Elseif Ad1 > 768 And Ad1 <= 800 Then
PortB.1 = 1
Waitus 1944
PortB.1 = 0
Waitus 20000
Elseif Ad1 > 800 And Ad1 <= 832 Then
PortB.1 = 1
Waitus 2000
PortB.1 = 0
Waitus 20000
Elseif Ad1 > 832 And Ad1 <= 864 Then
PortB.1 = 1
Waitus 2056
PortB.1 = 0
Waitus 20000
Elseif Ad1 > 864 And Ad1 <= 896 Then
PortB.1 = 1
Waitus 2168
PortB.1 = 0
Waitus 20000
Elseif Ad1 > 896 And Ad1 <= 928 Then
PortB.1 = 1
Waitus 2224
PortB.1 = 0
Waitus 20000
Elseif Ad1 > 928 And Ad1 <= 960 Then
PortB.1 = 1
Waitus 2280
PortB.1 = 0
Waitus 20000
Elseif Ad1 > 960 And Ad1 <= 992 Then
PortB.1 = 1
Waitus 2336
PortB.1 = 0
Waitus 20000
Elseif Ad1 > 992 And Ad1 <= 1024 Then
PortB.1 = 1
Waitus 2392
PortB.1 = 0
Waitus 20000
End If
Ad = Getadc(0)
If Ad <= 32 Then
Portb.2 = 1
Waitus 600
Portb.2 = 0
Waitus 20000
Elseif Ad > 32 And Ad <= 64 Then
Portb.2 = 1
Waitus 656
Portb.2 = 0
Waitus 20000
Elseif Ad > 64 And Ad <= 96 Then
Portb.2 = 1
Waitus 712
Portb.2 = 0
Waitus 20000
Elseif Ad > 96 And Ad <= 128 Then
Portb.2 = 1
Waitus 768
Portb.2 = 0
Waitus 20000
Elseif Ad > 128 And Ad <= 160 Then
Portb.2 = 1
Waitus 824
Portb.2 = 0
Waitus 20000
Elseif Ad > 160 And Ad <= 192 Then
Portb.2 = 1
Waitus 880
Portb.2 = 0
Waitus 20000
Elseif Ad > 192 And Ad <= 224 Then
Portb.2 = 1
Waitus 936
Portb.2 = 0
Waitus 20000
Elseif Ad > 224 And Ad <= 256 Then
Portb.2 = 1
Waitus 992
Portb.2 = 0
Waitus 20000
Elseif Ad > 256 And Ad <= 288 Then
Portb.2 = 1
Waitus 1048
Portb.2 = 0
Waitus 20000
Elseif Ad > 288 And Ad <= 320 Then
Portb.2 = 1
Waitus 1104
Portb.2 = 0
Waitus 20000
Elseif Ad > 320 And Ad <= 352 Then
Portb.2 = 1
Waitus 1160
Portb.2 = 0
Waitus 20000
Elseif Ad > 352 And Ad <= 384 Then
Portb.2 = 1
Waitus 1216
Portb.2 = 0
Waitus 20000
Elseif Ad > 384 And Ad <= 416 Then
Portb.2 = 1
Waitus 1272
Portb.2 = 0
Waitus 20000
Elseif Ad > 416 And Ad <= 448 Then
Portb.2 = 1
Waitus 1328
Portb.2 = 0
Waitus 20000
Elseif Ad > 448 And Ad <= 480 Then
Portb.2 = 1
Waitus 1384
Portb.2 = 0
Waitus 20000
Elseif Ad > 480 And Ad <= 512 Then
Portb.2 = 1
Waitus 1440
Portb.2 = 0
Waitus 20000
Elseif Ad > 512 And Ad <= 544 Then
Portb.2 = 1
Waitus 1496
Portb.2 = 0
Waitus 20000
Elseif Ad > 544 And Ad <= 576 Then
Portb.2 = 1
Waitus 1552
Portb.2 = 0
Waitus 20000
Elseif Ad > 576 And Ad <= 608 Then
Portb.2 = 1
Waitus 1608
Portb.2 = 0
Waitus 20000
Elseif Ad > 608 And Ad <= 640 Then
Portb.2 = 1
Waitus 1664
Portb.2 = 0
Waitus 20000
Elseif Ad > 640 And Ad <= 672 Then
Portb.2 = 1
Waitus 1720
Portb.2 = 0
Waitus 20000
Elseif Ad > 672 And Ad <= 704 Then
Portb.2 = 1
Waitus 1776
Portb.2 = 0
Waitus 20000
Elseif Ad > 704 And Ad <= 736 Then
Portb.2 = 1
Waitus 1832
Portb.2 = 0
Waitus 20000
Elseif Ad > 736 And Ad <= 768 Then
Portb.2 = 1
Waitus 1888
Portb.2 = 0
Waitus 20000
Elseif Ad > 768 And Ad <= 800 Then
Portb.2 = 1
Waitus 1944
Portb.2 = 0
Waitus 20000
Elseif Ad > 800 And Ad <= 832 Then
Portb.2 = 1
Waitus 2000
Portb.2 = 0
Waitus 20000
Elseif Ad > 832 And Ad <= 864 Then
Portb.2 = 1
Waitus 2056
Portb.2 = 0
Waitus 20000
Elseif Ad > 864 And Ad <= 896 Then
Portb.2 = 1
Waitus 2168
Portb.2 = 0
Waitus 20000
Elseif Ad > 896 And Ad <= 928 Then
Portb.2 = 1
Waitus 2224
Portb.2 = 0
Waitus 20000
Elseif Ad > 928 And Ad <= 960 Then
Portb.2 = 1
Waitus 2280
Portb.2 = 0
Waitus 20000
Elseif Ad > 960 And Ad <= 992 Then
Portb.2 = 1
Waitus 2336
Portb.2 = 0
Waitus 20000
Elseif Ad > 992 And Ad <= 1024 Then
Portb.2 = 1
Waitus 2392
Portb.2 = 0
Waitus 20000
End If
Loop
schon mal danke
mfg
ich hab gerade zwei servos bekommen und möchte einen kleinen Roboterarm basteln. ich hab jetzt ein Programm geschrieben mit dem ich die Position der Arme mit dem Poti über den analogeingang des atmega8 steuern kann.
leider bringt mir bascom eine Fehlermeldung. weiss jemand eine lösung???
Wenn ich die hälfte des Programms des zweiten servos lösche funktionierts.
Gibts da ne andere möglichkeit sowas zu programmieren
AD1 erster Servo, AD zweiter Servo
Unterteilung der 180° in ca.5°
$regfile "m8def.dat"
$crystal = 1000000
Dim Ad As Word
Dim Ad1 As Word
Config Portb = Output
Config Adc = Single , Prescaler = Auto , Reference = Avcc
Start Adc
Do
Ad1 = Getadc(1)
If Ad1 <= 32 Then
Portb.1 = 1
Waitus 600
PortB.1 = 0
Waitus 20000
Elseif Ad1 > 32 And Ad1 <= 64 Then
PortB.1 = 1
Waitus 656
PortB.1 = 0
Waitus 20000
Elseif Ad1 > 64 And Ad1 <= 96 Then
PortB.1 = 1
Waitus 712
PortB.1 = 0
Waitus 20000
Elseif Ad1 > 96 And Ad1 <= 128 Then
PortB.1 = 1
Waitus 768
PortB.1 = 0
Waitus 20000
Elseif Ad1 > 128 And Ad1 <= 160 Then
PortB.1 = 1
Waitus 824
PortB.1 = 0
Waitus 20000
Elseif Ad1 > 160 And Ad1 <= 192 Then
PortB.1 = 1
Waitus 880
PortB.1 = 0
Waitus 20000
Elseif Ad1 > 192 And Ad1 <= 224 Then
PortB.1 = 1
Waitus 936
PortB.1 = 0
Waitus 20000
Elseif Ad1 > 224 And Ad1 <= 256 Then
PortB.1 = 1
Waitus 992
PortB.1 = 0
Waitus 20000
Elseif Ad1 > 256 And Ad1 <= 288 Then
PortB.1 = 1
Waitus 1048
PortB.1 = 0
Waitus 20000
Elseif Ad1 > 288 And Ad1 <= 320 Then
PortB.1 = 1
Waitus 1104
PortB.1 = 0
Waitus 20000
Elseif Ad1 > 320 And Ad1 <= 352 Then
PortB.1 = 1
Waitus 1160
PortB.1 = 0
Waitus 20000
Elseif Ad1 > 352 And Ad1 <= 384 Then
PortB.1 = 1
Waitus 1216
PortB.1 = 0
Waitus 20000
Elseif Ad1 > 384 And Ad1 <= 416 Then
PortB.1 = 1
Waitus 1272
PortB.1 = 0
Waitus 20000
Elseif Ad1 > 416 And Ad1 <= 448 Then
PortB.1 = 1
Waitus 1328
PortB.1 = 0
Waitus 20000
Elseif Ad1 > 448 And Ad1 <= 480 Then
PortB.1 = 1
Waitus 1384
PortB.1 = 0
Waitus 20000
Elseif Ad1 > 480 And Ad1 <= 512 Then
PortB.1 = 1
Waitus 1440
PortB.1 = 0
Waitus 20000
Elseif Ad1 > 512 And Ad1 <= 544 Then
PortB.1 = 1
Waitus 1496
PortB.1 = 0
Waitus 20000
Elseif Ad1 > 544 And Ad1 <= 576 Then
PortB.1 = 1
Waitus 1552
PortB.1 = 0
Waitus 20000
Elseif Ad1 > 576 And Ad1 <= 608 Then
PortB.1 = 1
Waitus 1608
PortB.1 = 0
Waitus 20000
Elseif Ad1 > 608 And Ad1 <= 640 Then
PortB.1 = 1
Waitus 1664
PortB.1 = 0
Waitus 20000
Elseif Ad1 > 640 And Ad1 <= 672 Then
PortB.1 = 1
Waitus 1720
PortB.1 = 0
Waitus 20000
Elseif Ad1 > 672 And Ad1 <= 704 Then
PortB.1 = 1
Waitus 1776
PortB.1 = 0
Waitus 20000
Elseif Ad1 > 704 And Ad1 <= 736 Then
PortB.1 = 1
Waitus 1832
PortB.1 = 0
Waitus 20000
Elseif Ad1 > 736 And Ad1 <= 768 Then
PortB.1 = 1
Waitus 1888
PortB.1 = 0
Waitus 20000
Elseif Ad1 > 768 And Ad1 <= 800 Then
PortB.1 = 1
Waitus 1944
PortB.1 = 0
Waitus 20000
Elseif Ad1 > 800 And Ad1 <= 832 Then
PortB.1 = 1
Waitus 2000
PortB.1 = 0
Waitus 20000
Elseif Ad1 > 832 And Ad1 <= 864 Then
PortB.1 = 1
Waitus 2056
PortB.1 = 0
Waitus 20000
Elseif Ad1 > 864 And Ad1 <= 896 Then
PortB.1 = 1
Waitus 2168
PortB.1 = 0
Waitus 20000
Elseif Ad1 > 896 And Ad1 <= 928 Then
PortB.1 = 1
Waitus 2224
PortB.1 = 0
Waitus 20000
Elseif Ad1 > 928 And Ad1 <= 960 Then
PortB.1 = 1
Waitus 2280
PortB.1 = 0
Waitus 20000
Elseif Ad1 > 960 And Ad1 <= 992 Then
PortB.1 = 1
Waitus 2336
PortB.1 = 0
Waitus 20000
Elseif Ad1 > 992 And Ad1 <= 1024 Then
PortB.1 = 1
Waitus 2392
PortB.1 = 0
Waitus 20000
End If
Ad = Getadc(0)
If Ad <= 32 Then
Portb.2 = 1
Waitus 600
Portb.2 = 0
Waitus 20000
Elseif Ad > 32 And Ad <= 64 Then
Portb.2 = 1
Waitus 656
Portb.2 = 0
Waitus 20000
Elseif Ad > 64 And Ad <= 96 Then
Portb.2 = 1
Waitus 712
Portb.2 = 0
Waitus 20000
Elseif Ad > 96 And Ad <= 128 Then
Portb.2 = 1
Waitus 768
Portb.2 = 0
Waitus 20000
Elseif Ad > 128 And Ad <= 160 Then
Portb.2 = 1
Waitus 824
Portb.2 = 0
Waitus 20000
Elseif Ad > 160 And Ad <= 192 Then
Portb.2 = 1
Waitus 880
Portb.2 = 0
Waitus 20000
Elseif Ad > 192 And Ad <= 224 Then
Portb.2 = 1
Waitus 936
Portb.2 = 0
Waitus 20000
Elseif Ad > 224 And Ad <= 256 Then
Portb.2 = 1
Waitus 992
Portb.2 = 0
Waitus 20000
Elseif Ad > 256 And Ad <= 288 Then
Portb.2 = 1
Waitus 1048
Portb.2 = 0
Waitus 20000
Elseif Ad > 288 And Ad <= 320 Then
Portb.2 = 1
Waitus 1104
Portb.2 = 0
Waitus 20000
Elseif Ad > 320 And Ad <= 352 Then
Portb.2 = 1
Waitus 1160
Portb.2 = 0
Waitus 20000
Elseif Ad > 352 And Ad <= 384 Then
Portb.2 = 1
Waitus 1216
Portb.2 = 0
Waitus 20000
Elseif Ad > 384 And Ad <= 416 Then
Portb.2 = 1
Waitus 1272
Portb.2 = 0
Waitus 20000
Elseif Ad > 416 And Ad <= 448 Then
Portb.2 = 1
Waitus 1328
Portb.2 = 0
Waitus 20000
Elseif Ad > 448 And Ad <= 480 Then
Portb.2 = 1
Waitus 1384
Portb.2 = 0
Waitus 20000
Elseif Ad > 480 And Ad <= 512 Then
Portb.2 = 1
Waitus 1440
Portb.2 = 0
Waitus 20000
Elseif Ad > 512 And Ad <= 544 Then
Portb.2 = 1
Waitus 1496
Portb.2 = 0
Waitus 20000
Elseif Ad > 544 And Ad <= 576 Then
Portb.2 = 1
Waitus 1552
Portb.2 = 0
Waitus 20000
Elseif Ad > 576 And Ad <= 608 Then
Portb.2 = 1
Waitus 1608
Portb.2 = 0
Waitus 20000
Elseif Ad > 608 And Ad <= 640 Then
Portb.2 = 1
Waitus 1664
Portb.2 = 0
Waitus 20000
Elseif Ad > 640 And Ad <= 672 Then
Portb.2 = 1
Waitus 1720
Portb.2 = 0
Waitus 20000
Elseif Ad > 672 And Ad <= 704 Then
Portb.2 = 1
Waitus 1776
Portb.2 = 0
Waitus 20000
Elseif Ad > 704 And Ad <= 736 Then
Portb.2 = 1
Waitus 1832
Portb.2 = 0
Waitus 20000
Elseif Ad > 736 And Ad <= 768 Then
Portb.2 = 1
Waitus 1888
Portb.2 = 0
Waitus 20000
Elseif Ad > 768 And Ad <= 800 Then
Portb.2 = 1
Waitus 1944
Portb.2 = 0
Waitus 20000
Elseif Ad > 800 And Ad <= 832 Then
Portb.2 = 1
Waitus 2000
Portb.2 = 0
Waitus 20000
Elseif Ad > 832 And Ad <= 864 Then
Portb.2 = 1
Waitus 2056
Portb.2 = 0
Waitus 20000
Elseif Ad > 864 And Ad <= 896 Then
Portb.2 = 1
Waitus 2168
Portb.2 = 0
Waitus 20000
Elseif Ad > 896 And Ad <= 928 Then
Portb.2 = 1
Waitus 2224
Portb.2 = 0
Waitus 20000
Elseif Ad > 928 And Ad <= 960 Then
Portb.2 = 1
Waitus 2280
Portb.2 = 0
Waitus 20000
Elseif Ad > 960 And Ad <= 992 Then
Portb.2 = 1
Waitus 2336
Portb.2 = 0
Waitus 20000
Elseif Ad > 992 And Ad <= 1024 Then
Portb.2 = 1
Waitus 2392
Portb.2 = 0
Waitus 20000
End If
Loop
schon mal danke
mfg