+ Post New Thread
Results 1 to 10 of 10
  1. #1
    Newbie level 3
    Points: 359, Level: 4

    Join Date
    Jan 2011
    Posts
    3
    Helped
    0 / 0
    Points
    359
    Level
    4

    speed measurement using optical encoder

    Hi. I have an assignment at faculty to measure speed using incremental optical encoder (someone is using term rotary).
    Have anyone done the similar project maybe? I get 2 analog signals and I use DA converter at begging. I have several questions, at the begging do I have to debounce the signals, or how to measure the frequency of signals (I guess I can't use interrupts). I am using MSP430 microcontroller


    Thanks

  2. #2
    Super Moderator
    Points: 26,044, Level: 39
    andre_teprom's Avatar
    Join Date
    Nov 2006
    Location
    Brazil
    Posts
    7,853
    Helped
    971 / 971
    Points
    26,044
    Level
    39
    Blog Entries
    5

    Re: speed measurement using optical encoder

    Take a look here to inspire you :

    http://www.edaboard.com/thread209847.html

    +++



    •   Alt30th June 2011, 00:13

      advertising

        
       

  3. #3
    Advanced Member level 4
    Points: 6,702, Level: 19
    alexxx's Avatar
    Join Date
    Apr 2011
    Location
    Greece
    Posts
    1,011
    Helped
    278 / 278
    Points
    6,702
    Level
    19
    Blog Entries
    2

    Re: speed measurement using optical encoder

    Quote Originally Posted by mladen
    I guess I can't use interrupts
    On the contrary you should use external interrupt for the encoder. I don't use your MCU so I don't know about this MCU's interrupt handling, but I'm telling you this:
    You must not loose encoder interrupts. Make sure from your program or settings that this interrupt will always be enabled and hence executed.

    So if encoder A will be connected to external interrupt, then if you implement a state machine with A and B states, you will be able to measure not only speed (you can use a dedicated timer for this to measure the time between interrupts), but direction also (from state machine).

    Take a look at the following link and pay attention at the incremental rotary encoder part (the gray coding for clockwise and counter-clockwise are actually the state machine for the two directions):

    Rotary encoder - Wikipedia, the free encyclopedia


    Anoter way is to use latches to make your life easier, but this will make your circuit more expensive.





  4. #4
    Full Member level 1
    Points: 922, Level: 6

    Join Date
    Oct 2010
    Location
    kathmandu,nepal
    Posts
    119
    Helped
    3 / 3
    Points
    922
    Level
    6

    Re: speed measurement using optical encoder

    what help do u want? is it software or hardware help? you can (of course) make frequency counter. I suggest you use A simple OP-AMP like LM324 having 4-QUAD INPUT. It makes you easier to debug the whole process.



    •   Alt30th June 2011, 13:11

      advertising

        
       

  5. #5
    Newbie level 3
    Points: 359, Level: 4

    Join Date
    Jan 2011
    Posts
    3
    Helped
    0 / 0
    Points
    359
    Level
    4

    Re: speed measurement using optical encoder

    I need help for software. I thing that I can't use interrupts because I have to take the signal from encoder to the A/D converter. So my question is do I need do debounce the signal I get from the A/D converter?



  6. #6
    Advanced Member level 4
    Points: 6,702, Level: 19
    alexxx's Avatar
    Join Date
    Apr 2011
    Location
    Greece
    Posts
    1,011
    Helped
    278 / 278
    Points
    6,702
    Level
    19
    Blog Entries
    2

    Re: speed measurement using optical encoder

    Quote Originally Posted by mladens
    I have to take the signal from encoder to the A/D converter
    What does this mean? Encoder produces two digital signals, A and B. Please elaborate or post the circuit.


    Quote Originally Posted by mladens
    do I need do debounce the signal
    Yes, if we are talking about digital signals A and B from the encoder, you could use a non-inverting Schmitt buffer.


    Regards,
    Alexandros



  7. #7
    Newbie level 3
    Points: 359, Level: 4

    Join Date
    Jan 2011
    Posts
    3
    Helped
    0 / 0
    Points
    359
    Level
    4

    Re: speed measurement using optical encoder

    Quote Originally Posted by alexxx View Post
    What does this mean? Encoder produces two digital signals, A and B. Please elaborate or post the circuit.

    Yes, if we are talking about digital signals A and B from the encoder, you could use a non-inverting Schmitt buffer.
    This mean I get analog signal

    I can't use any additional hardware, only software debounce (if I have to, but I don't have experience with optical encoder so I don't know do I need to do this)



  8. #8
    Advanced Member level 4
    Points: 6,702, Level: 19
    alexxx's Avatar
    Join Date
    Apr 2011
    Location
    Greece
    Posts
    1,011
    Helped
    278 / 278
    Points
    6,702
    Level
    19
    Blog Entries
    2

    Re: speed measurement using optical encoder

    Quote Originally Posted by mladens
    This mean I get analog signal

    I can't use any additional hardware, only software debounce
    Maybe your board uses a frequency to voltage conversion.
    Encoder is a fast changing input. You could debounce the analog signal, but I guess you must define zones of operation. For example 0.5-1.5V=low speed, 1.5 to 2.5=medium speed, 2.5 to 3.5=high speed. At the given example, if you counted 1.4V until now and suddenly you see a value of 1.7V, count it for some milliseconds first, and then consider it as a valid state changed (low speed became medium speed). Practically and depending on the application, maybe more zones are needed.
    However, you could first try without debounce to see what happens and if you are not satisfied with the result, then insert the debounce code.


    Hope that helped.



  9. #9
    Super Moderator
    Points: 241,624, Level: 100
    Awards:
    1st Helpful Member

    Join Date
    Jan 2008
    Location
    Bochum, Germany
    Posts
    41,951
    Helped
    12763 / 12763
    Points
    241,624
    Level
    100

    Re: speed measurement using optical encoder

    You should clarify which "analog" signal properties require to connect an AD converter to the encoder interface. As long as the signal swings beyond the VIL and VIH threshold values, it may be connected to digital IOs as well.

    But if you would need to use ADC inputs, it's possible of course. You have to consider the ADC sampling and conversion time, so the maximum speed will be lower than with digital interfaces. Generally, the signals of a quadrature encoder don't need to be necessarily debounced. The decoding scheme involves a correct position count despite of bouncing signals. As you'll notice from th eliterature, a quadrature encoder signal is equivalent to a two bit gray counter, by design, only on eof two channels can bounce at a time, in turn, the counter position can be unsure by one position.

    It should be considered, that some simplified decoder circuits may miss this elementary feature, e.g. decoders that are only processing one signal edge of the encoder. The circuit in post #3 is however working correctly, also with bouncing inputs. But it has the disadavantage of not cointing on each quadrature transition.

    An example of a software quadrature decoder can be found e.g. in this recent thread:
    http://www.edaboard.com/thread216640.html
    Last edited by FvM; 30th June 2011 at 17:57.



    •   Alt30th June 2011, 17:50

      advertising

        
       

  10. #10
    Super Moderator
    Points: 26,044, Level: 39
    andre_teprom's Avatar
    Join Date
    Nov 2006
    Location
    Brazil
    Posts
    7,853
    Helped
    971 / 971
    Points
    26,044
    Level
    39
    Blog Entries
    5

    Re: speed measurement using optical encoder

    The purpose of work is not clear. You want to measure speed or angle ?

    If is only speed, a tachometer counter could be enought, but direction rotation information will be lost.
    However if is angle, should consider Index pin, to resset account and correct some accumulated error, every time turns at position 'zero'.

    PS : Some microcontrolers, like DSPIC30F60xx, have built-in quadrature decoder.

    +++



--[[ ]]--