Teensy4.0 CPU count reset

Status
Not open for further replies.

kdharbert

Well-known member
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.
 
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?
 
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.
 
It's non-intuitive, but by using unsigned arithmetic, the wrap-around issue can be made to go away.
 
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:
Code:
 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...
Code:
  uint32_t start_time = micros();
  <do your stuff>
   uint32_t delta_time = micros() - start_time;
   Serial.print(delta_time, DEC);
 
Status
Not open for further replies.
Back
Top