- LiFePO4 Speicher Test         
Ergebnis 1 bis 3 von 3

Thema: Drehrichtung/Position mit Inkrementalgeber bestimmen

  1. #1
    Benutzer Stammmitglied
    Registriert seit
    11.05.2006
    Beiträge
    33

    Drehrichtung/Position mit Inkrementalgeber bestimmen

    Anzeige

    Praxistest und DIY Projekte
    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

  2. #2
    Erfahrener Benutzer Roboter-Spezialist
    Registriert seit
    06.08.2004
    Beiträge
    378
    Hi,

    da gibt es einen Befehl mit den Namen: ENCODER!

    Hier ein Beispiel von MCS Electronics


    Code:
    '-----------------------------------------------------------------------------------------
    '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

  3. #3
    Benutzer Stammmitglied
    Registriert seit
    07.01.2006
    Beiträge
    46
    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.


    Zitat Zitat von Sommer
    Hi,

    da gibt es einen Befehl mit den Namen: ENCODER!

    Hier ein Beispiel von MCS Electronics


    Code:
    '-----------------------------------------------------------------------------------------
    '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

Berechtigungen

  • Neue Themen erstellen: Nein
  • Themen beantworten: Nein
  • Anhänge hochladen: Nein
  • Beiträge bearbeiten: Nein
  •  

Solar Speicher und Akkus Tests