Mozzi  version v1.1.0
sound synthesis library for Arduino
Analog

Efficient analog input functions for sensors and audio. More...

Functions

void setupFastAnalogRead (int8_t speed=FAST_ADC)
 
This is automatically called in startMozzi. More...
 
void disconnectDigitalIn (uint8_t channel_num)
 Prepare an analog input channel by turning off its digital input buffer. More...
 
void reconnectDigitalIn (uint8_t channel_num)
 Reconnect the digital input buffer for an analog input channel which has been set for analog input with disconnectDigitalIn(). More...
 
void adcDisconnectAllDigitalIns ()
 Prepare all analog input channels by turning off their digital input buffers. More...
 
void adcReconnectAllDigitalIns ()
 Reconnect the digital input buffers for analog input channels which have been set for analog input with disconnectDigitalIn().
 
int mozziAnalogRead (uint8_t pin)
 Reads the analog input of a chosen channel, without blocking other operations from running. More...
 
int getAudioInput ()
 This returns audio input from the input buffer, if #define USE_AUDIO_INPUT true is in the Mozzi/mozzi_config.h file. More...
 

Detailed Description

Efficient analog input functions for sensors and audio.

Helps produce glitch-free audio by allowing analog input functions which normally block processing to be performed in the background.

Function Documentation

◆ adcDisconnectAllDigitalIns()

void adcDisconnectAllDigitalIns ( )

Prepare all analog input channels by turning off their digital input buffers.

This helps to reduce noise, increase analog reading speed, and save power.

Definition at line 103 of file mozzi_analog.cpp.

◆ disconnectDigitalIn()

void disconnectDigitalIn ( uint8_t  channel_num)

Prepare an analog input channel by turning off its digital input buffer.

This helps to reduce noise, increase analog reading speed, and save power.

Here's more detail from http://www.openmusiclabs.com/learning/digital/atmega-adc/:

The DIDR (Data Input Disable Register) disconnects the digital inputs from whichever ADC channels you are using. This is important for 2 reasons. First off, an analog input will be floating all over the place, and causing the digital input to constantly toggle high and low. This creates excessive noise near the ADC, and burns extra power. Secondly, the digital input and associated DIDR switch have a capacitance associated with them which will slow down your input signal if you are sampling a highly resistive load.

And from the ATmega328p datasheet, p266:

When an analog signal is applied to the ADC pin and the digital input from this pin is not needed, this bit should be written logic one to reduce power consumption in the digital input buffer. Note that ADC named_pins ADC7 and ADC6 do not have digital input buffers, and therefore do not require Digital Input Disable bits.

Parameters
channel_numthe analog input channel you wish to use.

Definition at line 89 of file mozzi_analog.cpp.

◆ getAudioInput()

int getAudioInput ( )

This returns audio input from the input buffer, if #define USE_AUDIO_INPUT true is in the Mozzi/mozzi_config.h file.

The pin used for audio input is set in Mozzi/mozzi_config.h with #define AUDIO_INPUT_PIN 0 (or other analog input pin). The audio signal needs to be in the range 0 to 5 volts. Circuits and discussions about biasing a signal in the middle of this range can be found at http://electronics.stackexchange.com/questions/14404/dc-biasing-audio-signal and http://interface.khm.de/index.php/lab/experiments/arduino-realtime-audio-processing/ . A circuit and instructions for amplifying and biasing a microphone signal can be found at http://www.instructables.com/id/Arduino-Audio-Input/?ALLSTEPS

Returns
audio data from the input buffer

Definition at line 160 of file MozziGuts.cpp.

◆ mozziAnalogRead()

int mozziAnalogRead ( uint8_t  pin)

Reads the analog input of a chosen channel, without blocking other operations from running.

It actually returns the most recent analog reading and puts the chosen pin or channel on the stack of channels to be read in the background before the next control interrupt.

Parameters
pin_or_channelthe analog pin or channel number.
Returns
the digitised value of the voltage on the chosen channel, in the range 0-1023. that non-AVR hardware may return a different range, e.g. 0-4095 on STM32 boards.

Definition at line 229 of file mozzi_analog.cpp.

◆ reconnectDigitalIn()

void reconnectDigitalIn ( uint8_t  channel_num)

Reconnect the digital input buffer for an analog input channel which has been set for analog input with disconnectDigitalIn().

Parameters
channel_numthe analog input channel you wish to reconnect.

Definition at line 96 of file mozzi_analog.cpp.

◆ setupFastAnalogRead()

void setupFastAnalogRead ( int8_t  speed = FAST_ADC)


This is automatically called in startMozzi.

It makes mozziAnalogRead() happen faster than the standard Arduino analogRead(), changing the duration from about 105 in unmodified Arduino to about 16 microseconds for a dependable read with the default speed parameter FAST_ADC. If you want to set on of the faster modes (see params) you can call this after startMozzi(). See: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1208715493/11, and http://www.marulaberry.co.za/index.php/tutorials/code/arduino-adc/

Parameters
speedFAST_ADC, FASTER_ADC or FASTEST_ADC. If no parameter is supplied, the default is FAST_ADC, which sets the analog conversion clock predivide rate to 16, giving 1Mhz on a 16MHz board, the fastest rate for which behaviour is defined (~16us per sample). However, divisors of 8 and 4 also show usable results in the graphs in this paper: http://dam.mellis.org/Mellis%20-%20Sensor%20Library%20for%20Arduino%20-%20Paper.pdf, so you can also try FASTER_ADC or FASTEST_ADC for divide rates of 8 or 4, giving times of about 8us or 4us per sample. Beware, reliable results will depend on the sort of input signal you have. Only use FASTER_ADC or FASTEST_ADC if you know what you're doing.

Definition at line 39 of file mozzi_analog.cpp.