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

Abstract

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.

1
2
3
#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 uno.build.f_cpu 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.

Version

Arduino 1.8.13

Last Update

June 19, 2020

inserted by FC2 system