Just verifying that Audio library does not conflict with analogwrite

Status
Not open for further replies.

josechow

Well-known member
Using the Teensy 3.2

So I know there is an analogRead and Audio library conflict. In reference to page 649 of the K20P64 manual, this is due to conflicting ADC setup requirements for each, I am assuming. (without digging into the code for each)

but analogWrite/analogWriteResolution and the audio library should play nice together right? In reference to page 773/649 of the K20P64 manual, the only possible link between the ADC and PWM hardware would be a clock source, but the Flex Timers and the ADC module each have their own clock dividers, so this is a non-issue.

I want the Audio library to work on incoming audio to pin14 (A0) and have 3 pwm outputs for LED control at pins 5,6,9 on timer FTM0
 
So I know there is an analogRead and Audio library conflict.

Yes, but only if you use the ADC object. If your audio design doesn't use the ADC, analogRead() works fine.

but analogWrite/analogWriteResolution and the audio library should play nice together right?

Yes, you can use analogWrite(). Some of the input & output objects use various pins. Obviously when a pin is in use for I2S or PWM, you can't also use that pin with analogWrite().

I want the Audio library to work on incoming audio to pin14 (A0) and have 3 pwm outputs for LED control at pins 5,6,9 on timer FTM0

That should work fine, as long as you do not use the I2S objects. As you can see in the I2S object documentation (right side panel), I2S requires pin 9. If you also use I2S, you would need to choose a different pin for PWM output.

While unrelated to software, you should also consider grounding carefully. PWM waveforms to high-current devices can create considerable noise on nearby analog signals, by capacitive coupling, ground loops, and other subtle analog issues.

If using the SGTL5000 chip, you could set the PWM frequency to about 100 kHz and the ADC inside the codec chip would be able to reject it, because it has oversampling and digital filtering built in. But the on-chip ADC samples only at 44.1 kHz without any special filtering. High frequency noise will Nyquist alias and corrupt your signal. The need for careful low-noise analog design is even greater when using the on-chip ADC.
 
Status
Not open for further replies.
Back
Top