Encoder rotation calculation


Closed Thread
Results 1 to 2 of 2
  1. #1
    Stefan's Avatar
    Stefan Guest

    Default Encoder rotation calculation

    Greetings, I am new member and this is my first post.
    Please help me how to read encoder speed and direction for my application.

    I am using 24 position rotary encoder, pulled high, connected to ground when active. PIC 16F88
    Variables are : speed , direction

    This is what I want:
    1) If I turn the shaft slowly ( say 1 rpm ) then speed = 1
    2) If I turn the shaft fast ( say 10 rpm ) then speed = 255
    3) The direction will be 1 for clockwise, 0 for ccw rotation

  2. #2
    Join Date
    May 2007
    Posts
    65


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Stefan View Post
    Greetings, I am new member and this is my first post.
    Please help me how to read encoder speed and direction for my application.

    I am using 24 position rotary encoder, pulled high, connected to ground when active. PIC 16F88
    Variables are : speed , direction

    This is what I want:
    1) If I turn the shaft slowly ( say 1 rpm ) then speed = 1
    2) If I turn the shaft fast ( say 10 rpm ) then speed = 255
    3) The direction will be 1 for clockwise, 0 for ccw rotation
    First of all, to get direction, you may have a quadrature encoder [2 light sources, 4 pin interface]
    There are lots of sample codes and discussions about this topic over this forum. you could use them as a base for your creativity.
    One option is to use PULSIN. I haven't used that method.
    Other more powerfull option (I use) is to play with Interrupts to access PIC's hardware Timers. Timers (timer0) works in two modes:
    a) as Timer (T0CS=0). TMR0 variable counts instruction cycles (as time reference) between capture period. Real time depends on OSC & bits settings and crystal speed.
    b) as Counter (T0CS=1). TMR0 variable counts pulse's rising edge (T0SE=0) or falling edge (T0SE=1)

    Read datasheet for the other timer's info.
    One of the most beautifull of this is that this can work in background while you run other code.

    At least that's what I understood from datasheet.
    Last edited by RodSTAR; - 31st October 2007 at 07:41.

Similar Threads

  1. Quadrature encoder and ASM Interrupts. questions..
    By godfodder in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 17th March 2013, 14:45
  2. Instant Int and encoder (Elect. Gearing)
    By boroko in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 29th November 2009, 02:29
  3. encoder HEDL 5540
    By kutsi in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 11th June 2007, 14:00
  4. encoder wowes
    By wallaby in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 6th December 2005, 21:56
  5. Farnell's Rotary Encoder 733-726
    By crematory in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 12th October 2005, 13:51

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