PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : Drehrichtung/Position mit Inkrementalgeber bestimmen



rico65
23.05.2006, 15:41
Ich möchte mit einem einfachen Inkrementalgeber und 2
Lichtschranken jeweils die (Winkel-)Position der Welle
bestimmen (mit Bascom).
Mein Code ist nach ein paar Richtungsänderungen
neben den "Schuhen".
Hat jemand ein Stück Code der funktioniert ? Oder ist das etwa gar
nicht möglich ?
Danke für Hilfe

Sommer
23.05.2006, 16:42
Hi,

da gibt es einen Befehl mit den Namen: ENCODER!

Hier ein Beispiel von MCS Electronics



'-----------------------------------------------------------------------------------------
'name : encoder.bas
'copyright : (c) 1995-2005, MCS Electronics
'purpose : demonstration of encoder function
'micro : Mega48
'suited for demo : yes
'commercial addon needed : no
'An encoder has 2 outputs and a ground
'We connect the outputs to pinb.0 and pinb.1
'You may choose different pins as long as they are at the same PORT
'The pins must be configured to work as input pins
'This function works for all PIN registers
'-----------------------------------------------------------------------------------------

$regfile = "m48def.dat" ' specify the used micro
$crystal = 8000000 ' used crystal frequency
$baud = 19200 ' use baud rate
$hwstack = 32 ' default use 32 for the hardware stack
$swstack = 10 ' default use 10 for the SW stack
$framesize = 40 ' default use 40 for the frame space

Print "Encoder test"
Dim B As Byte
'we have dimmed a byte because we need to maintain the state of the encoder

Portb = &B11 ' activate pull up registers

Do
B = Encoder(pinb.0 , Pinb.1 , Links , Rechts , 1)
' ^--- 1 means wait for change which blocks programflow
' ^--------^---------- labels which are called
' ^-------^---------------------------- port PINs
Print B
Waitms 10
Loop
End

'so while you can choose PINB0 and PINB7,they must be both member of PINB
'this works on all PIN registers

Links:
Print "left rotation"
Return

Rechts:
Print "right rotation"
Return


End

Musst du mal testen ob das besser geht, in der Hilfe sieht das vielversprechend aus!

Bye Ulli

badamtam
23.05.2006, 16:59
Danke! Allerdings wäre ich in erster Linie am Sourcecode einer "händischen" Lösung interessiert. Eigentlich will ich die Geschwindigkeitsberechnung nicht in BASCOM schreiben ; in diesem Forum habe ich nur gepostet, da ich mit einem Beispiel in BASIC am meisten anfangen zu können glaubte.



Hi,

da gibt es einen Befehl mit den Namen: ENCODER!

Hier ein Beispiel von MCS Electronics



'-----------------------------------------------------------------------------------------
'name : encoder.bas
'copyright : (c) 1995-2005, MCS Electronics
'purpose : demonstration of encoder function
'micro : Mega48
'suited for demo : yes
'commercial addon needed : no
'An encoder has 2 outputs and a ground
'We connect the outputs to pinb.0 and pinb.1
'You may choose different pins as long as they are at the same PORT
'The pins must be configured to work as input pins
'This function works for all PIN registers
'-----------------------------------------------------------------------------------------

$regfile = "m48def.dat" ' specify the used micro
$crystal = 8000000 ' used crystal frequency
$baud = 19200 ' use baud rate
$hwstack = 32 ' default use 32 for the hardware stack
$swstack = 10 ' default use 10 for the SW stack
$framesize = 40 ' default use 40 for the frame space

Print "Encoder test"
Dim B As Byte
'we have dimmed a byte because we need to maintain the state of the encoder

Portb = &B11 ' activate pull up registers

Do
B = Encoder(pinb.0 , Pinb.1 , Links , Rechts , 1)
' ^--- 1 means wait for change which blocks programflow
' ^--------^---------- labels which are called
' ^-------^---------------------------- port PINs
Print B
Waitms 10
Loop
End

'so while you can choose PINB0 and PINB7,they must be both member of PINB
'this works on all PIN registers

Links:
Print "left rotation"
Return

Rechts:
Print "right rotation"
Return


End

Musst du mal testen ob das besser geht, in der Hilfe sieht das vielversprechend aus!

Bye Ulli