I created a stopwatch using and Arduino Uno, an LCD display, a start button, and a reset button. The code uses the millis() function to get the current number of milliseconds, does a little math, and then displays the minutes:seconds:hundredths. When the Arduino is plugged into the USB port on my computer, the accuracy (when checked with a racing stopwatch) is very accurate. When I plug a 9v battery into the Arduino, my homemade stopwatch is very accurate.
So... I wanted to make this more permanent. I built a standalone arduino using the ATMEGA328, 20 MHz quart crystal, a 9v-to-5v step-up/step-down regulator from Pololu, and a foot switch to start/stop the stopwatch (this is why I built this homemade stopwatch to begin with -- to get a foot switch operated stopwatch). I soldered everything to a board. The standalone stopwatch runs much faster than it should. For example, when the racing stopwatch says 20 seconds, my homemade stopwatch says 25 seconds.
Does anyone have any ideas why the homemade stopwatch is running too fast? Any ideas how I can fix it?
Does anyone have any ideas why the homemade stopwatch is running too fast? Any ideas how I can fix it?
An Arduino is clocked with 16MHz. If you built your custom board with a 20MHZ clock and compile your sketches with the standard Arduino settings the complete timing is wrong.
You can add an entry in your boards.txt where you change the clock setting to 20MHz, compile again with this board chosen and your clock will even be more accurate than the UNO because you're using a crystal instead of the UNO's ceramic resonator.
pylon:
You can add an entry in your boards.txt where you change the clock setting to 20MHz, compile again with this board chosen and your clock will even be more accurate than the UNO because you're using a crystal instead of the UNO's ceramic resonator.
Or less accurate. The Arduino Core is specifically designed to work correctly at 1, 2, 4, 8, and 16 MHz clock speeds. At other clock speeds millis and micros are inaccurate. A search of this forum should reveal more details.
Thank you very much! I guess I thought 16 MHz is good, 20 MHz would be better. Guess I was wrong! I will look into modifying the board.txt file (or de-solder the 20 MHz crystal and replace it with a 16 MHz).