encoder wowes


Results 1 to 17 of 17

Thread: encoder wowes

Threaded View

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


    Did you find this post helpful? Yes | No

    Default

    wallaby, This is a subroutine I use for the 6 channel repeater voter I designed. The A and B outputs from the rotary encoder are wired to port pins 0 and 1 respectively. The varaible KNOBLIM is used for a maximum rollover count ie(KNOBLIM to 0) and a underflow count ie(0 to KNOBLIM) and this variable can not be greater than 65535. The variable MULTIPLY is to be set for 1,10,100,1000,10000 to be used for incrementing or decrementing individual digits of the variable to be manipulated. The variable UPDOWN can be preloaded with a starting target value before calling the routine. As for the direction of the knob rotation as far as incrementing or decrementing the variable, just switch the A and B input wires of the encoder to adjust which input edge leads the other.

    OFS VAR BYTE 'ENCODER + or - COUNT
    TEMP1 VAR BYTE 'ENCODER SCRATCH VARIABLE
    TEMP2 VAR BYTE 'ENCODER SCRATCH VARIABLE
    KNOBLIM VAR WORD 'UP-DOWN COUNTER LIMIT
    UP_DOWN VAR WORD 'COUNTER PASS VARIABLE
    MULTIPLY VAR BYTE 'KNOB MULTIPLIER FOR SPEED

    '************************************************* ********************
    ENCOD: 'READ ROTARY ENCODER POSITION
    '************************************************* ********************
    TEMP2 = TEMP1 | (PORTD & %00000011)
    LOOKUP TEMP2,[2,3,1,2,1,2,2,3,3,2,2,1,2,1,3,2],OFS
    TEMP1 = (TEMP2 << 2) & %00001100
    UP_DOWN = UP_DOWN + ((OFS * MULTIPLY) - (2 * MULTIPLY))
    IF UP_DOWN = (KNOBLIM + MULTIPLY) THEN UP_DOWN = 0
    IF UP_DOWN > KNOBLIM THEN UP_DOWN = KNOBLIM
    MULTIPLY = 1
    RETURN

    Usage:
    TEMP1 = (PORTD & %00000011) << 2 'only executed once to preload temp1

    MODEX: 'SETUP KNOB TO SELECT WHICH ROUTINE
    UP_DOWN = PROGRAM 'Preset for current porgram
    KNOBLIM = 6 'SET PROGRAM NUMBER SELECTION LIMIT
    GOSUB ENCOD 'READ ENCODER
    PROGRAM = UP_DOWN
    IF OLDPRG <> PROGRAM THEN 'IF THE SAME THEN DON'T RE-DISPLAY
    OLDPRG = PROGRAM
    GOSUB DSPSEL 'IF NEW SELECTION THEN DISPLAY IT
    ENDIF

    Dave Purola,
    N8NTA
    Last edited by Dave; - 14th July 2005 at 18:33.

Similar Threads

  1. Reading incremental encoder interupt
    By RFsolution in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 1st March 2017, 13:50
  2. Quadrature encoder and ASM Interrupts. questions..
    By godfodder in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 17th March 2013, 15:45
  3. Instant Int and encoder (Elect. Gearing)
    By boroko in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 29th November 2009, 03:29
  4. Reset timer / encoder transition
    By DJEE in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 22nd June 2007, 15:37
  5. encoder HEDL 5540
    By kutsi in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 11th June 2007, 15:00

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