decoding quadrature encoders


Closed Thread
Results 1 to 40 of 94

Hybrid View

  1. #1
    Join Date
    Apr 2011
    Location
    León
    Posts
    5


    Did you find this post helpful? Yes | No

    Lightbulb Re: decoding quadrature encoders

    Quote Originally Posted by mat janssen View Post
    Hallo,
    I completed the programm for testing and it works ok.
    With the & ~ look in the manual it takes the not value of the bit.

    here is the complete source and also the hex file

    'PIC 16F628A test


    @ DEVICE PIC16F628A,INTRC_OSC
    @ DEVICE PIC16F628A,MCLR_OFF
    @ DEVICE PIC16F628A,BOD_OFF
    @ DEVICE PIC16F628A,LVP_OFF
    @ DEVICE PIC16F628A,CPD_OFF
    @ DEVICE PIC16F628A,PROTECT_OFF


    DEFINE OSC 4




    CMCON = 7
    VRCON = 0
    OPTION_REG.7 = 0

    TRISA = %11111111
    TRISB = %00000000


    A_INPUT VAR PORTA.0
    B_INPUT VAR PORTA.1

    HULP1 VAR BIT
    HULP2 VAR BIT

    COUNTER VAR WORD

    Clear

    COUNTER = 128

    START:


    HULP2 = A_INPUT & ~ HULP1 'EVERY POSITIVE GOWING EDGE OF A_INPUT
    HULP1 = A_INPUT 'GIVES A PULSE OF ONE PROGRAMM CYCLE

    IF HULP2 = 1 AND B_INPUT = 1 Then 'MOTOR TURNS RIGHT
    COUNTER = COUNTER + 1
    EndIF

    IF HULP2 = 1 AND B_INPUT = 0 Then 'MOTOR TURNS LEFT
    COUNTER = COUNTER - 1
    EndIF

    PORTB = COUNTER
    GoTo START
    I'm trying to do the example with PIC16f877a but i have problems for example the VRCON = 0 my compiler says it's a bad instruction how can i probe with this pic

    thanks

  2. #2
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,184


    Did you find this post helpful? Yes | No

    Default Re: decoding quadrature encoders

    877A does not have VRCON register. Instead it has CVRCON.

    Look in the P16F877A.inc file in the C:\Program Files\Microchip\MPASM Suite path.

    Also pf of the chip you are using is a must.

    Ioannis

  3. #3
    Join Date
    Apr 2011
    Location
    León
    Posts
    5


    Did you find this post helpful? Yes | No

    Question Re: decoding quadrature encoders

    Hi Ioannis exactly i'm using PIC16f877a i have the same problem that ice i cant see my count on my LCD and i cant see using pbp
    only add my count never sub my count do you know what's my problem?

    i tried all in my hands but i continue with same errors
    My code is:

    Code:
    '****************************************************************
    '*  Name    : UNTITLED.BAS                                      *
    '*  Author  : .                                                            *
    '*  Notice  : Copyright (c) 2011 [Ing..]  *
    '*          : All Rights Reserved                               *
    '*  Date    : 19/04/2011                                        *
    '*  Version : 1.0                                               *
    '*  Notes   :                                                   *
    '*          :                                                   *
    '****************************************************************
    'Parte de configuraciÛn de LCD
    DEFINE LCD_DREG PORTB
    DEFINE LCD_DBIT  4
    DEFINE LCD_RSREG PORTB
    DEFINE LCD_RSBIT 1
    DEFINE LCD_EREG  PORTB
    DEFINE LCD_EBIT  3
    DEFINE OSC 4
    
    contador var byte
    ON INTERRUPT GOTO SUMA
    INTCON.4 = 1
    INTCON.7 = 1
    OPTION_REG.6 = 1  
    CMCON=7
    CVRCON=0
    
    TRISB = %00000101
    CONTADOR = 12
    
    principal:
    lcdout $FE,1,"ENCODER= ",#CONTADOR," VALOR "
    pause 500
    goto principal
    DISABLE
    end
    
    SUMA:
    IF PORTB.0 = 1 THEN
        OPTION_REG.6 = 0
        IF PORTB.2 = 1 THEN
        contador = contador + 1
        ENDIF
    else
        OPTION_REG.6 = 1
        IF PORTB.2 = 1 THEN
        CONTADOR = CONTADOR - 1
        ENDIF
    ENDIF
    INTCON.1 = 0
    RESUME
    ENABLE

  4. #4
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,184


    Did you find this post helpful? Yes | No

    Default Re: decoding quadrature encoders

    After interrupt you reset Option_Reg.6.

    And then never set it again. Is it that what you want?

    Ioannis

  5. #5
    Join Date
    Apr 2011
    Location
    León
    Posts
    5


    Did you find this post helpful? Yes | No

    Question Re: decoding quadrature encoders

    Code:
    ...
    else
        OPTION_REG.6 = 1
        IF PORTB.2 = 1 THEN
        CONTADOR = CONTADOR - 1
        ENDIF
    ENDIF
    INTCON.1 = 0
     OPTION_REG.6 = 0 'Here???
    RESUME
    ENABLE
    My problem is the count never sub only add and add if the encoder turn left add and if the encoder turn right add too that's my problem


    I'm working with
    http://www.bourns.com/data/global/pdfs/pec11.pdf

  6. #6
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,184


    Did you find this post helpful? Yes | No

    Default Re: decoding quadrature encoders


  7. #7
    Join Date
    Apr 2011
    Location
    León
    Posts
    5


    Did you find this post helpful? Yes | No

    Thumbs up Re: decoding quadrature encoders

    Thank you so much Ioannis!!

Similar Threads

  1. Quick thoughts: DT Ints with encoders
    By kevlar129bp in forum mel PIC BASIC Pro
    Replies: 19
    Last Post: - 7th January 2010, 01:01
  2. PMDC SERVO MOTOR WITH quadrature encoder DRIVE ?
    By phoenix_1 in forum Schematics
    Replies: 37
    Last Post: - 22nd November 2009, 19:45
  3. 32-bit Quadrature Counter With Serial Interface
    By precision in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 10th June 2008, 02:49
  4. quad encoders
    By cpayne in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 13th March 2007, 17:49
  5. "momentary" IR decoding
    By sporker in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 20th June 2005, 01:53

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts