Efficient analog input functions for sensors and audio. More...
|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...|
|Prepare all analog input channels by turning off their digital input buffers. More...|
|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...|
|This returns audio input from the input buffer, if #define USE_AUDIO_INPUT true is in the Mozzi/mozzi_config.h file. 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.
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 https://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.|
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 https://electronics.stackexchange.com/questions/14404/dc-biasing-audio-signal and https://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 https://www.instructables.com/id/Arduino-Audio-Input/?ALLSTEPS
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.
|pin_or_channel||the analog pin or channel number.|
|void setupFastAnalogRead||(||int8_t||speed = ||)|
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: https://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1208715493/11, and https://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: https://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.|