Teensy 4.0 Main Clock Speed...

Status
Not open for further replies.
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.
 
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 '
 
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
 
Status
Not open for further replies.
Back
Top