Hardware Reference
In-Depth Information
voltage to control the volume, and to provide a clearer audio signal. The tone()
function generates a square wave, but unlike pulse width modulation, it has a
50% duty cycle, that is to say, it oscillates between a logical high and a logical
low, both phases being equal in length. It results in an audible tone, but cannot
represent a complex audio signal like voice.
CROSS REFERENCE
PWM is presented in Chapter 4.
Digital to Analog Converters
Digital to Analog Converters (DAC) can be used to generate waveforms and are
often used to create sine, triangle, and sawtooth waves. Because these devices
can create custom waveforms and because sound is also a waveform, they can
be used to create sound—and with relatively good precision.
WARNING Microcontrollers and DACs can generate signals but are not powerful
enough to power devices; they require an amplifi er to create a signal powerful enough
for a speaker to use. Connecting a speaker directly to the microcontroller can, and
probably will, damage the pin, maybe even the microcontroller.
A DAC is the opposite of an Analog to Digital Converter (ADC) but it uses
the same properties. A digital signal has a resolution; the amount of bits that are
used to create a signal. On the Arduino Due, the two DACs have 12-bit resolu-
tions; they can write values from 0 to 4,095. The analog output varies from one
analog value to another; on the Arduino Due, it varies from 0 V to +3.3 V, the
voltage of the Cortex-M microcontroller. Because the voltage range is 3.3 V and
because there are 4,096 possible values, the DAC has a precision of 3.3 divided
by 4,096, or approximately 0.000806. Each increment on the digital side will
result in a change of 0.8 mV on the analog side.
Digital Audio to Analog
Digital audio i les are essentially a representation of analog signals. It is therefore
easy to take each value and to write that value into a DAC, creating a waveform
that is close to the original audio. There are several factors to consider:
Resolution —The resolution of the digital audio i le is important; on most
computers, they are either 8 bits or 16 bits, but the Arduino Due's DAC
has a 12-bit resolution.
Speed —The original i le was sampled at a precise speed, and playing
back the audio data at a different speed would change the pitch.
Stereo or mono —Audio can be recorded as mono (single channel) or stereo
(dual channel). The Arduino Due can play only mono i les, so stereo i les
play back as mono; both channels convert to a single channel.
 
Search WWH ::




Custom Search