Hallo Leute,
ich hänge schon den ganzen Tag an einem Problem:
Ich möchte einen Incrementalgeber mit einem Atmel 128 auswerten, doch
die ISR wird ständig aufgerufen ( ich lasse zum test eine 2. var in der ISR nochzählen )
Kann mir bitte jemand helfen
Auf einem ATmega 644 habe ich es schon funktionstüchtig, doch auf dem 128 bekomme ich es einfach nicht gebacken.
vielen dank.
Wie muss ich die Register setzen und initialisieren, damit das funzt ?Code:$regfile = "m128def.dat" $crystal = 16000000 'enter the used clock of your actual microcontroller $baud = 38400 $baud1 = 38400 Open "COM2:" For Binary As #1 'If you are using a module with 16 MHz external, please change the $crystal value to 16000000 'If you use 14,7456 MHz crystal, change value to 14745600 'Einbindung der I2C-Bibliothek $lib "i2c_twi.lbx" '############## '# Interrupts # '############## 'dimension variables Dim New_value As Byte Dim Old_value As Byte Dim Direction As Byte Dim Int45 As Integer Dim Encoder_count As Long Encoder_count = 0 'Set data direction of PORTE 'Inputs = Pe4 , Pe5 Ddre = &B00000000 'Enable internal pull-up resistors on the inputs Pe4,Pe5. 'Porte = &B00000000 'External Interrupt Control Register B - 0 1 -> Any logical change on INTn generates an interrupt request Eicrb = &B00000011 ' für INT 5 und INT4 'Wait that PORTB stabilizes before we enable the pin change interrupt 'External Interrupt Mask Register Eimsk = &B00010000 Eifr.4 = 1 'Eifr.5 = 1 Waitms 10 On Int4 Pcint_isr 'On Int5 Pcint_isr Enable Int4 ' pin change interrupt 'Enable Int5 ' pin change interrupt Enable Interrupts '########################### schleife fürs Hauptprogramm '########################### ' ============================================= ' Interrupt routine Pcint_isr: Incr Int45 'Print "interrupt!" New_value = Pine And &B00110000 'New_value = New_value And &B00110000 Direction = Old_value.0 Xor New_value.1 If Direction = 1 Then Incr Encoder_count Else Decr Encoder_count End If Old_value = New_value ' Clear Pcint flag (Pin Change Interrupt flag) 'Eifr.5 = 1 ' auch schon mit 0 probiert 'Eifr.4 = 1 Return
Lesezeichen