Shop OBEX P1 Docs P2 Docs Learn Events
Quadrature Encoders — Parallax Forums

Quadrature Encoders

Hi everyone, I'm trying to figure out what is a basic code to test if the 36-position encoders I ordered from parallax work. However since i'm fairly new to coding, i'm struggling to understand how to do it. Anyone can help? Im using the green board of education.

Thanks

Comments

  • microcontrollerusermicrocontrolleruser Posts: 1,194
    edited 2018-12-06 16:37
    Hi

    What you have is part of the Arlo robot.

    Here is a linkto the robot.

    You have to look in documentation for robot to find some code you can adapt.

    https://www.parallax.com/news/2016-05-05/introducing-arlo-complete-robot-system-take-project-based-learning-next-stage-robot
  • This is PropBasic but it's self-explanatory and shows how the decode logic actually works.

    Chan_A and Chan_B are constants for the inputs.

    Just ignore the Wrlong stuff.



    
    
    'Decide where to start
    If Chan_A = 1 And
        Chan_B = 1 Then
        Goto A1B1
    Endif
    
    If Chan_A = 0 And
        Chan_B = 0 Then
        Goto A0B0
    Endif
    
    If Chan_A = 1 And
        Chan_B = 0 Then
        Goto A1B0
    Endif
    
    If Chan_A = 0 And
        Chan_B = 1 Then
        Goto A0B1
    Endif
    
    'Keep hopping between these labels 
      
     A1B1:
     If Chan_A = 0 Then
       Dec Counter
       Wrlong HubCTR,Counter
       Goto A0B1
     Elseif Chan_B = 0 Then
       Inc Counter
       Wrlong HubCTR,Counter
       Goto A1B0
     Endif
     Goto A1B1
     
     A0B0:
     If Chan_A = 1 Then
       Dec Counter
       Wrlong HubCTR,Counter
       Goto A1B0
     Elseif Chan_B = 1 Then
       Inc Counter
       Wrlong HubCTR,Counter
       Goto A0B1
     Endif
     Goto A0B0
     
     A1B0:
     If Chan_A = 0 Then
       Inc Counter
       Wrlong HubCTR,Counter
       Goto A0B0
     Elseif Chan_B = 1 Then
       Dec Counter
       Wrlong HubCTR,Counter
       Goto A1B1
     Endif
     Goto A1B0
     
     A0B1:
     If Chan_A = 1 Then
       Inc Counter
       Wrlong HubCTR,Counter
       Goto A1B1
     Elseif Chan_B = 0 Then
       Dec Counter
       Wrlong HubCTR,Counter
       Goto A0B0
     Endif
     Goto A0B1
    End
    
  • search "quadrature". There is tons of stuff on the forum.
Sign In or Register to comment.