![]() |
Mozzi
alpha 0.01.1t
sound synthesis library for Arduino
|
Functions | |
void | initADC () |
Call this in setup() to enable reading analog inputs in the background while audio generating continues. | |
void | startRead () |
Call startRead() at the end of each updateControl() and the reading will happen in the background, using a minimum of processor time and without blocking other code. | |
int | getSensor (unsigned char channel_num) |
This returns the current analog reading for the specified channel. | |
void | setupFastAnalogRead () |
Make analogRead() faster than the standard Arduino version, changing the duration from about 105 in unmodified Arduino to 15 microseconds for a dependable analogRead(). | |
void | disconnectDigitalIn (byte channel_num) |
Prepare an analog input channel by turning off its digital input buffer. | |
void | reconnectDigitalIn (byte channel_num) |
Reconnect the digital input buffer for an analog input channel which has been set for analog input with disconnectDigitalIn(). | |
void | startAnalogRead (unsigned char pin) |
Starts an analog-to-digital conversion of the voltage at a specified pin. | |
int | receiveAnalogRead () |
Waits for the result of the most recent startAnalogRead(). |
void disconnectDigitalIn | ( | byte | 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 ADC5..0 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 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 148 of file mozzi_analog.cpp.
int getSensor | ( | unsigned char | channel_num | ) |
This returns the current analog reading for the specified channel.
channel_num | The channels are plain numbers 0 to 5, not the pin labels A0 to A5 which Arduino maps to different numbers depending on the board being used. |
Definition at line 108 of file mozzi_analog.cpp.
void initADC | ( | ) |
Call this in setup() to enable reading analog inputs in the background while audio generating continues.
Then call startRead() at the end of each updateControl() and the results for each analog channel will be available by calling getSensor(channel_num) next time updateControl() runs.
Definition at line 34 of file mozzi_analog.cpp.
int receiveAnalogRead | ( | ) |
Waits for the result of the most recent startAnalogRead().
If used as the first function of updateControl(), to receive the result of startAnalogRead() from the end of the last updateControl(), there will probably be no waiting time, as the ADC conversion will have happened in between interrupts. This is a big time-saver, since you don't have to waste time waiting for analogRead() to return (1us here vs 105 us for standard Arduino).
Definition at line 241 of file mozzi_analog.cpp.
void reconnectDigitalIn | ( | byte | channel_num | ) |
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 159 of file mozzi_analog.cpp.
void setupFastAnalogRead | ( | ) |
Make analogRead() faster than the standard Arduino version, changing the duration from about 105 in unmodified Arduino to 15 microseconds for a dependable analogRead().
Put this in setup() if you intend to use analogRead() with Mozzi, to avoid glitches. 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/
Definition at line 123 of file mozzi_analog.cpp.
void startAnalogRead | ( | unsigned char | pin | ) |
Starts an analog-to-digital conversion of the voltage at a specified pin.
Unlike Arduino's analogRead() function which waits until a conversion is complete before returning, startAnalogRead() only sets the conversion to begin, so you can use the cpu for other things and call for the result later with receiveAnalogRead(). This works well in updateControl(), where you can call startAnalogRead() and get the result with receiveAnalogRead() the next time the updateControl() interrupt runs.
pin | is the analog pin number to sample from, A0 to A5 (or whatever your board goes up to). |
Definition at line 183 of file mozzi_analog.cpp.
void startRead | ( | ) |
Call startRead() at the end of each updateControl() and the reading will happen in the background, using a minimum of processor time and without blocking other code.
The results for each analog channel are available by calling getSensor(channel_num) next time updateControl() runs.
More detail: startRead() starts an initial conversion which triggers an interrupt when it's complete. The interrupt code stores the result in an array, changes to the next channel and starts another conversion. When all the channels have been sampled, the ISR doesn't start a new conversion, so it doesn't re-trigger itself or use processor time until startRead() is called again. At any time the latest conversion result for each channel is available by calling getSensor(channel_num).
Definition at line 56 of file mozzi_analog.cpp.