shown in Figure 7.
With these two additional features, I can set up a
worksheet exactly the way I want it with the graph
formatted using all the built-in cool features of Excel, and I
can use this worksheet over and over for each new run of
measurements. The old data in the copied sheet is cleared
out, the column headings are added, and all the data
flows into the sheet in real time.
Measuring the Timing
of Arduino Operations:
a New Window for Debugging
Now that I could effortlessly bring data into a
spreadsheet, I focused on the quality of the data and how
fast I could take it.
A key feature of a data acquisition system is to have
an accurate time associated with each data point. I didn’t
just want a lot of data points; I wanted a lot of data at
well-defined instants of time.
The best way of capturing the acquisition time is to
take advantage of the built-in timer functions, millis() and
micros(). They return the current elapsed time since the
Arduino was turned on in milliseconds and microseconds,
As long as I record the system time just before and
just after an analog measurement, I can get an accurate
measure of the actual time stamp for each data point. The
challenge was to determine how fast I could collect and
write the data.
Most online forums suggest using the built-in timer
functions like millis() or micros() to calculate the execution
times and print the results to the serial port. You just have
to add debug code to measure the time intervals between
sections of your code, print the times out to the serial
port, and read them with the serial monitor.
While this is a useful technique, I am a measurement
guy and like to use my scope and digital write pins to get
useful timing information of Arduino code. I think this is
an important technique as it gives a very visual window
into the time it takes for sections of code to execute. I use
38 June 2015
FIGURE 8. Screenshot from the Analog Discovery scope
showing the measured 10-90 rise time of the Arduino digital
signal of 16 nsec. This is limited by the scope. Its actual rise
time, measured with a faster scope, is 3 nsec.
FIGURE 7. The additional commands added in the void
setup() function to first clear the old data out and add labels
in the first row of the spreadsheet.
Avoid this common problem: Since the CLEARDATA
command erases all the data in the spreadsheet, make sure you
either want to remove the data or have a new worksheet set up in the
first tab position before you click the “connect” button.
Avoid this common problem: Even if you initialize a
timer as an unsigned long, the largest integer value it can hold is
4. 3 x 10^ 9. If this is in microseconds, the longest time you can
record before the timer resets is 4. 3 x 10^ 3 seconds, which is about
71 minutes. If you want to record data with a time stamp for a
longer time than 71 minutes, use the millis() timer. This can count up
1000x longer, or 49 days before resetting.