AudioInputAnalog - Change ADC Reference Voltage

Status
Not open for further replies.
I am looking to use the Audio.h library on my Teensy 4.0 for a spectrum analysis project using FFT_1024. I have a non-inverting summing opamp circuit that centers the average of a stereo line audio output (-1.1V to +1.1v) around half an input voltage such that:

Code:
Vout = (Vin+Vsigl+Vsigr)/2

...where Vin is the input voltage, and Vsigl/r are the voltages of the left and right channel. Due to the nature of the project and having a Vppk ~2.2v, I intend on using the audio library with a reference voltage of 3.3v, but can't figure out how to set the analog reference voltage to 3.3, as this is the maximum voltage of my circuit. The library sets it to the internal 1.2v reference voltage. I have no intention of rebuilding my circuit, as I've run out of components and I'm stuck inside for a while because... you know.

I have found a few threads, but all of them were from 2018. In one, Paul mentioned that there are plans to include a method of switching the reference voltage, but I can't seem to find anymore information past that. That thread can be found here. I'm very much in the same position as this guy. I understand the reason for a 1.2V reference, but at line-level, this would lead to clipping of the signal and distortion of the FFT result, so I'm banking on finding a way to use a 3.3v reference. Unlike him though, I have tried to change the analogReference(INTERNAL) statement on line 51 of input_adc.cpp, but the preprocessor block it sits in is disabled by the lack of definition of KINETISK. See the picture of Visual Studio yelling at me below.
Capture.PNG

A bit stuck.
 
A bit disappointed that there was no reply. I'd love to use the Audio library to do this project, but I don't quite know where to start. For now I've gone the route of using analogRead to do it.
 
You're using Teensy 4.0 which does not have any 1.2 volt reference for its ADC. That hardware only exists on Teensy 3.x. On Teensy 4.0 the ADC always uses the 3.3V power as its reference. That's hard-wired inside the chip (why NXP did this I can not say) so you always get 3.3V reference no matter what you do in software.

Since you mentioned analogReference(INTERNAL) on line 51, my guess is you're working with an older version of this code. Teensyduino 1.52 is the first version to support AudioInputAnalog on Teensy 4.0. Even so, that support is still considered "experimental", as you can see in the design tool documentation (right side panel):

https://www.pjrc.com/teensy/gui/?info=AudioInputAnalog

The very first step is to get the latest code. Look for "#if defined(__IMXRT1062__)" at line 216. That is the code for Teensy 4.0.

https://github.com/PaulStoffregen/A...a7404157b83e44e9e10922f730/input_adc.cpp#L216

As you can guess from the many "TODO" comments, that code is quite new and still in need of much work. If you try to use it now, at the very least edit line 401 with a better guess of your circuitry's DC level.
 
Thank you so much for your input! I ended up piling thru the chip manual's ADC section and found no mention of changing the reference voltage, and without definitions for INTERNAL or DEFAULT in imxrt.h, I figured this was the case. I'll definitely take a look at those lines when I get back to the project; hoping to figure out how to get the library to work with it, but so far no such luck.
 
Status
Not open for further replies.
Back
Top