Skip to content

Commit 3ece282

Browse files
committed
Simplifying microseconds <-> clock cycles conversions. (Rob Tillaart)
This should fix problems with overflows in pulseIn(). It may make millis() slightly less precise for clock speeds that aren't multiple of 1 million, but we don't really support those anyway. http://code.google.com/p/arduino/issues/detail?id=675
1 parent 5184064 commit 3ece282

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

cores/arduino/Arduino.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ extern "C"{
7373
#define noInterrupts() cli()
7474

7575
#define clockCyclesPerMicrosecond() ( F_CPU / 1000000L )
76-
#define clockCyclesToMicroseconds(a) ( ((a) * 1000L) / (F_CPU / 1000L) )
77-
#define microsecondsToClockCycles(a) ( ((a) * (F_CPU / 1000L)) / 1000L )
76+
#define clockCyclesToMicroseconds(a) ( (a) / clockCyclesPerMicrosecond() )
77+
#define microsecondsToClockCycles(a) ( (a) * clockCyclesPerMicrosecond() )
7878

7979
#define lowByte(w) ((uint8_t) ((w) & 0xff))
8080
#define highByte(w) ((uint8_t) ((w) >> 8))

0 commit comments

Comments
 (0)