HEDS5540 optical encoder


Closed Thread
Results 1 to 24 of 24

Hybrid View

  1. #1
    Join Date
    May 2013
    Location
    australia
    Posts
    2,632


    Did you find this post helpful? Yes | No

    Default Re: HEDS5540 optical encoder

    Thank You Richard for helping me. The your corrected code works, the routine counts up and down when I turn the encoder shaft cw or ccw, but if i mark the shaft starting position and turn on the MCU the reading is zero thats OK and when i slowly turn for example half turn and go back to marked position the encoder reading is not zero but less or more than zero. I think the routine not count correctly the encoder pulses, maybe the encoder send incorrect signals, I dont know
    .

    I tried my setup again more carefully and verified it works ok, several back and forth motions always returns to the zero mark as zero in either direction, so the question is does rbc_int on your chip react to every edge generated by the encoder the same as ioc_int on a 16f1825 / perhaps not
    Warning I'm not a teacher

  2. #2


    Did you find this post helpful? Yes | No

    Default Re: HEDS5540 optical encoder

    Yes, that's the problem. The RBC_INT react with pin RB.0 on port B, because this pin operate the LCD ENABLE pin. If I try to use only portA to operate the LCD (with internal 4MHz oscillator) and on the PORTB pin RB.6 and RB.7 hang only the encoder A and B channel, rest pins configured to output the reading is perfect. Always after turning up and down randomly, slower, quicker etc. when I return to marked starting position the reading is zero. Now, how to solve this problem, how to "tell" to MCU the only pinRB.6 and RB.7 trigger the interrupt, not the entire portB

  3. #3
    Join Date
    May 2013
    Location
    australia
    Posts
    2,632


    Did you find this post helpful? Yes | No

    Default Re: HEDS5540 optical encoder

    "
    Code:
    If I try to use only portA to operate the LCD (with internal 4MHz oscillator) and on the PORTB pin RB.6 and RB.7 hang only the encoder A and B channel, rest pins configured to output the reading is perfect.

    yes , makes sense . unfortunately setting or clearing a bit on a pic port entails a read of that port first , any read of portb clears the mismatch condition state for the rbc interrupt.
    so even though only the bits 4 to 7 that are set as inputs can cause an interrupt on change a write to your "e" pin can cause changes to be missed .
    if it won't keep up with the encoder using the int osc then use an i2c lcd display or a different pic
    Warning I'm not a teacher

  4. #4


    Did you find this post helpful? Yes | No

    Default Re: HEDS5540 optical encoder

    For testing and learning the 16F628A is seems to be OK. But now I try to convert the pulse reading to distance. One full encoder turn generates 1440 pulses. The wheel diameter is 25mm, the circumference is 157mm. I want reading precision to 0,1mm. I try basic math like:
    Code:
    Main_Loop: 
    if Flag = 1 then 
    let counter = (enc_counter/36) * 157 / 4
    Lcdout $fe, 1                    
    lcdout  Dec counter     ; display counter value on LCD
    Flag = 0
    endif
    goto Main_Loop
    But the precision is terrible, can you explain me the right way?
    Last edited by louislouis; - 5th October 2016 at 00:49.

  5. #5
    Join Date
    May 2013
    Location
    australia
    Posts
    2,632


    Did you find this post helpful? Yes | No

    Default Re: HEDS5540 optical encoder

    But the precision is terrible, can you explain me the right way?

    157/1440 = .109 mm per encoder tick

    .109 * 256 * 10 = 279

    distance * 10 = (counts * 279)/256

    to use pbp's higest resolution integer functions

    Code:
    counter = enc_counter */ 279 
    
    lcdout  Dec counter/10 ,".", dec counter//10     ; display counter value on LCD
    problem here is that when enc_counter > 60000 [or thereabouts] the internal 32bit result will overflow and the result will be wrong
    you could look at nbit math


    ps you could also use div32

    Code:
    counter = enc_counter * 1000
    counter =  div32 917
    
    lcdout  Dec counter/10 ,".", dec counter//10     ; display counter value on LCD
    Last edited by richard; - 5th October 2016 at 01:27.
    Warning I'm not a teacher

  6. #6


    Did you find this post helpful? Yes | No

    Default Re: HEDS5540 optical encoder

    Thank You Richard for helping me. That's great, now the "core" of my distance meter works perfectly. Yes, the max. distance what I can measure is near six and a half meter which is enough for me. If I want to measure more than 6,5m simply zeroed the reading and start count from that point. Now I must implement negative reading when I go to opposite direction from zero the reading must be from -1..... to -655,3.
    Your explanation helping me a lot, once again Thank You.

  7. #7


    Did you find this post helpful? Yes | No

    Default Re: HEDS5540 optical encoder

    I finally assembled my distance meter based on rotary optical encoder and precision wheel. But still I have problem with math and precision.
    For example, wheel circumference is 157mm, and when I take a 30 revs the result must be 4710mm, but the MCU calculates only 4708,1mm which is 1,9mm difference. Is there a way to improve the precision?
    I use Richard's math:
    157/1440 = .109 mm per encoder tick
    .109 * 256 * 10 = 279
    distance * 10 = (counts * 279)/256
    Code:
    counter = enc_counter */ 279 
    lcdout  Dec counter/10 ,".", dec counter//10     ; display counter value on LCD
    The precision 0,1mm is enough for me, the max. measurable distance want be 6000mm. I try some change, if I improve the precision to 0.01mm then the max. measurable distance shortened to 600mm and this not enough.
    Last edited by louislouis; - 9th October 2016 at 23:35.

Similar Threads

  1. 2 Beam Optical Pulse Generator
    By WOZZY-2010 in forum Schematics
    Replies: 8
    Last Post: - 6th April 2010, 04:03
  2. USB Optical mouse as motor encoder
    By RodSTAR in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 24th August 2008, 15:09
  3. optical voice link
    By Macgman2000 in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 18th May 2008, 21:11
  4. Using a optical coder
    By debutpic in forum mel PIC BASIC Pro
    Replies: 22
    Last Post: - 16th October 2007, 04:57
  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