Ich habe folgenden Code:
Sobald ich nu etwas an den Chip sende wird die variable Axis_raw auf 0 gesetzt. Die IF Abfragen werden ignoriert.Code:'------------------------------------------------------------------------------- ' Filename : QuadrDec_1.0.bas ' Purpose : Quadrature Decoder/Counter and Display ' Author : Ger langezaal ' Date : 5 April 2002 ' Compiler : BASCOM-AVR Rev. 1.11.6.5 ' '------------------------------------------------------------------------------- ' ' Algorithm: ' Interrupt on both edges of phase A ' Test phase B in ISR ' When phase B <> phase A then decrement counter ' When phase B = phase A then increment counter ' Convert counter value to displacment units ' Format value in string and display ' '------------------------------------------------------------------------------- ' ' Setup for AT90S2313-10 ' ' INT0 edge is set to rising edge ' INT1 edge is set to falling edge ' Encoder phase A to INT0 and INT1 (PD2 and PD3) ' Encoder phase B to PD4 ' Pushbutton between Portd.5 and GND (display zero) ' LCD at PortB ' ' Example for PROXXON KT150 XY table: ' Displacement/rev = 2 mm ' Encoder resolution = 20 pulses/rev ' Interrupt on both pulse edges = 40 interrupts/rev ' Dial resolution: 2 mm / 40 = 0.05 mm ' The optical encoder came from a used mouse (two available) ' '------------------------------------------------------------------------------- ' ' Options/Compiler/Chip: ' HW Stack 48 ' Soft Stack 8 ' Framesize 16 ' '------------------------------------------------------------------------------- ' $regfile = "m32def.dat" $crystal = 16000000 '10 MHz $baud = 9600 Dim Axis_raw As Integer 'optical pulse counter Dim Axis_save As Eram Integer 'counter in eeprom Dim I As Byte 'helpvar for udr Dim Stopp As Bit Dim Sending As Bit Config Portd = Input Portd = 255 'enable Portd pullup's Phase_a Alias Pind.2 'INT0 also connected to Pind.3 = INT1 Phase_b Alias Pind.6 '---[ Set Interrupt logic ]----------------------------------------------------- Mcucr = &B00001011 'set interrupt edges On Int0 Phase_a_edge 'ISR on rising edge On Int1 Phase_a_edge 'ISR on falling edge On Urxc Communication Enable Int0 Enable Int1 Enable Urxc Enable Interrupts '---[ Initialization ]---------------------------------------------------------- Stopp = 0 Axis_raw = 0 Sending = 1 If Axis_raw <> Axis_save Then ' Axis_raw = Axis_save End If '---[ Main program loop ]------------------------------------------------------- Do If Sending = 1 Then Print "{" ; Axis_raw ; "}"; Waitms 100 Loop '------------------------------------------------------------------------------- End '---[ Interrupt Service Routine ]----------------------------------------------- Phase_a_edge: 'Interrupt on rising and falling edge If Phase_b <> Phase_a Then 'test phase B Decr Axis_raw 'CCW Else Incr Axis_raw 'CW End If If Stopp = 0 Then If Axis_raw =< 0 Then Print "!" Stopp = 1 End If End If If Stopp = 1 Then If Axis_raw > 0 Then Stopp = 0 Return Communication: I = Udr If Chr(i) = "#" Then Axis_raw = 0 If Chr(i) = "$" Then Axis_save = Axis_raw If Chr(i) = "^" Then Sending = 1 If Chr(i) = "°" Then Sending = 0 Return '-------------------------------------------------------------------------------
Was stimmt da nicht?
Mfg
Tobi







Zitieren

Lesezeichen