Shop OBEX P1 Docs P2 Docs Learn Events
Pololu Optical Encoders for their Mico Motors "Signal Conditioning" question — Parallax Forums

Pololu Optical Encoders for their Mico Motors "Signal Conditioning" question

vanmunchvanmunch Posts: 568
edited 2014-08-08 11:53 in General Discussion
I've been messing around with these really small optical encoders from Polou.
http://www.pololu.com/product/2591

They output the raw analog single that I've been reading using the propeller and the QEDEngine. The sensors are very sensitive to other light sources and I've placed mine in a dark, black enclosure, but I still get goofy readings every once in awhile. It will give me a value of ~31,000 and the motor isn't turning.

They mention that you might want to do some "signal conditioning" to transform it from analog output to digital waveforms. Erich fond one way to do this, but I didn't know if there was a simpler way to convert the sinusoidal waveform to a more binary signal that you normally get from an encoder. Erich's work: USDigitalEncoderTest - Archive [Date 2014.08.04 Time 16.20].ziphttp://www.pololu.com/blog/303/custom-optical-encoder-signal-processing-board-for-the-zumo

I've used this same code with US DIgital's encoders with great success and Parallaxes's motor/encoder combos.

Any ideas for conditioning the signal would be great.

Thanks,

Dave

Comments

  • Martin_HMartin_H Posts: 4,051
    edited 2014-08-05 02:15
    A schmitt trigger is what I've used to do that. They resist transitioning from a 1 or 0 until the signal has spent time at the new state, and won't transition back without the same amount of time. This means that signal glitches are effectively ignored rather than counted as signal transitions.

    In addition the circuit usually requires some kind of pot to control either the LED brightness or detector sensitivity. You then run the motor and count the 1's and 0's while adjusting the pot until you get an equal amount per revolution. In looking at the waveform signals on the Pololu site, they're suggesting you tune the sensitivity by adjusting the position of the reflector relative to the detectors. That will work too, because moving the reflector away effectively decreases the brightness of the LED.
  • vanmunchvanmunch Posts: 568
    edited 2014-08-05 05:47
    Martin_H wrote: »
    A schmitt trigger is what I've used to do that. They resist transitioning from a 1 or 0 until the signal has spent time at the new state, and won't transition back without the same amount of time. This means that signal glitches are effectively ignored rather than counted as signal transitions.

    In addition the circuit usually requires some kind of pot to control either the LED brightness or detector sensitivity. You then run the motor and count the 1's and 0's while adjusting the pot until you get an equal amount per revolution. In looking at the waveform signals on the Pololu site, they're suggesting you tune the sensitivity by adjusting the position of the reflector relative to the detectors. That will work too, because moving the reflector away effectively decreases the brightness of the LED.

    Thanks Martin for your help. I did some searching and found an example of how to do a Schmitt trigger with 2 resistors and two propeller pins here: http://www.parallax.com/downloads/an015-creating-schmitt-triggered-inputs-p8x32a-propeller-microcontroller
    I'm going to give it a try and see how it goes. BTW I can't wait to meet you this week at the Boston Expo! :)

    Dave
  • RobotWorkshopRobotWorkshop Posts: 2,307
    edited 2014-08-05 08:06
    Hello Dave,

    If you don't want to use the extra Propeller pins (and the extra Propeller coding) I would suggest trying an external Schmitt trigger between the optical sensor outputs and your Propeller inputs. That want you can save Propeller I/O pins and can use your existing quadrature code as is. You can get non-inverting one like this:

    http://www.nxp.com/documents/data_sheet/74HC7014.pdf

    Where you'll be able to clean up 6 lines. Just use a single non-inverting Schmitt trigger between each encoder output and the Propeller pin. Since you'd only need 4 of the 6 gates be sure to tie the inputs of the two unused Schmitt triggers either high or low since floating CMOS inputs are bad news...

    Since the non-inverting versions aren't as common I usually use a pair of 74HC14 chips (one for each quadrature encoder) and just run each line through a pair of the inverting Schmitt triggers.

    http://www.ti.com/lit/ds/symlink/sn74hc14.pdf

    http://www.onsemi.com/pub_link/Collateral/MC14584B-D.PDF

    http://makeitlabs.com/files/LED_Board/CD40106BC.pdf

    Robert
  • vanmunchvanmunch Posts: 568
    edited 2014-08-05 09:11
    Hello Dave,

    If you don't want to use the extra Propeller pins (and the extra Propeller coding) I would suggest trying an external Schmitt trigger between the optical sensor outputs and your Propeller inputs. That want you can save Propeller I/O pins and can use your existing quadrature code as is. You can get non-inverting one like this:

    http://www.nxp.com/documents/data_sheet/74HC7014.pdf

    Where you'll be able to clean up 6 lines. Just use a single non-inverting Schmitt trigger between each encoder output and the Propeller pin. Since you'd only need 4 of the 6 gates be sure to tie the inputs of the two unused Schmitt triggers either high or low since floating CMOS inputs are bad news...

    Since the non-inverting versions aren't as common I usually use a pair of 74HC14 chips (one for each quadrature encoder) and just run each line through a pair of the inverting Schmitt triggers.

    http://www.ti.com/lit/ds/symlink/sn74hc14.pdf

    http://www.onsemi.com/pub_link/Collateral/MC14584B-D.PDF

    http://makeitlabs.com/files/LED_Board/CD40106BC.pdf

    Robert

    Hey Robert, the 74HC7014 looks great and I like the idea of just dropping it in and saving the I/O lines. I think I'll buy some of those: http://www.mouser.com/Search/Refine.aspx?Keyword=74HC7014

    It looks like you don't need any external resistors with the 74HC7014, is that correct? You just hook GND and Vcc up and then connect the encoder output to the data input and then the data output to the propeller pin for that encoder channel. I assume the Hysteresis Band is fixed at some predetermined size/ values?

    Thanks for your help!

    Dave
  • GordonMcCombGordonMcComb Posts: 3,366
    edited 2014-08-05 09:52
    That's correct; just connect and go. That said, many triggers trigger at lower voltages, typically under 1 volt (though some at precisely 1/2 VCC, so look around and compare). You need to make sure there is little or no "background" to the output, or you'll always be over the threshold. In cases where the voltage output has insufficient swing, you can also use an analog comparator (typically in DIP packages with 2 or more separate comparator circuits), and set the trip point with a small pot, or two resistors. More parts count, but it's all inexpensive stuff.

    Another option, and one I would recommend for quad optics, are the inexpensive quadrature encoder ICs from US Digital. Last I checked they were about $3.50 each, and one chip handled one encoder. Not only do they condition the inputs, but they level out the quadrature output, making for very nice 90 degree phase square waves. I've used them multiple times. Also last I checked they still didn't have a fully automated shopping cart system. You need to actually call and talk to a live person (I think it's the owner) and order over the phone.
  • RobotWorkshopRobotWorkshop Posts: 2,307
    edited 2014-08-05 10:00
    vanmunch wrote: »
    Hey Robert, the 74HC7014 looks great and I like the idea of just dropping it in and saving the I/O lines. I think I'll buy some of those: http://www.mouser.com/Search/Refine.aspx?Keyword=74HC7014

    It looks like you don't need any external resistors with the 74HC7014, is that correct? You just hook GND and Vcc up and then connect the encoder output to the data input and then the data output to the propeller pin for that encoder channel. I assume the Hysteresis Band is fixed at some predetermined size/ values?

    If you're running the 74HC7014 at 3.3v then you can connect the output from it directly to the Prop pin. If you're worried that you may accidentally load a Prop program that sets those I/O pins to outputs you certainly can use a small resistor between them to ensure the I/O on the Propeller is protected.

    Other than that I would just add a .1 uf cap across the supply leads near the 74HC7014 chip and make sure to tie the inputs of the two unused schmitt triggers either to 3.3v or ground.

    You'll find that those 74HC7014 chips can be useful for interfacing other things as well. I've used those and the 74HC14 chips on the outputs of the prop to interface to 5V devices (that didn't seem to like only 3.3V highs) and also to help drive more chips. Specifically for driving multiple 74HC595 chips. The Propeller would drive one or two ok but often when going up to four of them I had trouble until I added one of these chips inline to condition the signals.

    Hope this helps,

    Robert
  • vanmunchvanmunch Posts: 568
    edited 2014-08-05 10:22
    Gordon, Robert, thanks this helps a lot.

    @Robert I'm going to order a couple of those 74HC7014 and give them a try. Thanks for the tip about the cap and tying down the unused inputs.

    @Gordan I've ordered encoders from US Digital before and they work very well. I'd like to try those ICs. Do you have a link to the encoder IC you were talking about? I couldn't find anything that sounded similar. I was also wondering what you meant by "Background" to the output. I have your most recent book encase you mention it in there.

    Thanks again!

    Dave
  • vanmunchvanmunch Posts: 568
    edited 2014-08-08 05:04
    I received the 74HC7014 chips last night and they worked like a charm, thanks!

    Raw Optical Encoder input with 74HC7014 output (squ wav).jpg



    Dave
  • GordonMcCombGordonMcComb Posts: 3,366
    edited 2014-08-08 09:27
    vanmunch wrote: »
    @Gordan I've ordered encoders from US Digital before and they work very well. I'd like to try those ICs. Do you have a link to the encoder IC you were talking about? I couldn't find anything that sounded similar.

    They have several choices, depending on whether you want SMT or thru-hole, and how you want to handle the up/down part of quadrature. The two options for thru-hole parts are:

    http://www.usdigital.com/products/interfaces/ics/LFLS7183
    http://www.usdigital.com/products/interfaces/ics/LFLS7184

    The difference is how the clocking is used to show direction. I think I've preferred the '184. It has a single clock output and a separate line, high or low, that shows direction. I've used these in (ahem) Arduino Unos where there is a lack of external hardware interrupts. The Uno has only two built into hardware (the AVR chip supports pin change interrupts on any pin, but that's a lot more complexity than readers want to deal with). So, the two hardware interrupts are used for the clocks from the two motor encoders. When one of these pins receives an interrupt, it checks its corresponding pin to note HIGH or LOW, denoting direction.

    A more advanced controller like a Propeller isn't as hamstrung by available external hardware interrupt pins, so you could probably use either flavor of chip to do your bidding.
  • GordonMcCombGordonMcComb Posts: 3,366
    edited 2014-08-08 09:29
    vanmunch wrote: »
    I was also wondering what you meant by "Background" to the output. I have your most recent book encase you mention it in there.

    By "background" I mean how much ambient light is entering the sensor, that would alter its instantaneous voltage. The Pololu encoders incorporate their own resistors for setting LED brightness and phototransistor sensitivity, so everything you do to alter the characteristics of the sensor must be done externally. If you sensor "sees" a lot of ambient light -- something that might happen in a brightly lit room or outdoors -- that could raise (or lower depending on how the phototransistor is wired) the voltage.

    I see the Schmitt trigger point is a healthy 2 volts or so, so I don't think you'll have this particular problem. The LED of the sensor is bright enough, the phototransistor the right sensitivity, to give a decent swing.
  • vanmunchvanmunch Posts: 568
    edited 2014-08-08 11:53
    By "background" I mean how much ambient light is entering the sensor, that would alter its instantaneous voltage. The Pololu encoders incorporate their own resistors for setting LED brightness and phototransistor sensitivity, so everything you do to alter the characteristics of the sensor must be done externally. If you sensor "sees" a lot of ambient light -- something that might happen in a brightly lit room or outdoors -- that could raise (or lower depending on how the phototransistor is wired) the voltage.

    I see the Schmitt trigger point is a healthy 2 volts or so, so I don't think you'll have this particular problem. The LED of the sensor is bright enough, the phototransistor the right sensitivity, to give a decent swing.

    Hey Gordon, thanks. I've printed a body for the robot where the motors and encoders are safely tucked in a black hole with light absorbing tape. During earlier test I found that the ambient light did affect the results. The graph was taken while the assembly was safe and snug in it's hole. :)

    With everything else remaining constant I saw a 10x decrease in the number of "click" counted between the raw single and the processed single. 800-1200 to 80-90

    I'm going to take a look at those US digital boards. They might be really helpful with a different project. Thanks again!

    Dave
Sign In or Register to comment.