Jump to content
43oh

Energia millis() and micros() issues


Recommended Posts

I have just managed to upload my first Energia code to the c2000 LaunchPad I have bought about 6 months ago (got a little help on TI forums). BTW, if anyone has issues with that on OS X, I can share my limited experience.

 

So I used this test for millis() and micros() that were not sufficiently precise on MSP430 (micros() would detect only a half millisecond at a time). To my surprise, the faster high end c2000 only has a resolution of 13 ms (that is, 13 000 us). Is that a limitation of the chip(s) or simply some error in Energia's libraries?

 

I get plenty of zeros and a 13 from time to time with the code below, in the middle of the line, so it's not the serial communication that delays reads.

 

Thanks in advance for any help.

 

int size = 80;

unsigned long ms[80];
 
void setup()
{
  Serial.begin(9600);
}
 
void loop()
{
  for(int i = 0; i < size; i++) {
    ms = millis();
    delay(1);
  }
    
  for(int i = 1; i < size; i++) {
    Serial.print(ms - ms[i - 1]);
    Serial.print(" ");
  }
  
  Serial.println();
}
Link to post
Share on other sites

I thought I would try the code from @@Nicu with some other LaunchPads.  I don't have a C2000.  Returning lots of zeros?  Here is what I got on other LaunchPads:

 

FR5969 - mostly 2's with a rare 3

F5529 - 2 about 2/3 of time, and 1 for 1/3 of time

MSP432 - almost always 1 but the rare occasional 2048 or 2049                          <<< this should probably be checked also

CC3200 - always 1

Tiva TM4C123 - always 1

 

By the way, on an Arduino Uno this gives mostly 1s, with an occasional zero and occasional 2.

Link to post
Share on other sites

I thought I would try the code from @@Nicu with some other LaunchPads. I don't have a C2000. Returning lots of zeros? Here is what I got on other LaunchPads:

 

FR5969 - mostly 2's with a rare 3

F5529 - 2 about 2/3 of time, and 1 for 1/3 of time

MSP432 - almost always 1 but the rare occasional 2048 or 2049 <<< this should probably be checked also

CC3200 - always 1

Tiva TM4C123 - always 1

 

By the way, on an Arduino Uno this gives mostly 1s, with an occasional zero and occasional 2.

Definitely something @@energia may want to know about regarding the msp432 glitch...

 

Sent from my Galaxy Note II using Tapatalk

Link to post
Share on other sites
  • 1 month later...

 

I thought I would try the code from @Nicu with some other LaunchPads.  I don't have a C2000.  Returning lots of zeros?  Here is what I got on other LaunchPads:

 

FR5969 - mostly 2's with a rare 3

F5529 - 2 about 2/3 of time, and 1 for 1/3 of time

MSP432 - almost always 1 but the rare occasional 2048 or 2049                          <<< this should probably be checked also

CC3200 - always 1

Tiva TM4C123 - always 1

 

By the way, on an Arduino Uno this gives mostly 1s, with an occasional zero and occasional 2.

UPDATE:  Whatever the problem was for the MSP432 it appears to be fixed in Energia 16.  I always get 1s now, same as CC3200 and TMC123.

Link to post
Share on other sites
  • 3 weeks later...

The millis() function implementation isn't the greatest.  I implemented this the same way other LaunchPads had implemented it using the watchdog timer.  This leaves the main CPU timers free for functions like tone() to use.  The resolution is due to the speed that the watchdog runs at.

 

Can I ask what you're trying to accomplish that you need such precise timing for?  There may be other ways we can meet your timing needs in hardware.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...