Forum Rule: Always post complete source code & details to reproduce any issue!
Page 4 of 4 FirstFirst ... 2 3 4
Results 76 to 86 of 86

Thread: Hardware Quadrature Code for Teensy 3.x

  1. #76
    Junior Member
    Join Date
    Apr 2018
    Posts
    2
    I have had a look at the code by TLB, and I am quite puzzled by the fact that the addresses of the registers that are set up do not match the addresses as specified in the memory map from the K20 reference manual.

    All the adresses seem to be off by 0x1000 compared to the datasheet (or kinetis.h for that matter...).

    What am I missing here?
    Last edited by polwel; 04-10-2018 at 08:37 PM. Reason: typos

  2. #77
    Junior Member
    Join Date
    Apr 2018
    Posts
    2
    OK, nevermind, I had been looking at FTM0 in the reference instead of FTM1... D'oh.


  3. #78
    I'm new to the Arduino IDE.
    What is the best way to install the five files by tlb for use in the IDE?

  4. #79
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    2,381
    The programs attached are:

    QuadDecode.h, QuadDecode_def.h - the important ones. Code to utilize the hardware quadrature decode channels on Teensy3.x

    main.cpp - an example of use. As I mentioned, it is templated, and I did not Arduinofy it, so this shows how to use the templates.

    GenEncoder.h, GenEncoder.cpp - program that generates simulated encoder signals for debug and development.


    That means that you do not forcibly have to include all 5 files.

    As tlb wrote, he did not "Arduinofy" it. That means that you can use the example file main.cpp as inspiration and documentation to create your own .ino sketch based on that. You'd have to copy QuadDecode.h and QuadDecode_def.h in your sketch folder and using #include tags to use their functions in the .ino file.

  5. #80
    Theremingenieur,
    Thanks, got it.

  6. #81
    Junior Member
    Join Date
    Sep 2018
    Posts
    2
    I feel like this is a silly question but I don't see a way to download tlb's attached files... Where can I find them?

  7. #82
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    2,381
    In the very first post of this thread. Depending on your browser and OS, these files are either opened or downloaded when you click on them. In case they open, just copy/paste the content in new tabs with identical names in the Arduino IDE

  8. #83
    Junior Member
    Join Date
    Sep 2018
    Posts
    2
    Ahhh, for some reason on my laptop the list of files wasn't showing but I see them now.

  9. #84
    Junior Member
    Join Date
    Sep 2017
    Posts
    9
    Quote Originally Posted by BrianC View Post
    Hi TLB,

    For 4x count mode, 4 counts are made per pulse (low, rising, high, falling)
    For 2x count mode, 2 counts are made per pulse (low, high)
    For 1x count mdoe, 1 count is made per pulse (just the high I believe).

    The encoder library is in 4x count mode https://www.pjrc.com/teensy/td_libs_Encoder.html
    Is there any way to set 2x or 1x mode when using the Encoder library?

    Id like to reduce the amount of times the interrupts are triggered and would be okay with resolution being lowered.

    Thanks

  10. #85
    Junior Member
    Join Date
    Nov 2015
    Posts
    15
    Sorry for the necro. This is a great library, but there's one catch - tlb uses pointers and non-template functions in the headers.

    If you try to include the library in your sketch and into another library (e.g. trying to allow a communications library to use encoder data), you'll get a pile of multiple definition errors from the linker (despite the compile guards and even a #pragma once). It's a particularly tricky thing to debug if you haven't worked much with template classes.

    I separated out those non-template parts into its own cpp. I'm uploading it here in case it helps someone else with the same problem.

    I haven't changed anything except the arrangement of the code in files.

    I also added an arduino sketch showing example use of the library (but not the encoder simulator).

    QuadDecode.zip
    Attached Files Attached Files

  11. #86
    Senior Member xxxajk's Avatar
    Join Date
    Nov 2013
    Location
    Buffalo, NY USA
    Posts
    521
    It is worth noting that C++ templates are actually considered a separate language. I try to avoid them when possible.
    Sometimes they make sense, though, and in some instances I have found that templates can produce smaller code footprints.
    No idea on why, but it is an observation of mine.

Posting Permissions

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