Forum Rule: Always post complete source code & details to reproduce any issue!
Page 3 of 3 FirstFirst 1 2 3
Results 51 to 59 of 59

Thread: Teensy Quick Reference: Code Examples, Tips and Tricks

  1. #51

  2. #52
    Senior Member pictographer's Avatar
    Join Date
    May 2013
    Location
    San Jose, CA
    Posts
    602
    Dealing with electrical noise in an automotive environment:

    https://forum.pjrc.com/threads/34687...l=1#post105577

  3. #53

  4. #54
    Calling this "CPUspecs();" from setup will show you compile time details on your Teensy:
    Code:
    void CPUspecs() {
      Serial.println();
    #if defined(__MKL26Z64__)
      Serial.println( "CPU is T_LC");
    #elif defined(__MK20DX256__)
      Serial.println( "CPU is T_3.1/3.2");
    #elif defined(__MK20DX128__)
      Serial.println( "CPU is T_3.0");
    #elif defined(__MK64FX512__)
      Serial.println( "CPU is T_3.5");
    #elif defined(__MK66FX1M0__)
      Serial.println( "CPU is T_3.6");
    #endif
      Serial.print( "F_CPU =");   Serial.println( F_CPU );
      Serial.print( "ARDUINO =");   Serial.println( ARDUINO );
      Serial.print( "F_PLL =");   Serial.println( F_PLL );
      Serial.print( "F_BUS =");   Serial.println( F_BUS );
      Serial.print( "F_MEM =");   Serial.println( F_MEM );
      Serial.print( "NVIC_NUM_INTERRUPTS =");   Serial.println( NVIC_NUM_INTERRUPTS );
      Serial.print( "DMA_NUM_CHANNELS =");   Serial.println( DMA_NUM_CHANNELS );
      Serial.print( "CORE_NUM_TOTAL_PINS =");   Serial.println( CORE_NUM_TOTAL_PINS );
      Serial.print( "CORE_NUM_DIGITAL =");   Serial.println( CORE_NUM_DIGITAL );
      Serial.print( "CORE_NUM_INTERRUPT =");   Serial.println( CORE_NUM_INTERRUPT );
      Serial.print( "CORE_NUM_ANALOG =");   Serial.println( CORE_NUM_ANALOG );
      Serial.print( "CORE_NUM_PWM =");   Serial.println( CORE_NUM_PWM );
    }
    Above should be correct - I never had a T_3.0 and apparently never ran it on the T_LC - I made this to watch the T_3.5 and T_3.6.

    This line is also useful to record compile TIME and DATE:
    Code:
      Serial.print(__DATE__);   Serial.print(" -- ");  Serial.println(__TIME__);
    Last edited by defragster; 09-22-2016 at 07:32 AM.

  5. #55
    Moderator MichaelMeissner's Avatar
    Join Date
    Nov 2012
    Location
    Ayer Massachussetts
    Posts
    2,573

    Cool

    Quote Originally Posted by defragster View Post
    This line is also useful to record compile TIME and DATE:
    Code:
      Serial.print(__DATE__);   Serial.print(" -- ");  Serial.println(__TIME__);
    You can simplify this via string pasting at compilation time to:

    Code:
      Serial.print (__DATE__ " --- " __TIME__);
    Basically, adjacent strings are combined together by the compiler to from one single string.

  6. #56
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    16,231
    We also have a special linker symbol for the build time. Unlike these macros (which don't force a rebuild of the file they're in), it's always updated on every build because Arduino passes it as a parameter to the linker command line. But it's UNIX time, so you need mktime() or TimeLib.h to convert to human readable.

  7. #57
    Quote Originally Posted by MichaelMeissner View Post
    You can simplify this via string pasting at compilation time to:

    Code:
      Serial.print (__DATE__ " --- " __TIME__);
    Basically, adjacent strings are combined together by the compiler to from one single string.
    Thanks MichaelMeissner - I finally got around to using this as follows - in setup() after SerialStart( #milis ); is called a programmed wait for Serial to appear is done and a compile signature for the file is the first output.

    #define SerialStart(a) ({Serial.begin(19200); while (!Serial && (millis()< (a))); Serial.print("\n" __DATE__ " --- " __TIME__ " --- " __FILE__ "\n");} )

    used like :: SerialStart( 4000 );

    So setup() just gets one line { if you copy the macro ) that waits a #millis for Serial to come online, and starting a Teensy shows if it was programmed after the last change 3 minutes ago - and a random Teensy on the desk will show with what file and when it was last programmed.

  8. #58
    Senior Member
    Join Date
    Nov 2012
    Location
    Salt Lake City, UT, USA
    Posts
    246
    Thanks everyone, this is all helpful! I have so many versions of test code running at the moment it is nice to see the exact build time, file, and also the CPU details verify settings like clock were correct.

  9. #59
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    16,231

Tags for this Thread

Posting Permissions

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