The code for controlling the speed of the spin table is an RPM counter using a Hall effect sensor reading magnetic pulses on each rotation of the wafer holder.
The RPM is calculated every 250 milliseconds if the table’s rotational speed is not within the set range, or every second if the previous calculation of the RPM shows that it is within the proper range.
A magnet detection counter increases each time the magnet causes the nonlatching Hall effect sensor to send a 5 V signal to the Arduino. Each time the RevCalc loop is called, the time from the last calculation is compared to the current time, and used along with the number of rotations in that time to calculate the revolutions per minute.
Both the time tracking variable and the magnet counting variable are reset after each calculation of speed. The following code contains comments for each statement after a double slash.