Pages: [1]   Go Down
Author Topic: How to calculate the Instruction Cycle time?  (Read 503 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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);
}
Logged

DELHI
Offline Offline
God Member
*****
Karma: 8
Posts: 962
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

AMPS

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Cheers
Logged

0
Online Online
Shannon Member
****
Karma: 220
Posts: 12687
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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).
Logged

[ I won't respond to messages, use the forum please ]

Pages: [1]   Go Up
Jump to: