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

Thread: Teensy 4 and 2 Encoder TTL

  1. #1
    Junior Member
    Join Date
    Sep 2019
    Posts
    2

    Teensy 4 and 2 Encoder TTL

    Hi at all,

    I bought the Teensy 4 few days ago and now I have to prototype a board that must read 2 linear encoder (TTL).
    http://www.givimisure.it/download/1_...T_GIVI_ENG.pdf

    I bought also a bidirectional signal converter 3.3 to 5V witch mount a TBX0108
    https://cdn-shop.adafruit.com/datasheets/txb0108.pdf

    I've tried the sample Encoder (inside Teensyduino installer) and works fine a "slow speed", the problem appear when I move fast the linear encoder... some counters are lost.
    I've put a #define ENCODER_OPTIMIZE_INTERRUPTS as mentioned in this tutorial https://www.pjrc.com/teensy/td_libs_Encoder.html and I obtain better result but I always lost some counters.

    If I understand correctly the max frequency of the linear encoder is 500KHz (120meter / min), so 500ns every 90.
    This evening I can connect the oscilloscope and catch the waveform to try to understand and see the signals.

    In the meantime do you have any advice?
    What can I have to check or verify?

    Finally, I read this post https://forum.pjrc.com/threads/57159-encored-T-4-0 and I don't understand if the quadrature encoder signals (QEI) are available on Teensy 4 and supported by the Encoder library.

    Thank you so much, any suggestions will be appreciated.

  2. #2
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    2,544
    AFAIK, the encoder lib does not benefit from the optimized hardware modules inside the T4. It works in the arduino way by attaching interrupts to GPIO pins and digital read operations which introduces latency and requires processing time for each signal ramp which limits the maximum signal frequency.

    If I were you, I'd use either the internal ENC modules (accessible via the XBARIO pins and setting the XBAR registers accordingly) or the eFlexPWM modules which can also do quadrature demodulation and counting in a similar way on their respective FLEXPWMx_PWMy_A and _B pins. Both are well documented in the reference manual with code examples, so that this is your moment to contribute a library to the Teensy ecosystem...

  3. #3
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    4,289
    As @Theremingenieur indicated the T4 has an internal ENC module that can be used. During the beta testing I put together a test sketch. Its not pretty but does work. I am attaching for reference to help you on the path.
    Attached Files Attached Files

  4. #4
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    577
    And here a quick video what you can achieve with the built in decoders (Teensy 3.2) https://www.youtube.com/watch?v=ZLVXQfjfS6Q

  5. #5
    Junior Member
    Join Date
    Sep 2019
    Posts
    2
    First at all, thank you.
    As mentioned above I check the signals with my scope and... They are horrible.

    This is the TTL signals in input at TBX0108
    NewFile3.bmp

    This is the outputs... (3.3V)
    NewFile4.bmp
    ...Under 2V ????

    This is the 3.3 power supply (in yellow) and one encoder channel converted in 3.3V by TBX0108.
    NewFile7.bmp

    I've connected an external 5V power supply to teensy 4 (VIn) and not the USB cable.
    I've connected the 3.3V marked as (250 mA max) as VCCA on this Logic level converter.
    Click image for larger version. 

Name:	TBX0108.jpg 
Views:	3 
Size:	41.0 KB 
ID:	17724
    https://www.robot-italy.com/en/logic...rectional.html

    Do you know why are the 3.3V signals so bad?
    What I missing?

    @Theremingenieur: thank you but I'm no expert so I don't undestard what you mean...
    @mjs513: can I download your example on my Teensy 4? ...and where I have to connect the 4 signals of my 2 linear encoders?

    Thank you.

  6. #6
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    2,544
    I meant the unofficial forum rule: I f there isn’t a library which fits your needs, study the processor’s reference manual, then write the library yourself, and contribute the result here. I gave you just the needed keywords which allow you to easily locate the 3 or 4 needed chapters in the 3000+ pages and >60 chapters manual to save you some searching time.

  7. #7
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    4,289
    That sketch is only setup to run a single quad encoder on pins 2 and 3. It is not a library that you can use for your project. Its something to get you started as you go through the reference manual that @Theremingenieur posted. Again its meant to save you time.

  8. #8
    Junior Member
    Join Date
    Mar 2015
    Posts
    18
    I find these chips generally to be terrible. Adafruit and Sparkfun have not done the world a favor by promoting them so heavily.

    Get yourself a uni-directional level-shifter like a 74LVC2T45 or the old CD4504. It will work rail-to-rail up to many MHz with clean signals and sharp edges.

Posting Permissions

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