Capturing timer value based on external interrupt , leveraging the 62.5nsec (16MHz) resolution) of the ATMEGA328 on the Arduino Uno

All of the #include files needed are already included by Arduino.h.

The _BV(x) is a macro in one of those files, roughly equivalent to (1 << x) but may be limited to 8 bits.

You can generally use the C-language examples in the datasheet. You can usually read and write 8-bit and 16-bit registers as if they were global variables. Pin names (PB0-7, PD0-7) are just bit numbers (0-7). That's why _BV(x) or (1 << x) is used to make them a bitmask. Some registers have weird behaviors. For example, in most Interrupt Flag registers you CLEAR the flag by writing a 1 bit in the bit location. The locations written with 0 bits do nothing.

Print out a copy of the Arduino board pinout so you can translate between Arduino pin numbers and AVR ports and bits. For example, on the UNO and Nano (ATmega328P) pins 0 through 7 are PD0 through PD7 and pins 8 through 13 are PB0 through PB5. That will be different on other processors like the MEGA and Leonardo.

1 Like