Hoerbii3
Hoerbii3

Reputation: 50

Timer values on serial monitor

I want to compare changing values (which I declare in a look up table, not shown in the following example) with timer 0 (TCNT0) of the Arduino.

The results from an oszi showing me, that I don't get what I want to. So I've tried to see the timer values (obviously I was expecting to see values from 0-255). But serial monitor shows me, that I only get values with a big gap between each other.

My question is: is the serial monitor just too slow to show all the values, or is my approach wrong?

int PIN11 = 11; 

void setup() 
{
  Serial.begin(9600);
  pinMode(PIN11, OUTPUT);
}

void loop() 
{
  if(TCNT0 < 100)
  {
    digitalWrite(PIN11, HIGH);
  }
  else
  {
    digitalWrite(PIN11, LOW);
  }
  Serial.println(TCNT0);
}

Serial monitor returns following output:

Expected values: 0 1 2 3...
Actual values: 14 30 46 62 78 94 110 130 150 170 190 210 230 250 14 ...

TimerValues

Upvotes: 1

Views: 294

Answers (1)

Mike
Mike

Reputation: 4288

Yes, your UART is too slow.
Your mainloop is running as fast as it could and don't wait for the UART to be ready. Just wait after the Serial.println(TCNT0); until its ready. Or put a small delay (approx 1ms) after Serial.println(TCNT0);
But if if you want to see your expected values just increment an integer value in your loop and send it to the UART. Don't to that with a timer value.

Upvotes: 1

Related Questions