Arduino UNO internal clock not working properly with millis

Hi, I'm was trying to use millis function in a project and realised that maybe there's a problem with my Arduino UNO internal clock, so I simply ran a basic code to print millis and what I've got at the serial monitor was a countdown from around 400 to 250 and then it stucked between 255 and 248...

Here's the code I ran:

void setup() {
  Serial.begin(115200);
}

void loop() {
  Serial.print(millis());
}
Serial.println(millis());

What about now?

You said internal clock, that's not standard. To what did you set it and can that handle 115200 baud?

TheMemberFormerlyKnownAsAWOL:

Serial.println(millis());

What about now?

I've tried that, but still the same numbers...

what I've got at the serial monitor was a countdown from around 400 to 250 and then it stucked

Of all the things that might happen the millis() value counting down is just about the last thing that I would have expected.

Try this

void setup()
{
  Serial.begin(115200);
}

void loop()
{
  Serial.println(millis());
  delay(1000);
}

What output do you get ?
Is the Serial monitor set to the correct baud rate ?

septillion:
You said internal clock, that's not standard. To what did you set it and can that handle 115200 baud?

I don't quite understand what you mean by "not standard", sorry I'm a begginer here jeje. But I'm using Arduino UNO R3, and previously tried with 9600 baud.

Well, thing is that I still get the same results, even with the 1000 ms delay after println... I'm no expert but a simple begginer, but I believe that it's an issue with my board, maybe the internal clock. Is that possible? If so, I should try with another one, right?

Definitely try another one.

If you just use a plain Uno you're not using it's internal clock, you use the onboard crystal :wink:

A clock as slightly different meaning in micro controllers. Here you just want to use millis() which is a bit confusing if you call that a clock.

How is a simple Hello World holding up?

void setup(){
  Serial.begin(115200);
  Serial.print("Hello");
}

void loop(){
  Serial.println(" world!");
  delay(1000);
}

millis counting down? O_o.

Never heard that one.

erictissembaum:
Well, thing is that I still get the same results, even with the 1000 ms delay after println... I'm no expert but a simple begginer, but I believe that it's an issue with my board, maybe the internal clock.

Please post proof.

Here I upload a screenshot of the serial monitor running at 115200 baud as a proof of what I'm saying...

Try again with the screenshot, you have the serial monitor set to 9600 baud, but the sketch is using 115200. Also, you compiled the sketch, but did not upload to the arduino.

The only thing I can think of that would cause an odd output like that would be if someone were altering the code for the millis() function in the Arudino.h file, the oscillator itself can't be off very far if the serial port is still working.

septillion:
How is a simple Hello World holding up?

The MilliSecondUpCounter of my Arduino UNO is counting up the millis at 1-ms interval very nicely.
smMilli.png

unsigned long prMilli = 0;
unsigned long n = 0;

void setup()
{
  Serial.begin(2000000);  //takes 0.02 ms time to send a 4-digit message to Serial Monitor
}

void loop()
{
  Serial.println(n);
  prMilli = millis();
  while (millis() - prMilli < 1)
  {
    ;
  }
  n = n + 1;
}

smMilli.png

Is 1.8.9 the most recent version - did you download the official version or one of the hourly builds (non-stable)?

It might be a bug - most likely a compiler bug - what OS are you using?