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

Thread: Teensy4.0 CPU count reset

  1. #1

    Teensy4.0 CPU count reset

    Teensy 4 goes through it's full CPU count in about 7.15 seconds. I need to reference it in order to fix timing. However, there's a jump when ever the CPU flips. Is there a slower clock I can reference to get around this?

    Also is there a way to reset the CPU count without effecting anything? I might be able to solve the problem by resetting before it can flip.

  2. #2
    Senior Member
    Join Date
    Jul 2020
    Normally one uses timestamp differences to avoid issues with the wrap-around - perhaps this could fix the problem
    in the code you've not posted?

  3. #3
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    micros() lasts longer with 1 instead of 600 million ticks per second. But it takes a bit more time - like 40 cycles to read than the CYCCNT which takes 3 or less to transfer the value.

    Indeed what is being timed for how long and what fashion - update start and check end periods only - or continuous checks from start to end of a process?

    The wrapping of the 32 bit value can be handled depending on use or need.

    Also if micros() is good enough there is a wrapper for with an elapsedMicros variable.

  4. #4
    Senior Member
    Join Date
    Apr 2014
    Here a simple method to extend the cycle counter to 64bit

  5. #5
    Darn...looks like detecting the overflow and accounting for it is the only way.

  6. #6
    Senior Member
    Join Date
    May 2015
    It's non-intuitive, but by using unsigned arithmetic, the wrap-around issue can be made to go away.

  7. #7
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Again don't know how accurate you need. For example is the micros() sufficient?

    if so the elapsedMicros object take care of this for you.

    you can do things like:
     elapsedMicros em;
      em = 0;  // resets to zero.
      <Do your stuff>
      Serial.print((uint32_t)em, DEC);
    And the object takes care of the book keeping for you. But note, you can do similar with just using uint32_t...
      uint32_t start_time = micros();
      <do your stuff>
       uint32_t delta_time = micros() - start_time;
       Serial.print(delta_time, DEC);

Posting Permissions

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