Efficient analog input functions for sensors and audio. More...
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.
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(). | |
template<byte RES> | |
uint16_t | mozziAnalogRead (uint8_t pin) |
See mozziAnalogRead(). More... | |
uint16_t | mozziAnalogRead16 (uint8_t pin) |
See mozziAnalogRead() but always returns the value shifted to 16 bit range. More... | |
template<byte RES> | |
uint16_t | getAudioInput () |
See getAudioInput(). More... | |
template<byte RES> | |
uint16_t | getAudioInput16 () |
See getAudioInput(). More... | |
|
inline |
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 111 of file mozzi_analog.h.
|
inline |
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.
channel_num | the analog input channel you wish to use. |
Definition at line 86 of file mozzi_analog.h.
uint16_t getAudioInput | ( | ) |
See getAudioInput().
This returns audio input from the input buffer, if @ref MOZZI_AUDIO_INPUT is enabled in the config (see also the related option MOZZI_AUDIO_INPUT_PIN).
The template parameter specifies the desired value range in bits.
The audio signal needs to be in the range 0 to VCC volts (i.e. 5 volts on Arduino Uno R3). 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
Definition at line 172 of file MozziGuts.h.
|
inline |
uint16_t mozziAnalogRead | ( | uint8_t | pin | ) |
See mozziAnalogRead().
Reads the analog input of a chosen channel, without blocking other operations from running.
The template parameter RES specifies the number of bits to return.
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.
pin_or_channel | the analog pin or channel number. |
Definition at line 174 of file mozzi_analog.h.
|
inline |
See mozziAnalogRead() but always returns the value shifted to 16 bit range.
THis is exactly equivalent to mozziAnalogRead<16>(pin);
Definition at line 152 of file mozzi_analog.h.
|
inline |
Reconnect the digital input buffer for an analog input channel which has been set for analog input with disconnectDigitalIn().
channel_num | the analog input channel you wish to reconnect. |
Definition at line 99 of file mozzi_analog.h.
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/
speed | FAST_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. |