millis() almost 1/6 slower?

Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
nateclaflin
 
Posts: 3
Joined: Mon Aug 16, 2021 4:37 pm

millis() almost 1/6 slower?

Post by nateclaflin »

i ported code over from one of my esp8266 projects which ran perfectly on time, but ive found that the millis() are almost interpreted 1/6 the speed. in the example ive found that 150ms equals about 1s, and it appears to be linear so if i set it to 1000ms it takes about 6s to process the light change.

Anyone have any idea why? the CPU is overclocked to 200mhz and i have it compiled for the fastest mode.

Here's the relevant snippits of my code. I've tried a few things like using uint32_t instead of long to record the millis in case it was an issue of memory alignment

Code: Select all

 
               for (;;) {
                    spin_crystal((uint32_t)millis());
                }
and function:

Code: Select all

void spin_crystal(uint32_t global_millis) {
  if (crystal_millis == 0) {
    crystal_millis = global_millis;
  }
	if ((global_millis-crystal_millis) > 150) {
    crystal_millis = global_millis;
		current_crystal_color = (current_crystal_color + 1) % 3;
		for (int i = CRYSTAL_OFFSET; i < MOON_OFFSET; i++) {
				strip1.setPixelColor(i, crystal_colors[(current_crystal_color+i)%3]);
		}
		strip1.show();
	}

User avatar
Franklin97355
 
Posts: 23940
Joined: Mon Apr 21, 2008 2:33 pm

Re: millis() almost 1/6 slower?

Post by Franklin97355 »

What processor are you using?

User avatar
nateclaflin
 
Posts: 3
Joined: Mon Aug 16, 2021 4:37 pm

Re: millis() almost 1/6 slower?

Post by nateclaflin »

franklin97355 wrote:What processor are you using?
it's the itsybitsy m4

User avatar
nateclaflin
 
Posts: 3
Joined: Mon Aug 16, 2021 4:37 pm

Re: millis() almost 1/6 slower?

Post by nateclaflin »

For now, i've worked around this by just using a hardware timer and counters to control flow during different events, but i'm still curious why trying to delay using millis() specifically is just super wrong on this board

Locked
Please be positive and constructive with your questions and comments.

Return to “Itsy Bitsy Boards”