Farnell's Rotary Encoder 733-726


Closed Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    Jul 2005
    Posts
    65

    Default Farnell's Rotary Encoder 733-726

    Hello

    I was looking for a rotary encoder and I found this 733-726, you can download its datasheets from here

    www.farnell.com/datasheets/48122.pdf

    I thought I can post the code I wrote for this encoder here before ordering...

    Please if any body got this kind of rotary encoders, then try this code and tell me if it works or not, also if any one has a suggestion to improve the code, don't hesitate to share....

    @ DEVICE PIC16F84A, HS_OSC, WDT_ON, PWRT_ON, PROTECT_OFF

    DATA $C0,$F9,$A4,$B0,$99,$92,$82,$F8,$80,$90

    Define Osc 4

    TRISA = %00011
    TRISB = 0
    PORTA = 0
    PORTB = 0
    INTCON = 0

    Index Var Byte : Index = 0

    A var PortA.0
    B vAR PortA.1


    ATemp var bit
    BTemp var bit


    Main:

    atemp = a : btemp = b

    if atemp == btemp then
    while a == b : wend
    else
    goto main
    ENDIF


    PAUSE 1
    if atemp <> a AND BteMP == B then VOL_UP ' CW Rotation Checking
    IF ATEMP == A AND BTEMP <> B THEN VOL_DOWN ' CCW Rotation Checking


    ' Indicate the incoming pulses and rotation direction
    ' with a 7-segment display.... Very Nice indeed....
    VOL_UP:
    read Index, PortB
    If index == 10 then
    index = 0
    else
    Index = Index + 1
    endif
    GOTO MAIN

    VOL_DOWN:
    read index, PortB
    If Index == 0 then
    Index = 9
    else
    index = index - 1
    endif
    Goto main

    END

    A seven segmet display is used to allow visual indication of response, I tested this code with a wheel from an old mouse, it has three wires, black, red, and yellow, but results were annoying because of the bad wheel signals, but in essense the code is working fine...as I tried to pulse the inputs with a wire and three fingers...when I squeeze the wheel a little bit, it works very nice

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    i don't know if will be handy but here's a snip of my encoder routine
    Code:
    GetEncoder:
        '
        OldPos = (PORTB & %11000000)>>6 ' get only PORTB<7:6> bits
        NewPos = OldPos 
        
        ' see if encoder has move 
        ' 
        while ((NewPos==0) or (NewPos==3)) 
           NewPos = (PORTB & %11000000)>>6 ' get only PORTB<7:6> bits
        wend
        pause 20 ' debounce delay
     
        ' Get encoder movement
        ' --------------------
        '
        '      Rotary encoder output table (clockWise rotation):
        '      -------------------------------------------------
        '             00
        '             01 between move (half detent)
        '             11
        '             10 between move (half detent)
        '
        '     Using XOR
        '
        '               OldPOS   : 0     0     3     3
        '               NewPos   : 1     2     1     2
        '               movement : CW   CCW   CCW    CW
        '           XOR -------------------------------
        '                          1     2     2     1
        '
        ' So, if NewPos XOR OldPos = 1 => increment
        '        Newpos XOR OldPos = 2 => Decrement    
        '
        Newpos=newpos ^ oldpos 
        select case newpos
    
               case 1
                   Menupointer=menupointer+1
    
               case 2
                   Menupointer=menupointer-1
    
         end select
    Yeah i know, more comments than code but.. i like it
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    Jul 2005
    Posts
    11


    Did you find this post helpful? Yes | No

    Default encoder

    I have used these encoders and still have problems, I tried code supplied on this forum and it still does the same thing, it jumps up by 2 values instead of one ( rotate right one click generates 2 counts ). I do have the board set up still so I will try both code examples and advise.

    Nigel, Queensland, Australia

  4. #4
    Join Date
    Jul 2005
    Posts
    65


    Did you find this post helpful? Yes | No

    Lightbulb

    Hello mister_e

    Thanks for the nice code.... and comments also

    I think I found my way of how to use these evil rotary encoders...

    Now, I don't know how to explain this very well, but I think the code will do..

    Code:
    @ DEVICE PIC16F84A, XT_OSC, PWRT_ON, PROTECT_OFF, WDT_ON

    TRISA = 3
    TRISB = 0

    PORTA = 0
    PORTB = 0

    NEW VAR BYTE
    OLD VAR BYTE
    TEMP VAR BYTE
    DIRECTION VAR BIT

    INIT:
    TEMP = PORTA
    NEW = TEMP & 3 ' PortA<1,0> only required as inputs<B,A>
    START:
    OLD = NEW
    BEGIN:
    TEMP = PORTA ' Read the new value to see if changed
    NEW = TEMP & 3
    IF NEW == OLD THEN BEGIN ' If not changed, keep reading
    DIRECTION = NEW.1 ^ OLD.0 ' XOR left bit of new and right bit of old
    IF DIRECTION = 1 THEN CLOCKWISE

    COUNTERCLOCKWISE:
    '
    '
    GOTO START


    CLOCKWISE:
    '
    '
    GOTO START

    I tested this code with a mouse wheel, and it worked perfectly without any problems, I used 7 segment display to monitor the results. Tomorrow I will order the rotary encoder, and see if it also works as I intended...

    This method prevents double stepping each time the nob is rotated, try it guys, and tell me what is your experience like...
    Last edited by crematory; - 9th September 2005 at 21:50.

  5. #5
    Join Date
    Feb 2003
    Posts
    432


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by wallaby
    I have used these encoders and still have problems, I tried code supplied on this forum and it still does the same thing, it jumps up by 2 values instead of one ( rotate right one click generates 2 counts ). I do have the board set up still so I will try both code examples and advise.

    Nigel, Queensland, Australia
    Hi Nigel,

    I am about to use a rotary encoder for the first time and whilst trying to confirm the pinout with a multimeter I couldnt get any readings across any pins. I then went and found the datasheet and discovered I have bought a high resolution encoder.

    My encoder has 24 detents in common with many others, but many of the encoders have only 6 cycles per revolution so 4 clicks to go through 00,01,11,10

    Mine apparently has 24 cycles per revolution so a single click travels through 00,01,11,10 and back to 00. Basically whenever the encoder is resting on a detent BOTH switches are open. I confirmed this by using LED's and you can see the 4 steps during each click.

    Given that the code above will generate an output count whenever 00 or 11 are presented I guess that using the type of encoder I have will give a count of two for each click.

    Just need to code for that now

    Regards
    Keith

    www.diyha.co.uk
    www.kat5.tv

  6. #6
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default

    keithdoxey, I am the one that supplied Nigel with the code and it works perfectly with a standard encoder, however the encoder you have selected as well as Nigel are ment to be used in low power situations. That is why the encoder seems to be open circuited at rest or in the detented position. As I told Nigel, take the encoder count and divide it by 2 is the easiest way to use these type of "low power" encoders.

    Dave Purola,
    N8NTA

  7. #7
    Join Date
    Feb 2003
    Posts
    432


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Dave
    As I told Nigel, take the encoder count and divide it by 2 is the easiest way to use these type of "low power" encoders.
    Hi Dave,

    Excellent idea. Just because I need a result of 0-63 doesnt meant I cant use an encoder value of 0-126 in steps of two.

    Will give it a try later.

    Thanks
    Keith

    www.diyha.co.uk
    www.kat5.tv

Similar Threads

  1. Quadrature encoder and ASM Interrupts. questions..
    By godfodder in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 17th March 2013, 15:45
  2. Calculate Distance Using Rotary Encoder
    By guanerrr in forum mel PIC BASIC Pro
    Replies: 17
    Last Post: - 4th May 2012, 17:40
  3. Rotary encoder help (not 'counting steps)
    By Elnino in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 26th October 2009, 23:03
  4. encoder wowes
    By wallaby in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 6th December 2005, 22:56
  5. Automotive quality rotary encoder
    By d1camero in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 8th October 2004, 16:46

Members who have read this thread : 2

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