Using a optical coder


Closed Thread
Results 1 to 23 of 23

Hybrid View

  1. #1
    Join Date
    Dec 2005
    Posts
    23


    Did you find this post helpful? Yes | No

    Default

    Hello Picusers

    Now I use an optical coder with 1000 pulses per turn,but the final result is not good,the PIC does not count all the pulses (~ -200 pulses)
    For you it's a problem of time with the routine of the LCD?




    DEFINE OSC 20 'Fréquence du quartz utilisé
    ADCON1=7 'PortA et PortE en numérique

    '-----------------------------------------------------------------

    'Configuration LCD

    DEFINE LCD_DREG PORTB ' LCD o/p on port B
    DEFINE LCD_DBIT 4 ' LCD on lower 4 bits of port B
    DEFINE LCD_RSREG PORTB ' LCD reset on port B
    DEFINE LCD_RSBIT 3 ' LCD reset portB.3
    DEFINE LCD_EREG PORTB ' LCD enable on port B
    DEFINE LCD_EBIT 2 ' LCD output on PortB.2
    DEFINE LCD_BITS 4 ' LCD o/p is 4 bit data
    DEFINE LCD_LINES 2 ' Number of lines on LCD = 2
    DEFINE LCD_COMMANDUS 1500
    '-------------------------------------------------------------------

    'Configuration des registres

    TRISB = %00000011 ' Port B en sortie sauf B1 et B0
    OPTION_REG = %01000000 ' Config registre
    INTCON = %10010000 ' Config registre

    '----------------------------------------------------------------------

    'Déclarations des variables

    Pulse_Rev VAR WORD ' Pulses par Rev
    Pulse_Rev = 0

    '-----------------------------------------------------------------------------



    On Interrupt Goto ISR ' Si appui sur le BP saut en "ISR"

    Main:

    Lcdout$fe,1
    Lcdout #Pulse_Rev," pulses" 'Affiche valeur variable incrément
    pause 1
    goto Main
    Disable 'interdit toute interruption

    '-------------------------------------------------------------------------------

    'Routine d'interruption + comptage

    ISR:


    Pulse_Rev = Pulse_Rev +1 'Incrémente de 1 la valeur de la variable
    INTCON.1 = 0 'Remet le flag d'interruptio à 0
    Resume 'fin de l'interruption
    Enable 'Autorise à nouveau une interruption



    End

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


    Did you find this post helpful? Yes | No

    Default

    How fast is the encoder turning?

    Even in assembler there is a limit in the speed a PIC can respond.

    As a suggestion, try to put the LCD commands inside your ISR handler. If they are executed within the main, lot of time is wasted with no reason. If you don't move the encoder, LCD will still be accessed.

    Ioannis

  3. #3
    Join Date
    Dec 2005
    Posts
    23


    Did you find this post helpful? Yes | No

    Default

    Ioannis

    Speed max 6 turn sec --> 6 KHz

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


    Did you find this post helpful? Yes | No

    Default

    Hmm, I think it is very fast for the PIC to respond and also display to LCD. I guess that you might try use second PIC to display and get the data through a fast connection either parallel (PIC to PIC with 8 bit ports) or serial the fastest possible. This way the main PIC will have all the time to read the encoder and send the data to the second PIC or terminal device.

    Also the first PIC should run as fast as you can, 20MHz xtal, or in assembly. I don't have the time to do the math right now to calculate how fast it has to run.

    Ioannis

  5. #5
    Join Date
    Aug 2003
    Location
    Northern California
    Posts
    14


    Did you find this post helpful? Yes | No

    Default Optical Encoder - Shumatech

    Greetings,

    Scott Shumate of Shumatech http://www.shumatech.com has designed a 3 axis Digital ReadOut for lathes and mills based on a single PIC microcontroller.

    Full documentation is available on his web site and he sells bare circuit boards at very reasonable prices.

    The Shumatech DRO has advanced features such as bolt hole patterns, tool offsets and RPM.

    The Shumatech DRO will work with Chinese linear scales and / or rotary encoders simultaneously.

    I bought the circuit board from Shumatech and built my 3 axis DRO for about $125 in parts which is a tremendous savings when comparable DROs cost $1,200+.

    My Shumatech DRO:

    http://users.rcn.com/seiths/projects...s/RPM_DRO.html

    http://users.rcn.com/seiths/projects...s/RPM_DRO.html

    I had started designing a PIC based DRO for my milling machine when I discovered the Shumatech DRO.

    I abandoned the design, as it didn't make sense for me to attempt to reinvent a DRO when an excellent advanced featured DRO was available for the cost of a circuit board and parts.

    Ned

  6. #6
    Join Date
    Dec 2005
    Posts
    23


    Did you find this post helpful? Yes | No

    Default Optical codeur ,another questions

    Hello everyone

    Currently I have one quadrature optical coder and my code works fine (increase and reduction according to the sense of rotation)

    I have two questions

    1) I want to increase the resolution (x4) of the optical codeur while decoding the fronts high and low of two channels A and B (see the picture in blue)

    2) When I start the code if I decrease immediately the value displayed is 65535 65534.9 65534.8 etc....
    but I will want -0.1 -0.2 -0.3 etc

    Do you have an idea to begin?
    Attached Images Attached Images  

Similar Threads

  1. 2 Beam Optical Pulse Generator
    By WOZZY-2010 in forum Schematics
    Replies: 8
    Last Post: - 6th April 2010, 04:03
  2. Home made optical rencoder issues
    By Elnino in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 27th November 2009, 22:17
  3. USB Optical mouse as motor encoder
    By RodSTAR in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 24th August 2008, 15:09
  4. optical voice link
    By Macgman2000 in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 18th May 2008, 21:11
  5. Using the optical sensor from a ball mouse
    By lsteele in forum General
    Replies: 5
    Last Post: - 5th September 2007, 16:45

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