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

  • 3 Comments sorted by Date Added Votes
  • microcontrollerusermicrocontrolleruser Posts: 1,170
    edited December 6 Vote Up0Vote Down
    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
    
    Failure is not an option...it's bundled with the software.
  • search "quadrature". There is tons of stuff on the forum.
    Re-inventing the wheel is not a waste of time if, when you are done, you understand why it is round.
Sign In or Register to comment.