Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 8 of 8

Thread: T4 w/ Encoder library differential signal question.

  1. #1
    Junior Member
    Join Date
    Jan 2020
    Posts
    7

    T4 w/ Encoder library differential signal question.

    Hello all.

    I recently purchased a Teensy 4.0 with the intent to use it with Paul's encoder library to track the position of an optical linear encoder. This seems to work really well while manually pushing the encoder back and forth on the scale. When I hook a motor up to a belt drive system to move a robot (using the linear encoder for position feedback) I get runaway counts from the encoder. I assume this is noise generation from the motor as it only happens when the motor is energized.

    I've read that quadrature encoders can have a differential signal to elliminate these false pulses due to noise. My linear encoder has A, B, /A and /B outputs and I'm wondering if the encoder library supports this or if the T4's hardware support for encoders can with some other library.

    Thanks for your time.

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    22,756
    You need special hardware to correctly receive those differential signals. Software alone can't give you the noise rejection your want.

    While it might be possible to use Teensy's analog comparators, this really should be done with a proper differential receiver chip. Those chips have special circuitry for a "wide common mode range" at their inputs, which is the key to rejecting noise in harsh environments and giving you a cleanly received signal.

    As a first guess without knowing anything about the specific encoder you have, I'd look at RS485 chips like MAX3483. These chips both transmit and receive, but you can just wire the transmitter enable low so it doesn't ever try to transmit. Teensy 4.0 does not have 5V tolerant inputs, so you want to get one of those chips which is rated to run on 3.3V, or otherwise has a feature to send a 3.3V output signal. Or if you get a 5V one, plan on using resistors to reduce its 5V output signal to approx 3V.

  3. #3
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    5,628
    As added FYI. The T4 HW Quad Encoder does have a glitch filter that gives you some leeway for false signals. For more info on the Quad encoder you can check chapter 55 of the IMXRT1062 Reference Manual. A couple of examples in the lib give examples of using the filter settings:
    Code:
    		/* Filter for PHASEA, PHASEB, INDEX and HOME. */
    		/* Input Filter Sample Count. This value should be chosen to reduce the probability of noisy samples causing an incorrect transition to be recognized. The value represent the number of consecutive samples that must agree prior to the input filter accepting an  input transition. A value of 0x0 represents 3 samples. A value of 0x7 represents 10 samples. The Available range is 0 - 7. */
    		uint16_t filterCount; 
    
    		/* Input Filter Sample Period. This value should be set such that the sampling period is larger than the period of the expected noise. This value represents the sampling period (in IPBus clock cycles) of the decoder input signals.	The available range is 0 - 255. */
    		uint16_t filterSamplePeriod;


    However, with that said if you really have runaway counts you will probably have to do what was suggested in post #2. I have used several encoders on robots including ones built into the motors themselves without an issue. I did see a couple places of using capacitors across the motor terminal terminals:
    Code:
    You should always put a capacitor across the motor terminals even if your circuit is not affected, because brush arcing creates rf noise that can interfere with other equipment (eg. AM radios). The usual recommendation is to install two 0.1uF ceramic capacitors, one connected from each motor terminal to the case. This 'grounds' the case to rf without the danger of having an exposed DC connection.
    ref: https://electronics.stackexchange.co...dc-motor-noise. This is usually for 12v type electric motors.

  4. #4
    Junior Member
    Join Date
    Jan 2020
    Posts
    7
    Quote Originally Posted by PaulStoffregen View Post
    As a first guess without knowing anything about the specific encoder you have, I'd look at RS485 chips like MAX3483.
    Here is the encoder with relevant wire connections:

    Reeson Optical Linear Encoder

    Click image for larger version. 

Name:	encoder pinout.jpg 
Views:	17 
Size:	78.8 KB 
ID:	18849

    I am currently using it with the TTL wiring but I'm assuming I will have to move to RS-422. The MAX3483 appears to be able to communicate with this standard and I've ordered a couple. The encoder operates on 5V and I've been using a 5v to 3.3v level shifter for the inputs into the T4 but MAX3483 chip has 3.3v outputs and tolerates 5v inputs so I think I can remove those. I'm not an electronics expert though, and I'm not sure how to wire this chip between the encoder and the T4. Actually, I'm not sure how to wire the encoder to the MAX3483 chip. Do I need multiple chips for each channel?

    I'm reading the datasheet for the MAX3483 and I'm getting pretty confused. Pointers to more documentation or examples would be greatly appreciated.

  5. #5
    Junior Member
    Join Date
    Jan 2020
    Posts
    7
    After some more research it looks like i'm going to try using an MC3486N RS-422 line receiver. From my understanding it should take the A, /A, B, /B, and Z, /Z signals then do the differential comparison and output A, B, Z signals which I can send through a 5v to 3.3V signal shifter and on to the T4. I guess now I wait for the chip to arrive.

    If anyone has anything else to offer while I wait, I'm all ears

  6. #6
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    22,756
    MC3486 should also work. It requires 85 mA current, almost as much as Teensy 4.0 running at 600 MHz, so if you're running the whole thing on USB power make sure you're plugged into a PC or powered hub. Together with Teensy, this will add up to more than unpowered hubs can provide.

    Of course be careful not to drive any Teensy 4.0 pin beyond 3.3V. That MC3486 is an ancient bipolar TTL logic part that probably won't output the full 5V at logic high, so if you convert to 3.3V using resistors you may need to fiddle a bit to get the right ratio.

  7. #7
    Junior Member
    Join Date
    Jan 2020
    Posts
    7
    So, quick update. The MCD3486 seems to work pretty well. Paired this with a CD74HC4050E level shifter to convert to 3.3v signals. So far no random noise issues with the motor energized.

  8. #8
    Junior Member
    Join Date
    Jan 2020
    Posts
    7
    I should also mention that I've powered the chips from an alternate 5v power supply (with a 3.3v regulator for the 3.3v parts). If I want to power the teensy from this power supply, I just cut the pads between VIN and VUSB right?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •