Go Down

Topic: How to calculate the Instruction Cycle time? (Read 521 times) previous topic - next topic

AK51

I need to make a delay of , for instance, 180ms with high accuracy. If I make a subroutine like this, how much micro second delay I have to subtract it? Thanks.

void delay_subroutine(long timedelay){
  while (timedelay > 16383){
    delayMicroseconds(16383);
    timedelay = timedelay-16383;
  }
  delayMicroseconds(timedelay);
}

AMPS-N

You can use timer library. It will be useful when you are trying to run call function exact time .
Else use MSTIMER liberay to get control over function.
AMPS

AK51

Thanks, I use micros() function and it is kind of ok.

Cheers

MarkT

If you have an Arduino with a ceramic resonator rather than a quartz crystal the
+/-0.3% accuracy of ceramic resonator itself will dwarf any fiddle factor in your
loop.

Having said that waiting for micros() is a reasonable approach - the largest source
of error is the jitter caused by the timer0 interrupt handler (assuming a perfect
crystal timebase).
[ I won't respond to messages, use the forum please ]

Go Up