had something fun to offer as signals. In channel 1, I had a
simple one-turn pot connected between the + 5 and gnd.
In channel 2, I had a thermistor connected to + 5 with
a 10K resistor. All resistors change their resistance with
temperature. How much the resistance changes is
described by the temperature coefficient of resistance
(TCR). For a carbon resistor, it’s about 0.1% per degree C.
A thermistor turns this problem into a feature. Its TCR can
be as high as 5% per
The thermistor I
used from SparkFun was
nominally 10K ohms
with a 5% change per
degree C. Touching it
increased its resistance
by 20-40%. I turned it
into a simple resistor
voltage divider between
+ 5 and gnd.
In channel 3, I
added a simple light
sensitive resistor, also
from SparkFun. Its
nominal resistance in the dark was about 10K ohms, and it
could drop to 2K ohms in the light. Again, I just added it
to a simple voltage divider and measured the voltage
across the 10K resistor in series.
Using my digital Write triggers as a timer, I measured
the time it took to read a single analog channel, and then
to read all three channels sequentially. The code to do this
is shown in Figure 11. Reading one analog channel
increased the time for the low signal to be on from 5. 25
µs to 120.7 µs. This is about 115.5 µs for an analog read
command. When reading three channels consecutively,
the low bit time increased to 344.3 µs. Taking out the
digital Write overhead, this is (344.3 – 5. 25)/3 = 113 µs per
channel — very close to the measurement of the single
analog read. To be generous, I use the value of 120 µs as
the time to read an analog channel.
In principle, if there are no other functions going on, it
sounds like I could take one channel’s worth of data at a
sample rate of about 8 kHz. However, it’s what we do
with the data that will really slow things down.
How Long Does it Take to
For this first data acquisition system, I wanted the
fastest data acquisition I could easily get and have the
data go into an Excel spreadsheet with PLX-DAQ. The
limitation I quickly found was the print command to the
The first way to decrease the time to print to the serial
bus is to use the highest baud rate practical. The
difference in times to print using 9600 and 56000 is
almost (but not quite) the x5.8 difference in baud rate.
There is some overhead used in the
Printing one character at 56000 takes about 0.4 ms.
However, printing 30 characters takes about 5. 6 ms.
Depending on the number of characters in the data being
printed, the total print time in my code may vary from 2 to
40 June 2015
FIGURE 12. Measured timing diagram showing the relative time to print to the serial port
(top trace, on time) and the successive analog channel reads (bottom trace, on times). This shows
the many consecutive analog reads which were then averaged to arrive at one value per channel in
each sample interval.