[gnoduino: 226/237] Simplifying microseconds <-> clock cycles conversions. (Rob Tillaart)



commit 65cb858eeb5eff189389d7bc5d9c586591c398a2
Author: David A. Mellis <d mellis arduino cc>
Date:   Fri Dec 30 18:05:12 2011 -0500

    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

 arduino/cores/arduino/Arduino.h |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
---
diff --git a/arduino/cores/arduino/Arduino.h b/arduino/cores/arduino/Arduino.h
index c05b919..bfec943 100755
--- a/arduino/cores/arduino/Arduino.h
+++ b/arduino/cores/arduino/Arduino.h
@@ -73,8 +73,8 @@ extern "C"{
 #define noInterrupts() cli()
 
 #define clockCyclesPerMicrosecond() ( F_CPU / 1000000L )
-#define clockCyclesToMicroseconds(a) ( ((a) * 1000L) / (F_CPU / 1000L) )
-#define microsecondsToClockCycles(a) ( ((a) * (F_CPU / 1000L)) / 1000L )
+#define clockCyclesToMicroseconds(a) ( (a) / clockCyclesPerMicrosecond() )
+#define microsecondsToClockCycles(a) ( (a) * clockCyclesPerMicrosecond() )
 
 #define lowByte(w) ((uint8_t) ((w) & 0xff))
 #define highByte(w) ((uint8_t) ((w) >> 8))



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]