Created
May 21, 2020 01:48
-
-
Save kamilion/6b7cdd9b19618ec7f5eca588b7a1fc57 to your computer and use it in GitHub Desktop.
t4clockspeed.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Clock speed changes | |
* Lifted from: | |
* https://forum.pjrc.com/threads/57444-How-to-change-clock-speed-on-Teensy-4-0?p=214257&viewfull=1#post214257 | |
*/ | |
#if defined(__IMXRT1062__) | |
extern "C" uint32_t set_arm_clock(uint32_t frequency); | |
#endif | |
uint32_t count, prior_count; | |
uint32_t prior_msec; | |
uint32_t count_per_second; | |
bool flip = true; | |
void setup() { | |
#if defined(__IMXRT1062__) | |
set_arm_clock(24000000); | |
#endif | |
Serial.begin(1000000); // edit for highest baud your board can use | |
while (!Serial) ; | |
#if defined(__IMXRT1062__) | |
//set_arm_clock(24000000); | |
Serial.print("F_CPU_ACTUAL="); | |
Serial.println(F_CPU_ACTUAL); | |
#endif | |
count = 10000000; // starting with 8 digits gives consistent chars/line | |
prior_count = count; | |
count_per_second = 0; | |
prior_msec = millis(); | |
pinMode( LED_BUILTIN, OUTPUT ); | |
digitalWriteFast( LED_BUILTIN, flip ); | |
} | |
void loop() { | |
while (1) { | |
Serial.print(" >count="); | |
Serial.print(count); | |
Serial.print(", lines/s="); | |
Serial.print(count_per_second); | |
if ( !(count % 4) ) { | |
Serial.print(' '); | |
Serial.println(millis() / 1000); | |
} | |
count = count + 1; | |
uint32_t msec = millis(); | |
if (msec - prior_msec > 1000) { | |
flip = !flip; | |
digitalWriteFast( LED_BUILTIN, flip ); | |
if ( !Serial ) { | |
delay( 50 ); | |
flip = !flip; | |
digitalWriteFast( LED_BUILTIN, flip ); | |
} | |
prior_msec = prior_msec + 1000; | |
count_per_second = count - prior_count; | |
prior_count = count; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment