Help with a count up timer.

okay so one of my friends asked me to build him a count up timer for his wrist. he wants it to display: years, months, days, hours, minutes, seconds, and miliseconds on an lcd. it works fine when i write it for seconds(i’m testing it over serial monitor till the lcd comes in) but when i add milliseconds it takes about two minutes to reach a second. i’m thinking that my code is a little to laborious for the processor (arduino duemillenove) and it is taking to long to write it to the serial port. will someone look it over, also i haven’t inserted the clear code for the lcd yet.

#include <Streaming.h>

#include <MsTimer2.h>

long month = 0;
long day = 0;
long year = 0;
long hour= 0;
long minute = 0;
long second = 0;
long millisecond = 0;



void setup() 
{
  //opens the serial port
Serial.begin(9600);

// sets the timer to run count every milisecond
MsTimer2::set(1, count);
MsTimer2::start();

}

void count()
{
  //incriment the millisecond
    ++millisecond;
  
  //tells the machine every year to reset month and add a year
   if (month == 12)
  {
    month = 0;
    ++year;
  }
  
  //tells the machine every 30 days to reset day and add a month and yes i picked an arbitrary number for the month
  
  else if (day == 30)
 {
   day = 0;
   ++month;
 } 
  
  //tells the machine every 24 hours to reset hour and add a day
  
  else if (hour == 24)
  {
    hour = 0;
     day += 1;
  } 
  
  //tells the machine every 60 minutes to reet minute and add an hour
  
  else if (minute == 60){
    minute = 0;
    hour += 1;
  }
  
  //tells the machine every 60 seconds to reset second and add a minute
  
  else if (second == 60){
    second = 0;
    minute += 1;
  }
  
  //tells the machine every 1000 miliseconds to reset milisecond to 0 and increase the second
  else if (millisecond == 1000)
  {
    millisecond = 0;
   second += 1;
  } 
  

// sends the obejects via the serial port using the Streaming library
Serial << "Years: " << year << " " << "Months: " << month << " " << "Days: " << day << " " << "Hours: " << hour << " " << "Minutes:" << minute << " " << "Seconds: " << second << " " << "Milliseconds: " << millisecond  << endl;
}


void loop()
{
  


   

}

any ideas and criticism’s welcome.

Say you have this time:

Years: 2011 Months: 06 Days: 04 Hours: 17 Minutes: 23 Seconds: 14 Milliseconds: 123

Including the newline at the end that is 85 characters. At 9600 baud you can display 960 characters a second. So sending 85 characters you will be able to get 11.2 updates a second. Hardly millisecond precision.

In any case as KE7GKP said, movies are screened at somewhere around 24 to 30 frames per second because that is where the eye has persistence of vision. Plus, I found that trying to update an LCD very quickly, the pixels just merge into each other giving a jumbled, unreadable blur.

The best you could hope for is 10ths of a second, and that assumes the LCD updates pretty fast.

The other flaw in your plan is that you have a timer set to go off every millisecond, and you are adding 1 to a counter. But all that assumes your code takes no time to run - not a very realistic assumption. You should be getting the current time (eg. using millis() ) rather than just adding one to a counter.

Hey everybody
Can someone help me
I want to create a timer for Mega 2560 and i found a perfect library , to bad it doesn’t work , it has some errors can someone help me to repair this library
I have this error message

error timer.txt (3.03 KB)

[quote author=Nick Gammon link=msg=457473 date=1307172520] The best you could hope for is 10ths of a second, and that assumes the LCD updates pretty fast. [/quote]

I was planning something similar, a sub-second display. When I realized it would be too fast to read, I thought of just making the outer segments "race around", sort of like a hand on a clock, or a GUI progress indicator. There are six outer segments, so it would count sixths of a second. Just thought I'd share that.

What IDE version are you using because my library does work on 1.6.0 and 1.0.6. *It also works on 1.5.7

Post your code.

Use this library instead. https://github.com/AndrewMascolo/CountUpDownTimer

Added: Where did you download 1.5.5-r2 ? The arduino download page only shows 1.5.5 and 1.5.6-r2.