Sign in to follow this  
Followers 0
Nicu

Energia millis() and micros() issues

10 posts in this topic

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();
}
Fmilburn likes this

Share this post


Link to post
Share on other sites

At a low level, the MCU has to get the value from the timer, then move that value into the memory location defined by the variable and counter. This takes some time to do, so probably is why you're seeing the time discrepancies you are.

Share this post


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.

Share this post


Link to post
Share on other sites

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

Timer overflow / two's complement issue?

 

*delayed edit to fix quote formatting

Share this post


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

Share this post


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.

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0