Revalogics
Well-known member
Hi guys, I discovered a way to use both ADC (mono audio in) and analogRead without interfering with each other.
I use the original libraries supplied by Teensyduino, without modifying any files in it.
Does this also work in you?
I use the original libraries supplied by Teensyduino, without modifying any files in it.
Code:
/****************************************************************
* Teensy 3.6 *
* Serial + MIDI + Audio, 180 MHz *
* Coded by Revalogics *
* Arduino IDE 1.6.12 / Teensyduino 1.33 *
* Running in Windows 8.1 *
****************************************************************
* This code streams mono audio from an analog input to USB *
* while blinking the built-in LED while sending a value of *
* another analog pin to the Serial Monitor. *
* *
* This only works using Mono ADC. Stereo ADC uses both ADC0 & *
* ADC1 and analogRead makes the code freeze(LED doesn't blink).*
* Setting the right channel pin in Stereo ADC does nothing *
* (A3 is still the right channel input). *
* *
* My assumption is maybe it is possible to use ADC0 for audio *
* and ADC1 for analogRead since there are two hardware ADCs in *
* Teensy 3.x. *
* *
* Audio + analogRead Possibilities, Here's what I found: *
* Audio Input + analogRead = status *
* ADC0 ADC0 code freezes, no audio, no blink *
* ADC1 ADC0 code freezes, no audio, no blink *
* ADC0 + ADC1 ADC0 code freezes, no audio, no blink *
* ADC0 ADC1 audio on, blinking, serial works *
* ADC1 ADC1 no audio, blinking, serial works *
* ADC0 + ADC1 ADC1 audio on, blinking, serial works * A2, A3 & A10 only, A11 = no audio, blinking, serial works
* *
* DAC0/A21 also works as an audio in. *
* *
* analogRead returns 16-bit values (65535 max) because the *
* Audio Library sets the analog read resolution to 16. *
* *
* This is useful to me because I want to sample and modulate *
* my voice while controlling the parameters of a synth/vocoder *
* using a potentiometer (analog pin). *
****************************************************************
* Source: [PDF] Kinetis K66 Sub-Family Datasheet, *
* in K66 Signal Multiplexing and Pin Assignments Section *
* *
* ADC0 analog pins * ADC1 analog pins *
* A0 (ADC0_SE5b) * A12 (ADC1_SE14) *
* A1 (ADC0_SE14) * A13 (ADC1_SE15) *
* A4 (ADC0_SE13) * A16 (ADC1_SE4b) *
* A5 (ADC0_SE12) * A17 (ADC1_SE5b) *
* A6 (ADC0_SE6b) * A18 (ADC1_SE6b) *
* A7 (ADC0_SE7b) * A19 (ADC1_SE7b) *
* A8 (ADC0_SE15) * A20 (ADC1_SE17) *
* A9 (ADC0_SE4b) * A22 (ADC1_SE23/DAC1_OUT) *
* A14 (ADC0_SE17) * A23 (ADC1_SE10) *
* A15 (ADC0_SE18) * A24 (ADC1_SE11) *
* A21 (ADC0_SE23/DAC0_OUT) * *
* *
* ADC0 + ADC1 analog pins *
* A2 (ADC0_SE8/ADC1_SE8) Default Left/Mono input *
* A3 (ADC0_SE9/ADC1_SE9) Default Right input *
* A10 (ADC1_DP0/ADC0_DP3) *
* A11 (ADC1_DM0/ADC0_DM3) *
****************************************************************/
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
AudioInputAnalog adc1(A0); // must use ADC0 or ADC0 + ADC1 analog pin here
AudioOutputUSB usb1;
AudioConnection patchCord1(adc1, 0, usb1, 0);
AudioConnection patchCord2(adc1, 0, usb1, 1);
elapsedMillis LED0timer;
void setup() {
Serial.begin(115200);
AudioMemory(16);
pinMode(13, 1); // 0 = input, 1 = output, 2 = input_pullup
digitalWrite(13, 1); //0 = low, 1 = high
}
void loop() {
if(LED0timer >= 0 && LED0timer <= 500) digitalWrite(13, 1);
if(LED0timer > 500 && LED0timer <= 1000) digitalWrite(13, 0);
if(LED0timer > 1000) {
Serial.println(analogRead(A12)); // must use ADC1 analog pin here
LED0timer = 0;
}
}
Does this also work in you?