Playing with Arduino
A page to record my playing with Arduino
clockCyclesPerMicrosecond()/ clockCyclesToMicroseconds()/ microsecondsToClockCycles()


These macros convert the number of clocks and time(in microsecond).

Source Code

The clockCyclesPerMicrosecond()/clockCyclesToMicroseconds()/microsecondsToClockCycles() is defined in hardware/arduino/avr/cores/arduino/Arduino.h as below.

#define clockCyclesPerMicrosecond() ( F_CPU / 1000000L )
#define clockCyclesToMicroseconds(a) ( (a) / clockCyclesPerMicrosecond() )
#define microsecondsToClockCycles(a) ( (a) * clockCyclesPerMicrosecond() )

The clockCyclesPerMicrosecond() shows the number of clocks a micro second.

F_CPU is (maybe) uses defined in hardware/arduino/boards.txt. In case of Arduino Uno it is 16000000(=16MHz). As a second is 1000*1000 microseconds, it is 16 which is F_CPU divided by 1000000.

The clockCyclesToMicroseconds() converts the number of clocks to microseconds.

The microsecondsToClockCycles() converts the microseconds to the number of clocks.


Arduino 1.8.13

Last Update

June 19, 2020

inserted by FC2 system