<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://shawnreeves.net//wiki/index.php?action=history&amp;feed=atom&amp;title=Frequency_meter_on_Arduino</id>
	<title>Frequency meter on Arduino - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://shawnreeves.net//wiki/index.php?action=history&amp;feed=atom&amp;title=Frequency_meter_on_Arduino"/>
	<link rel="alternate" type="text/html" href="https://shawnreeves.net//wiki/index.php?title=Frequency_meter_on_Arduino&amp;action=history"/>
	<updated>2026-04-17T08:16:20Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.0</generator>
	<entry>
		<id>https://shawnreeves.net//wiki/index.php?title=Frequency_meter_on_Arduino&amp;diff=2717&amp;oldid=prev</id>
		<title>Shawn at 20:51, 23 May 2014</title>
		<link rel="alternate" type="text/html" href="https://shawnreeves.net//wiki/index.php?title=Frequency_meter_on_Arduino&amp;diff=2717&amp;oldid=prev"/>
		<updated>2014-05-23T20:51:00Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;a href=&quot;https://shawnreeves.net//wiki/index.php?title=Frequency_meter_on_Arduino&amp;amp;diff=2717&amp;amp;oldid=2647&quot;&gt;Show changes&lt;/a&gt;</summary>
		<author><name>Shawn</name></author>
	</entry>
	<entry>
		<id>https://shawnreeves.net//wiki/index.php?title=Frequency_meter_on_Arduino&amp;diff=2647&amp;oldid=prev</id>
		<title>Shawn: /* Arduino-based frequency meter */</title>
		<link rel="alternate" type="text/html" href="https://shawnreeves.net//wiki/index.php?title=Frequency_meter_on_Arduino&amp;diff=2647&amp;oldid=prev"/>
		<updated>2014-03-26T22:24:04Z</updated>

		<summary type="html">&lt;p&gt;&lt;span class=&quot;autocomment&quot;&gt;Arduino-based frequency meter&lt;/span&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 15:24, 26 March 2014&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l1&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==Arduino-based frequency meter==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==Arduino-based frequency meter==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;The following program directs an Arduino or compatible micro-controller to time a signal (falling voltage) on an input pin and report the inverse of the time between previous signals as a frequency in Hz, in a range of 100.0Hz to 0.10Hz. Used with the circuit diagrammed in [[File:Frequency-meter-Arduino-on-a-board.pdf]].&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;The following program directs an Arduino or compatible micro-controller to time a signal (falling voltage) on an input pin and report the inverse of the time between previous signals as a frequency in Hz, in a range of 100.0Hz to 0.10Hz. Used with the circuit diagrammed in [[File:Frequency-meter-Arduino-on-a-board.pdf]].&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;For a discussion of the circuit and its function, please see [[frequency meter]].&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;===Code===&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;===Code===&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  /*&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  /*&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Shawn</name></author>
	</entry>
	<entry>
		<id>https://shawnreeves.net//wiki/index.php?title=Frequency_meter_on_Arduino&amp;diff=2646&amp;oldid=prev</id>
		<title>Shawn: Created page with &quot;==Arduino-based frequency meter== The following program directs an Arduino or compatible micro-controller to time a signal (falling voltage) on an input pin and report the inv...&quot;</title>
		<link rel="alternate" type="text/html" href="https://shawnreeves.net//wiki/index.php?title=Frequency_meter_on_Arduino&amp;diff=2646&amp;oldid=prev"/>
		<updated>2014-03-26T22:22:48Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;==Arduino-based frequency meter== The following program directs an Arduino or compatible micro-controller to time a signal (falling voltage) on an input pin and report the inv...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Arduino-based frequency meter==&lt;br /&gt;
The following program directs an Arduino or compatible micro-controller to time a signal (falling voltage) on an input pin and report the inverse of the time between previous signals as a frequency in Hz, in a range of 100.0Hz to 0.10Hz. Used with the circuit diagrammed in [[File:Frequency-meter-Arduino-on-a-board.pdf]].&lt;br /&gt;
===Code===&lt;br /&gt;
 /*&lt;br /&gt;
 On timing:&lt;br /&gt;
 micros() returns the number of microseconds since the Arduino board began running the current program.&lt;br /&gt;
 micros() returns an unsigned long integer, so it overflows to zero after 4,294,967,295 µs.&lt;br /&gt;
 millis() is similar except it counts milliseconds.&lt;br /&gt;
 NOTA BENE:Both millis() and micros() clear interrupts while they read the timer, so use them sparingly!&lt;br /&gt;
 &lt;br /&gt;
 On LCD quirks:&lt;br /&gt;
 Clearing the display with the clear/home command takes a lot of time.&lt;br /&gt;
 We might consider leaving characters in memory and just overwriting them.&lt;br /&gt;
 --We&amp;#039;d just need to be sure to write spaces at the end if one printout might be shorter than the previous printout.&lt;br /&gt;
 &lt;br /&gt;
 On interrupt routine:&lt;br /&gt;
 attachInterrupt(interrupt, ISR, mode)&lt;br /&gt;
   interrupt: 0 means digital pin 2 and 1 means digital pin 3. (Mega2560, Leonardo, and Due boards offer it on more pins)&lt;br /&gt;
   ISR: routine to call when interrupt happens.&lt;br /&gt;
   mode: LOW, CHANGE, RISING, FALLING (DUE boards also allow HIGH)&lt;br /&gt;
 */&lt;br /&gt;
 //Uncomment the following to allow serial debug messages. May interfere with timing?&lt;br /&gt;
 //#define serialDebug 1&lt;br /&gt;
 //Define NOP as an assembly language macro to delay one cycle. See http://forum.arduino.cc/index.php?topic=43333.0&lt;br /&gt;
 #define NOP __asm__ __volatile__ (&amp;quot;nop\n\t&amp;quot;)&lt;br /&gt;
 // and then use it in code as follows&lt;br /&gt;
 //NOP; // delay 62.5ns on a 16MHz AtMega&lt;br /&gt;
 &lt;br /&gt;
 //HARDWARE PIN SELECTION:&lt;br /&gt;
 //The pins are selected to minimize spaghetti-crossing on the breadboard, and so are dependent on the microcontroller&amp;#039;s physical config.&lt;br /&gt;
 const int switchPin = 3;//must be pin 2 or 3&lt;br /&gt;
 const int switchPinInt = 1;//for 328-based arduinos, 0 means digital I/O pin 2, and 1 means digital I/O pin 3&lt;br /&gt;
 //We&amp;#039;re using home-made SPI instead of the standard library since our LCD (EA DOGM081) uses its own flavor of SPI&lt;br /&gt;
 //The following pins depend on how the DOGM081 and the mircro-controller are connected&lt;br /&gt;
 const int DATAP = 9;  //to SI on the DOGM081&lt;br /&gt;
 const int CLKP = 10;  //to CLK on the DOGM081&lt;br /&gt;
 const int chipSelectPin = 11;  //to CSB on the DOGM081&lt;br /&gt;
 const int RSPin = 12;  //to RS on the DOGM081&lt;br /&gt;
 &lt;br /&gt;
 //CONDITIONAL, CONSTANT PARAMETERS:&lt;br /&gt;
 const unsigned long debounceMicroSeconds = 100;//Our routine will ignore signals that come closer together than this amount of microseconds&lt;br /&gt;
 const unsigned long maxTime = 11000000;//The amount of microseconds before going into waiting mode.&lt;br /&gt;
 &lt;br /&gt;
 //&lt;br /&gt;
 //It&amp;#039;s recommended all variables used in the interrupt service routine are considered volatile,&lt;br /&gt;
 // so not kept in multi-purpose registers but in dedicated memory slots:&lt;br /&gt;
 volatile unsigned long hitTime;&lt;br /&gt;
 unsigned long lastTime;//Track the time of the previous signal so we can calculate time elapsed since.&lt;br /&gt;
 unsigned long microsSince;//for determining idleness. 0 &amp;lt;= ul &amp;lt;= 4,294,967,295&lt;br /&gt;
 unsigned long periodMicroSeconds;&lt;br /&gt;
 float frequencyHz;//we use floating point math for maximum precision.&lt;br /&gt;
 word frequencycHz;//this we will convert to a string to display.&lt;br /&gt;
 byte thisDigit;&lt;br /&gt;
 byte precision;  //to keep track of roughly how precise the frequency will be.&lt;br /&gt;
 byte updateDisplay;  //True this byte when display should be updated.&lt;br /&gt;
 byte trackDigits;  //track whether display of significant digits has started.&lt;br /&gt;
 word delayCounter;//can count 0 to 65535&lt;br /&gt;
 &lt;br /&gt;
 void recordTime(){//this is the interrupt service routine to be called whenever switchPin&amp;#039;s voltage falls&lt;br /&gt;
 //we want as few instructions and variables inside this routine as possible, so we just gather the time and go.&lt;br /&gt;
   hitTime = micros();//reads a clock in microseconds&lt;br /&gt;
 }&lt;br /&gt;
 void sendToDisplay(byte byteToSend, word microsecondsToDelay ){&lt;br /&gt;
   for (int shiftCounter = 0; shiftCounter &amp;lt; 8; shiftCounter++) {//repeat 8 times&lt;br /&gt;
     if (byteToSend &amp;gt; 127) {//get most significant bit. If a byte is over 127, then it must start with a one.&lt;br /&gt;
       digitalWrite(DATAP,HIGH);//Represent one, or on&lt;br /&gt;
     } else {&lt;br /&gt;
       digitalWrite(DATAP,LOW);//Represent zero, or off&lt;br /&gt;
     }&lt;br /&gt;
     //data setup time, the minimum time the display chip needs the data pin to be stable before the clock rises, is 10ns&lt;br /&gt;
     NOP; // Do nothing for one cycle, delaying 62.5ns on a 16MHz AtMega&lt;br /&gt;
     digitalWrite(CLKP,HIGH);//raise voltage on clock pin, forcing display chip to read from the data pin.&lt;br /&gt;
     //data hold time, the maximum time the display chip might need to read the data after the clock rises, is 20ns&lt;br /&gt;
     NOP; // delay 62.5ns on a 16MHz AtMega&lt;br /&gt;
     digitalWrite(CLKP,LOW);//get ready for next time&lt;br /&gt;
     for (int clockDelay=16;clockDelay&amp;gt;0;clockDelay--){//repeat 16 times&lt;br /&gt;
       NOP; // delay 62.5ns on a 16MHz AtMega&lt;br /&gt;
     }&lt;br /&gt;
     byteToSend *=2;//line up second-most significant bit as the most significant bit&lt;br /&gt;
   }&lt;br /&gt;
 //  shiftOut(DATAP, CLKP, MSBFIRST, byteToSend);//this built-in library was working extremely slowly (~1Hz).&lt;br /&gt;
   while(microsecondsToDelay-- &amp;gt; 0){//If microsecondsToDelay is above zero, do the following. Also decrement microsecondsToDelay by one.&lt;br /&gt;
     NOP; // delay 62.5ns on a 16MHz AtMega&lt;br /&gt;
     NOP; //By using 15 of these, we delay a predictable microsecond. A loop would be neater but probably less precise&lt;br /&gt;
     NOP; //But to be accurate we&amp;#039;d need to know how long it takes to execute the while statement each time.&lt;br /&gt;
     NOP;&lt;br /&gt;
     NOP;&lt;br /&gt;
     NOP;&lt;br /&gt;
     NOP;&lt;br /&gt;
     NOP;&lt;br /&gt;
     NOP;&lt;br /&gt;
     NOP;&lt;br /&gt;
     NOP;&lt;br /&gt;
     NOP;&lt;br /&gt;
     NOP;&lt;br /&gt;
     NOP;&lt;br /&gt;
     NOP;&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
 void waitingMode(){&lt;br /&gt;
   precision = 0;//We use &amp;#039;precision&amp;#039; as a flag to mark whether we&amp;#039;ve already made one clock-reading.&lt;br /&gt;
   digitalWrite(RSPin, LOW);  //about to issue a command&lt;br /&gt;
   for (int clockDelay=160;clockDelay&amp;gt;0;clockDelay--){//wait ten microseconds&lt;br /&gt;
     NOP; // delay 62.5ns on a 16MHz AtMega&lt;br /&gt;
   }&lt;br /&gt;
   sendToDisplay(B00000001, 0);  //clear display and go home&lt;br /&gt;
   for (int clockDelay=1600;clockDelay&amp;gt;0;clockDelay--){//wait a hundred microseconds&lt;br /&gt;
     NOP; // delay 62.5ns on a 16MHz AtMega&lt;br /&gt;
   }&lt;br /&gt;
   digitalWrite(RSPin, HIGH);  //about to issue data&lt;br /&gt;
   //Address setup time is supposed to be 10 µs, but the following W goes missing without the following 100 microsecond delay.&lt;br /&gt;
   for (int clockDelay=1600;clockDelay&amp;gt;0;clockDelay--){&lt;br /&gt;
     NOP; // delay 62.5ns on a 16MHz AtMega&lt;br /&gt;
   }&lt;br /&gt;
   sendToDisplay(&amp;#039;W&amp;#039;,0);//The compiler interprets &amp;#039;W&amp;#039; as the ascii value for W, B01010111.&lt;br /&gt;
   sendToDisplay(&amp;#039;a&amp;#039;,0);&lt;br /&gt;
   sendToDisplay(&amp;#039;i&amp;#039;,0);&lt;br /&gt;
   sendToDisplay(&amp;#039;t&amp;#039;,0);&lt;br /&gt;
   sendToDisplay(&amp;#039;i&amp;#039;,0);&lt;br /&gt;
   sendToDisplay(&amp;#039;n&amp;#039;,0);&lt;br /&gt;
   sendToDisplay(&amp;#039;g&amp;#039;,0);&lt;br /&gt;
   #ifdef serialDebug//Only do the following if serialDebug is defined above.&lt;br /&gt;
     Serial.println(&amp;quot;Waiting&amp;quot;);&lt;br /&gt;
   #endif&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 void setup(){//This is the routine done only once when the board is reset, or first receives power.&lt;br /&gt;
   pinMode(DATAP, OUTPUT);//Prepare these pins to assert a voltage&lt;br /&gt;
   pinMode(CLKP, OUTPUT);&lt;br /&gt;
   pinMode(chipSelectPin, OUTPUT);&lt;br /&gt;
   pinMode(RSPin, OUTPUT);&lt;br /&gt;
   pinMode(switchPin, INPUT_PULLUP);//get switchPin ready for interrupt input, activating (internal) pullup resistor Hall Switch expects.&lt;br /&gt;
 &lt;br /&gt;
   #ifdef serialDebug//Only do the following if serialDebug is defined above.&lt;br /&gt;
     // initialize serial communication at 9600 bits per second:&lt;br /&gt;
     Serial.begin(9600);//prepare the serial lines to use 9600 baud&lt;br /&gt;
   #endif&lt;br /&gt;
 &lt;br /&gt;
   delay(500);  //Wait half a second for display to power.&lt;br /&gt;
   digitalWrite(chipSelectPin, HIGH);//Set high to make sure CSB has fallen once before beginning commands,&lt;br /&gt;
   for (int clockDelay=1600;clockDelay&amp;gt;0;clockDelay--){&lt;br /&gt;
     NOP; // delay 62.5ns on a 16MHz AtMega&lt;br /&gt;
   }  &lt;br /&gt;
   digitalWrite(CLKP, LOW);//DOGM081 expects to take in data on rising clock.&lt;br /&gt;
   digitalWrite(chipSelectPin, LOW);//and keep it low, unless you need the other pins to do something not with this display&lt;br /&gt;
   digitalWrite(RSPin, LOW);//About to issue commands&lt;br /&gt;
   //The following lines from Electronic Assembly&amp;#039;s data sheet, with cursor mode altered.&lt;br /&gt;
   //One might repeat the following command many times to get the attention of the ST7032 driver&lt;br /&gt;
   sendToDisplay(B00110000, 27); //Function Set, 1 line, instruction table 0&lt;br /&gt;
   sendToDisplay(B00110001, 27); //Function Set, 1 line, instruction table 1&lt;br /&gt;
   sendToDisplay(B00110001, 27); //Function Set, 1 line, instruction table 1, repeat request recommended by ST7032 datasheet&lt;br /&gt;
   sendToDisplay(B00011100, 27); //Bias 1/4, 1 line LCD&lt;br /&gt;
   sendToDisplay(B01010001, 27); //Booster off, set contrast C5, C4&lt;br /&gt;
   sendToDisplay(B01101010, 0); //set voltage follower on, gain 2/7&lt;br /&gt;
   delay(200);//recommended by ST7032 datasheet&lt;br /&gt;
   sendToDisplay(B01110100, 27); //set contrast C3, C2, C1&lt;br /&gt;
   sendToDisplay(B00001100, 27); //display on, cursor off, blink cursor position&lt;br /&gt;
   sendToDisplay(B00000001, 3); //clear display, home cursor&lt;br /&gt;
   delay(2);//takes over a millisecond to clear&lt;br /&gt;
   sendToDisplay(B00000110, 2); //entry from right to left, no scrolling.&lt;br /&gt;
   waitingMode();&lt;br /&gt;
   attachInterrupt(switchPinInt, recordTime, FALLING);//Go to recordTime whenever interrupt switchPinInt goes from high to low&lt;br /&gt;
 }//Done setting up&lt;br /&gt;
 &lt;br /&gt;
 void loop() {&lt;br /&gt;
   if(hitTime&amp;gt;0){//There&amp;#039;s a 1 in 4 billion chance hitTime is zero but represents an actual reading.&lt;br /&gt;
     if (0==precision) {//this is first time switch, so no reference, so only set precision flag and record time.&lt;br /&gt;
       precision = 1;//so we don&amp;#039;t end up here next time&lt;br /&gt;
       lastTime = hitTime;//record now for reference next time.&lt;br /&gt;
     }&lt;br /&gt;
     else&lt;br /&gt;
     { periodMicroSeconds = hitTime - lastTime; //if timer has overflowed once since last time, ok since this subtraction will overflow back.&lt;br /&gt;
       if (periodMicroSeconds &amp;gt; debounceMicroSeconds) {//debounce by rejecting too-fast times&lt;br /&gt;
         precision = 1;//Set our flag so we know we have a valid period&lt;br /&gt;
         updateDisplay = 1;//We have a new period, so let&amp;#039;s update the display&lt;br /&gt;
         lastTime = hitTime;//record now for reference next time.&lt;br /&gt;
       }&lt;br /&gt;
     }&lt;br /&gt;
     hitTime=0;//skip the above routine until another hit.&lt;br /&gt;
   }&lt;br /&gt;
   //We don&amp;#039;t want to read micros every trip through this loop--Reading micros causes interrupt issues.&lt;br /&gt;
   // So, if we increase a 16-bit (word) variable by one every trip, it will only overflow back to zero once every 65536 (2^16) trips.&lt;br /&gt;
   if(0 == delayCounter++){&lt;br /&gt;
     microsSince = micros() - lastTime;//Keep track of idleness.&lt;br /&gt;
   }&lt;br /&gt;
   if(precision &amp;gt; 0 &amp;amp;&amp;amp; microsSince &amp;gt; maxTime){//It&amp;#039;s been more than maxTime since the last hit, so go back into waiting mode&lt;br /&gt;
     waitingMode();&lt;br /&gt;
   }&lt;br /&gt;
   if (updateDisplay) {&lt;br /&gt;
     updateDisplay = 0;//Don&amp;#039;t come back here until next update is requested by changing this flag back to 1&lt;br /&gt;
     frequencyHz = 1000000.0 / (float)periodMicroSeconds;//float math for best precision over a wide range.&lt;br /&gt;
     if (periodMicroSeconds&amp;gt;20) {precision = 2;}//Only when a rounded divisor is about 20 does the quotient have any meaning past the first digit.&lt;br /&gt;
     if (periodMicroSeconds&amp;gt;200) {precision = 3;}&lt;br /&gt;
     if (periodMicroSeconds&amp;gt;2000) {precision = 4;}&lt;br /&gt;
     if (periodMicroSeconds&amp;gt;20000) {precision = 5;}&lt;br /&gt;
 #ifdef serialDebug&lt;br /&gt;
     Serial.println(periodMicroSeconds);// print the value you read:&lt;br /&gt;
 #endif&lt;br /&gt;
     digitalWrite(RSPin, LOW);  //about to issue a command&lt;br /&gt;
     sendToDisplay(B00000001, 0);  //clear display and go home&lt;br /&gt;
     //wait a long time for display to clear.&lt;br /&gt;
     for (int clockDelay=3200;clockDelay&amp;gt;0;clockDelay--){&lt;br /&gt;
       NOP; // delay 62.5ns on a 16MHz AtMega&lt;br /&gt;
     }&lt;br /&gt;
     digitalWrite(RSPin, HIGH);  //about to issue data&lt;br /&gt;
     frequencyHz *= 100.0;  //Temporarily, if you uncomment the re-conversion below, convert to cHz.&lt;br /&gt;
     frequencycHz = (word)frequencyHz;//round to a number between 0 and 65535&lt;br /&gt;
     //frequencyHz /= 100.0;  //Convert back to Hz in case we ever need it.&lt;br /&gt;
     trackDigits = 0;//We&amp;#039;re going to display the correct precision by tracking significant digits&lt;br /&gt;
     //The highest a word integer can be is 65535, so the most significant digit we could possibly have is the ten thousands digit.&lt;br /&gt;
     thisDigit = frequencycHz / 10000;//get ten-thousands digit. This is integer math, so no fractions in result.&lt;br /&gt;
     if(thisDigit &amp;gt; 0){&lt;br /&gt;
       trackDigits = 1;  //start tracking significant digits&lt;br /&gt;
       thisDigit +=48; //convert to ASCII&lt;br /&gt;
       sendToDisplay(thisDigit, 0);&lt;br /&gt;
     }&lt;br /&gt;
     frequencycHz = frequencycHz % 10000;//discard ten-thousands by modulo arithmetic&lt;br /&gt;
     thisDigit = frequencycHz / 1000;//get thousands digit&lt;br /&gt;
     if(trackDigits){&lt;br /&gt;
       if(++trackDigits &amp;gt; precision) {//Increment trackDigits, then check to see whether it has exceeded precision.&lt;br /&gt;
         sendToDisplay(48, 0);//We&amp;#039;ve run beyond our precision, so display a placeholding zero.&lt;br /&gt;
       } else {&lt;br /&gt;
         thisDigit +=48; //convert to ASCII&lt;br /&gt;
         sendToDisplay(thisDigit, 0);//show this digit since it is significant&lt;br /&gt;
       }&lt;br /&gt;
     } else {&lt;br /&gt;
       if(thisDigit &amp;gt; 0){&lt;br /&gt;
         trackDigits = 1;  //start tracking significant digits&lt;br /&gt;
         thisDigit +=48; //convert to ASCII&lt;br /&gt;
         sendToDisplay(thisDigit, 0);&lt;br /&gt;
       }&lt;br /&gt;
     }&lt;br /&gt;
     frequencycHz = frequencycHz % 1000;//discard thousands&lt;br /&gt;
     thisDigit = frequencycHz / 100;//get hundreds digit&lt;br /&gt;
     if(trackDigits){&lt;br /&gt;
       if(++trackDigits &amp;gt; precision) {//Increment trackDigits, then check to see whether it has exceeded precision.&lt;br /&gt;
         sendToDisplay(48, 0);//We&amp;#039;ve run beyond our precision, so display a placeholding zero.&lt;br /&gt;
       } else {&lt;br /&gt;
         thisDigit +=48; //convert to ASCII&lt;br /&gt;
         sendToDisplay(thisDigit, 0);//show this digit since it is significant&lt;br /&gt;
       }&lt;br /&gt;
     } else {&lt;br /&gt;
       if(thisDigit &amp;gt; 0){&lt;br /&gt;
         trackDigits = 1;  //start tracking significant digits&lt;br /&gt;
       }&lt;br /&gt;
       thisDigit +=48; //convert to ASCII&lt;br /&gt;
       sendToDisplay(thisDigit, 0);//this time, even if zero, we display, since placeholder needed for decimal point.&lt;br /&gt;
     }&lt;br /&gt;
     sendToDisplay(&amp;#039;.&amp;#039;, 0);//send a decimal point&lt;br /&gt;
     frequencycHz = frequencycHz % 100;//discard hundreds&lt;br /&gt;
     thisDigit = frequencycHz / 10;//get tens digit&lt;br /&gt;
     if(trackDigits){&lt;br /&gt;
       if(++trackDigits &amp;lt;= precision) {//increment trackDigits, then check to see whether it hasn&amp;#039;t exceeded precision&lt;br /&gt;
         thisDigit +=48; //convert to ASCII&lt;br /&gt;
         sendToDisplay(thisDigit, 0);//show this digit since it is significant&lt;br /&gt;
       }&lt;br /&gt;
     } else {&lt;br /&gt;
       if(thisDigit &amp;gt; 0){&lt;br /&gt;
         trackDigits = 1;  //start tracking significant digits&lt;br /&gt;
       }&lt;br /&gt;
       thisDigit +=48; //convert to ASCII&lt;br /&gt;
       sendToDisplay(thisDigit, 0);//show this digit since it is significant&lt;br /&gt;
     }&lt;br /&gt;
     thisDigit = frequencycHz % 10;//get ones digit&lt;br /&gt;
     if(++trackDigits &amp;lt;= precision) {//increment trackDigits, then check to see whether it hasn&amp;#039;t exceeded precision&lt;br /&gt;
       thisDigit +=48; //convert to ASCII&lt;br /&gt;
       sendToDisplay(thisDigit, 0);//show this digit since it is significant&lt;br /&gt;
     }&lt;br /&gt;
     sendToDisplay(&amp;#039;H&amp;#039;, 0);//always show units if they exist&lt;br /&gt;
     sendToDisplay(&amp;#039;z&amp;#039;, 0);&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
[[Category:Electronics]]&lt;/div&gt;</summary>
		<author><name>Shawn</name></author>
	</entry>
</feed>