Go Down

Topic: What does Arduino do every 1ms? (Read 378 times) previous topic - next topic

PhiMu

i tried to see how fast an Arduino processes a loop:

Code: [Select]

void setup()
{
  // put your setup code here, to run once:
  pinMode(2, OUTPUT);
}

void loop()
{
  // put your main code here, to run repeatedly:
  static uint8_t n=B00000000;

    PORTD = n;
    n = ~n;
}


I get about 667 kHz (0.74 microseconds) pulse but
I see every 1 ms there is a gap (about 6 microseconds) in the pulse

Is this the interrupt that updates millis() ? does it do something more?
If it's for millis, why don't i see an similar gap for micros()?

steve_mcdonald

I'm not sure of the answer although someone here will help, but your query lead me to wonder what would be the result if you used the bitwise XOR (^) rather than the bitwise NOT.  It could toggle only the one bit you are interested in...

Coding Badly


Timer 0 overflow interrupt.  It's the interrupt that drives micros / millis.


PaulRB

#3
Aug 18, 2019, 08:43 pm Last Edit: Aug 18, 2019, 08:53 pm by PaulRB
I knew it drives millis(). Does it also drive micros()? I got the impression that when your code reads micros(), one of the hardware timer/counter registers is read directly.

I also wonder what happens when loop() terminates. I suspect it checks for received serial characters and buffers them. Maybe the same for i2c and SPI. What else happens?

westfw

Quote
I also wonder what happens when loop() terminates. I suspect it checks for received serial characters and buffers them. Maybe the same for i2c and SPI.
No.
You can LOOK, you know...
Arduino Core Source Code

Coding Badly

Does it also drive micros()?
Correct.

I got the impression that when your code reads micros(), one of the hardware timer/counter registers is read directly.
Also correct.


Go Up