Standalone Atmega168...timing issue?

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1256871170

As per that thread, I just burned a sketch onto an Atmega168 that should display "Uptime = xxx" on an lcd (uptime being seconds that the atmega has been running. The LCD works great, but the time is erratic.. sometimes a second is short, sometimes it's long. I assume it's a timing issue, but I'm unsure how to troubleshoot the problem. Any suggestions?

hmmm, I just tried a sketch that does

led on
delay 1sec
led off
delay 1sec

and it seems to run accurately....

What's the code for the problematic example you gave above?

Ok so with the following code the LED appears to go on for a second/off for a second but the count on the LCD isn't accurate. It's as if the millis() function isn't functioning properly.

#include <LiquidCrystal.h>
//rs,enable
// initialize the lcd
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);

void printTicks()
{
  lcd.setCursor(0, 0);

  char tickString[16] = "Uptime = ";
  char milliString[5];
  itoa(millis()/1000, milliString, 5);
  strcat(tickString, milliString);
  
  lcd.print(tickString);  
}

void setup() {
  pinMode(10, OUTPUT);
  
  lcd.begin(16, 2);
}

void loop() {
  
  // update the tick counter
  printTicks();
   
  digitalWrite(10, HIGH);
  delay (1000);
  digitalWrite(10, LOW);
  delay (1000);
}

Wow, this looks familiar....

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1232663936

I'm not using home though..

Boots,

I believe that the final argument to itoa() is the base (radix), not the string length. If so, your numbers would be printing out in base 5: 0, 1, 2, 3, 4, 10, 11, 12, 13, 14, 20, etc.

Change the final argument to 10. Also, increase your length of millistring[] to 10 or 20. Don't be too stingy with the bytes.

-Mike

Thanks Mike! That was totally the problem! Good eye!