Hallo, ich habe einen kleinen Code geschrieben (das meiste kopiert), der aber leider nicht funktioniert. Ich glaube das etwas mit der Timerbrechnung nicht stimmt. Also angeschlossen werden fünf Servos und mittels eines Interrups angesteuert. Der soll ja alles 20ms schalten. Könnt ihr bitte mal drüberschauen, was da nicht passt? Wenn ich ein Servo anschließe, dreht es ein paar schritte in eine Richtung weiter und macht nichts mehr. Es fährt definitiv nicht in die Mitte! DANKE Lg Peter
1 | $regfile "m32def.dat" |
2 | $crystal = 8000000 |
3 | $hwstack = 64 |
4 | $swstack = 64 |
5 | $framesize = 64 |
6 | |
7 | Config Pinc.1 = Output 'LCD |
8 | Config Pinc.0 = Output 'LCD |
9 | Config Pind.4 = Output 'LCD |
10 | Config Pind.5 = Output 'LCD |
11 | Config Pind.6 = Output 'LCD |
12 | Config Pind.7 = Output 'LCD |
13 | Config Pind.2 = Input 'Signal Eingang |
14 | |
15 | Config Pina.7 = Output |
16 | Config Pinc.4 = Output |
17 | Config Pinc.5 = Output |
18 | Config Pinc.6 = Output |
19 | Config Pinc.7 = Output |
20 | |
21 | |
22 | Config Lcdpin = Pin , Db4 = Portd.4 , Db5 = Portd.7 , Db6 = Portd.5 , Db7 = Portd.6 , E = Portc.0 , Rs = Portc.1 |
23 | Config Lcd = 20 * 2 |
24 | Cursor Off |
25 | |
26 | Config Timer1 = Timer , Prescale = 8 'timer für servos |
27 | Enable Timer1 |
28 | Timer1 = 45536 |
29 | |
30 | Portc.4 = 0 'hier hängt servo1 |
31 | Portc.5 = 0 'hier hängt servo2 |
32 | Portc.6 = 0 'hier hängt servo3 |
33 | Portc.7 = 0 'hier hängt servo4 |
34 | Porta.7 = 0 'hier hängt servo4 |
35 | |
36 | On Timer1 Servoirq |
37 | Enable Interrupts |
38 | |
39 | Dim Servo(5) As Word |
40 | Dim Kanal As Byte |
41 | Kanal = 0 |
42 | |
43 | Do |
44 | |
45 | Servo(1) = 45535 'Mitte |
46 | Servo(2) = 45535 'Mitte |
47 | Servo(3) = 45535 'Mitte |
48 | Servo(4) = 45535 'Mitte |
49 | Servo(5) = 45535 'Mitte |
50 | |
51 | |
52 | Loop |
53 | End |
54 | |
55 | Servoirq: |
56 | If Kanal = 0 Then |
57 | If Portc.4 = 0 Then 'wenn port low |
58 | Timer1 = Servo(1) 'dann timer auf entsprechende verzögerung |
59 | Portc.4 = 1 'und port anschalten |
60 | Else 'das hier passiert erst bei dem darauf folgenden interrupt |
61 | Portc.4 = 0 'dann port wieder ausschalten |
62 | Incr Kanal 'und den nächsten kanal bearbeiten |
63 | End If |
64 | End If |
65 | If Kanal = 1 Then |
66 | If Portc.5 = 0 Then |
67 | Timer1 = Servo(2) |
68 | Portc.5 = 1 |
69 | Else |
70 | Portc.5 = 0 |
71 | Incr Kanal |
72 | End If |
73 | End If |
74 | If Kanal = 2 Then |
75 | If Portc.6 = 0 Then |
76 | Timer1 = Servo(3) |
77 | Portc.6 = 1 |
78 | Else |
79 | Portc.6 = 0 |
80 | Incr Kanal |
81 | End If |
82 | End If |
83 | If Kanal = 3 Then |
84 | If Portc.7 = 0 Then |
85 | Timer1 = Servo(4) |
86 | Portc.7 = 1 |
87 | Else |
88 | Portc.7 = 0 |
89 | Incr Kanal |
90 | End If |
91 | End If |
92 | If Kanal = 4 Then |
93 | If Porta.7 = 0 Then |
94 | Timer1 = Servo(5) |
95 | Porta.7 = 1 |
96 | Else |
97 | Porta.7 = 0 |
98 | Incr Kanal |
99 | End If |
100 | End If |
101 | |
102 | |
103 | If Kanal = 4 Then |
104 | Timer1 = 55536 '10ms pause damit ich auch 20ms komme |
105 | Kanal = 0 |
106 | End If |
107 | Return |