PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : Timer läuft ab dem 2. Mal nicht mehr an



xxrider
25.07.2007, 21:37
Hallo,

mein programm benötigt einen timer, der eine variable hochzählt und beim überschreiten eine sprunganweisung machen soll. in dieser anweisung wird der timer derweil abgeschaltet mit disable timer0.
beim nächsten enable timer0 läuft dieser aber nicht mehr an.
woran kann das liegen?

gruß
holger
$regfile = "m32def.dat"

$crystal = 9000000

$baud = 9600

$hwstack = 64
$swstack = 64
$framesize = 64

Portd.5 = 1
Portb.0 = 0

Config Portb = Output
Config Portd.2 = Output 'leds
Config Portd.3 = Output
Config Portd.4 = Output
Config Portd.5 = Input 'taster
Portd.5 = 1
Portd.6 = 1


Config Lcd = 16 * 2
Config Lcdpin = Pin , Db4 = Portc.4 , Db5 = Portc.3 , Db6 = Portc.2 , Db7 = Portc.1 , E = Portc.5 , Rs = Portc.7
Config Lcdbus = 4
Config Lcdmode = Port

Portc.6 = 0 'display rw bei bascom immer 0
Config Portc = Output 'display
Reset Portc.1 'write mode for display
Initlcd
Cursor Off
Cls

Dim A As Word
Dim B As Word

Config Timer0 = Timer , Prescale = 1024 'Konfiguriere Timer0
On Timer0 Interr 'verzweige Bei Timer0 überlauf Abbruch2
Enable Interrupts

Wait 2
Locate 1 , 1
Lcd "Start"
Wait 3

Cls



A = 1
B = 1



Warten:

If A > 1800 Then
Do
Portd.2 = 1
Wait 5
Loop
Else



Program:

Cls
Locate 1 , 1
Lcd "Programm"
Wait 3
Cls

Do
Loop Until Pind.5 = 0

Enable Timer0

Portd.4 = 1
Wait 1
Portd.4 = 0

cls
Locate 1 , 1
Lcd B
Waitms 500
Cls

Waitms 200 'anschalten

Do
Loop Until Pind.6 = 0 Or Pind.5 = 0
If Pind.5 = 0 Then
Goto Abbruch
Else
Waitms 200
Do
Loop Until Pind.6 = 0 Or Pind.5 = 0
If Pind.5 = 0 Then
Goto Abbruch
Else
Waitms 200
Do
Loop Until Pind.6 = 0 Or Pind.5 = 0
If Pind.6 = 0 Then
Goto Abbruch
Else
Waitms 200
Do
Loop Until Pind.6 = 0 Or Pind.5 = 0
If Pind.5 = 0 Then
Goto Abbruch
Else
Waitms 200
Portd.3 = 1
Wait 1
Portd.3 = 0

End If
End If
End If
End If
End If

Goto Program



Abbruch:
B = 1
Portd.3 = 0

Disable Timer0

Locate 1 , 1
Lcd "Fehler:"
Waitms 500
Locate 2 , 1
Lcd "Wartezeit"
Waitms 200
Wait A
A = A + 1
Goto Warten




Interr:
B = B + 1
If B > 100 Then
Goto Abbruch
Else
End If

Return





End

linux_80
25.07.2007, 22:34
Hallo,

mit enable/disable stellt man aber nicht den Timer ab, sondern nur dessen Interruptanforderung, der Timer läuft weiter !

Mit Start/Stop wird er gestartet, und gestoppt.
Gleich am Anfang (Config) macht Bascom automatisch ein Start, da muss es nicht nochmal extra angegeben werden.

PS:
Dann sehe ich gerade Du springst aus der ISR per Goto raus, das ist natürlich tödlich, da musst du dir eine andere Strategie überlegen, eine ISR muss immer bis zum Return kommen, sonst gibts Krautsalat oder so !

xxrider
27.07.2007, 05:54
Danke!
Ich hab deine Infos beachtet und nun geht es!

Gruß
Holger