For measuring motos speed there can Optical interrupter used like H21A1. This is a device where IR LED and photo-transistor is coupled in to plastic housing. The gap between then allows interrupting signal with opaque material and this way switching the output from ON to OFF.
This device can be connected to Microcontrollers ICP pin and this way measuring PWM disk (with hole in it) speed can be measured. Disk has to me fixed to axis of motor. Each time the hole of disk passes the gap, optical interrupter will form a pulse which goes to ICP pin to trigger the timer. If take measuring interval 1s, then counted pulses will be equal to turns in Hz.
Lets take Atmega8 microcontroller which is clocked at 8MHz. For this lets use timer pre-scaler 8, then timer will run at frequency equal 1MHz(period 1μs ). Each time the pulse reaches ICP(Atmega8 – PB0 pin) pin then on falling front of pulse input capture interrupt occur. Interrupt service routine counts the number of timer pulses between two pulses. Number of timer counts define the disk speed (RPM – revolutions per minute).
T – duration of one disk turn. The results will be displayed on 2×16 LCD. LCD is connected to AVR as follows:
LCD data pins to AVR PORTD;
LCD control pins to AVR PORTC (RS->PC0, R/W->PC1, E->PC2).
#define RPM 60000000u
#define ICP PINB0
//timer overflow counter For more detail: Measuring motor speed and display result on LCD using ATmega8 microcontroller