Measuring fan RPM
Going on from our earlier posts about how to synchronise a strobe light to a three wire fan, I've designed something a bit more practical, to measure the RPM of the fan. https://github.com/swiftforarduino/community/blob/master/contributed%20examples/Fan%20RPM%20speed.swift4a/main.swift The important trick is we need to turn one of the timers into a "counter" and count the number of pulses coming in from the fan tachometer. Then if we monitor the count per unit time, we get the RPM simply by multiplication. What is a timer really? It is actually really a counter. In normal timer modes, the timer counts clock cycles. You may have noticed you can run it at different speeds, this is done by dividing the clock cycle. But alternatively, two of the atmega328p timers can alternatively count pulses from external sources. How easy is it to do? Well on S4A it's pretty easy... timer0SetAsCounter(edgeType: RISING_EDGE) Timer 0 will now count the rising edge of pulses...