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

Thread: Teensy 4.0 Main Clock Speed...

  1. #1
    Junior Member
    Join Date
    May 2019
    Posts
    12

    Teensy 4.0 Main Clock Speed...

    Hello All,

    I am using a Teensy 4.0 and runing Teensy - Tutorial 1 - Blink code.

    How can I figure out what speed is my MCU running at?
    Is there an easy way?
    Can I change it (let's say 1MHz)?

    Thanks lot,
    Normal.User.

  2. #2
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    11,528
    On Teensy 4 there is a dynamic run time variable :: F_CPU_ACTUAL

    That will return the current speed in Hz. There are various fixed times that can be selected in the IDE during the build. The Teensy will be at that speed on entry to setup().

    There is a way to alter the speed at runtime. If using USB Serial - it functions perhaps as low as 24 MHz. The CPU speed can be made lower.

    Code:
    extern "C" uint32_t set_arm_clock(uint32_t frequency); // required prototype
    
    void setup() {
      while ( !Serial );
      Serial.println("\n" __FILE__ " " __DATE__ " " __TIME__);
    
      if ( F_CPU_ACTUAL >= 600'000'000 )
        set_arm_clock(100'000'000);
    }
    // Fun note the 'apostrophe' as shown above is ignored by the compiler, but makes the string of zeros easier to parse.
    // When used singly like 60'000 however can mess with editor parsing where it tries to find the matching '

  3. #3
    Junior Member
    Join Date
    May 2019
    Posts
    12
    I got it.
    Thanks!

  4. #4
    Junior Member
    Join Date
    May 2020
    Location
    South East England
    Posts
    1
    Hi,
    I'm building a digital frequency meter into a major project and using FreqCount().
    I've progressed as far as reading a frequency OK, but need to make a correction to take account of the Teensy's clock error, I'm reading about 12ppm high.
    (50MHz is displayed as 50.000607 with a 1 sec gate period.)
    Can I adjust the frequency of the clock that underlies the FreqCount() function to trim out the error?
    Regards,
    RichardL

Posting Permissions

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