Hallo,
ich bin gerade dabei beim Bau einer PWM Schaltung mit ATMega 8 als
Steurung. Das Programm sieht so aus.
1 | $regfile "m8adef.dat"
|
2 | $crystal = 1000000
|
3 |
|
4 | Config Portb.1 = Output
|
5 |
|
6 | Config Timer1 = Pwm , Pwm = 8 , Compare A Pwm = Clear Up , Prescale = 1
|
7 |
|
8 | Compare1a = 1
|
9 |
|
10 | Config Portd.0 = Input
|
11 | Config Portd.1 = Input
|
12 |
|
13 | Do
|
14 |
|
15 | If Pind.0 = 0 Then
|
16 | Compare1a = Compare1a + 1
|
17 | If Compare1a > 255 Then Compare1a = 255
|
18 | Waitms 200
|
19 | End If
|
20 | If Pind.1 = 0 Then
|
21 | Compare1a = Compare1a - 1
|
22 | If Compare1a < 1 Then Compare1a = 1
|
23 | Waitms 200
|
24 | End If
|
25 |
|
26 | Loop
|
Das Problem ist, das wenn ich an Portd.0 ein Dauerhaftes Signal habe,
und der Wert 255 ereicht hat, das er wieder bei 1 anfängt.
Umgekehrt wenn ich zurück gehe und ich bei 1 angelange, bleibt er dann
auch bei eins und wechselt nicht wieder zu 255.
Nun, suche ich den passenden Befehl, dass wenn Compare1a über 255
ist, das es nicht weiter geht.
Danke für Antworten!