PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : URXC Interrupt löscht Variablen???



EDatabaseError
15.09.2006, 20:09
Ich habe folgenden 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
'-------------------------------------------------------------------------------

Sobald ich nu etwas an den Chip sende wird die variable Axis_raw auf 0 gesetzt. Die IF Abfragen werden ignoriert.
Was stimmt da nicht?

Mfg
Tobi

linux_80
15.09.2006, 20:40
Bin mir jetzt nicht sicher, aber das mit den ERAM Variablen scheint ein Problem zu sein,
Probier mal die Variable erst in einen andere Temp-Variable zu kopieren bevor sie im IF verwendet wird.

Evtl. dauert das schreiben und lesen (vom ERAM) auch nur zu lange, sodass in der ISR das ganze durcheinander kommt, vor allem weils zwei Byte sind !? :-k
Vielleicht mal mit Disable/Enable Interrupts rumprobieren, wenn an den Integervariablen Daten geändert werden, glaub nicht das Bascom das von sich aus macht. :-k

EDatabaseError
15.09.2006, 20:41
ok danke!

mfg
tobi

Vitis
15.09.2006, 22:26
also die Verwendung von

Chr(i) = "#"

ist nicht besonders geschickt, versuchs doch mit

if i = 35

oder besser
select case i:
case 35:
tudas xy
case 36:
tuanderes
case xy: ....... etc.
end select

EDatabaseError
15.09.2006, 22:27
werde ich versuchen :-)