Teensy 4 and 2 Encoder TTL

Status
Not open for further replies.

addebito

New member
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_RIGHE_OTTICHE/5_GVS600/ST04_A54_A_GVS600T_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.
 
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... ;)
 
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.
 

Attachments

  • ENC1_test_xbar1.zip
    9.4 KB · Views: 73
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
View attachment NewFile3.bmp

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

This is the 3.3 power supply (in yellow) and one encoder channel converted in 3.3V by TBX0108.
View attachment 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.
TBX0108.jpg
https://www.robot-italy.com/en/logic-level-converter-8-channels-bidirectional.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... :confused:
@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.
 
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.
 
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.
 
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.
 
Status
Not open for further replies.
Back
Top