Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 11 of 11

Thread: Teensy 4.1 A2 input question

  1. #1
    Junior Member
    Join Date
    Sep 2020
    Posts
    11

    Teensy 4.1 A2 input question

    Hi Folks,

    yesterday I received my first Teensy4.1 (after using ++2.0 for long time) and i was very excited to try out the audio libary. In the end, I was very frustrated and now I hope you can help!

    I was trying the Example > Audio > Analysis > PeakMeterMono with the input at A2/16, but serial monitor shows nothing. I put a "Serial.print("AAA");" after the first "if(fps > 24)" and it was printed. If I put it after the 2nd if (peak1.available(), it's not printed.

    I tryed the advised circuit but also a funktion generator with adjustable offset without any result. On the serial monitor just happens nothing.

    After I made a test with the example "readPin" and this was working very fine. I supplyed an external DC Voltade to Pin 16 and got plausible values at the serial monitor. So the pin A2/16 and ADC seems to be ok.

    Do you have any ideas? I really have no plan what to do.
    Thanks a lot!

    Regards from Germany,
    Ben

  2. #2
    Senior Member
    Join Date
    Jul 2020
    Posts
    976
    T4 support for ADC input was unfinished I believe, I'm pretty sure this has been addressed for uncoming release
    though, but can't find the thread about it. You can probably fix this by adding an I2S output to your design, as
    I2S objects do fire up the main audio interrupt (and I think that's what's missing in the ADC handling).

    The way the audio library works is that there has to be at least one object capable of firing up suitable interrupts
    that will then drive the whole workflow. These are typical input and output objects related to actual hardware.

  3. #3
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    24,080
    It is indeed unfinished, but does partially work.

    Make sure you're using the latest beta. In Arduino, click Help > About to check which version you have installed. If it's older than 1.47-beta7, get the installer here:

    https://forum.pjrc.com/threads/66357...no-1-54-Beta-7

  4. #4
    Junior Member
    Join Date
    Sep 2020
    Posts
    11
    Thank you for your answers!
    The latest 1.54 beta7 is installed.
    What i did not mind yesterday, this massage appears while compiling:

    C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Audio\ output_i2s.cpp:340:55: warning: default argument given for parameter 1 of 'static void AudioOutputI2S::config_i2s(bool)' [-fpermissive]
    void AudioOutputI2S::config_i2s(bool only_bclk = false)
    ^
    In file included from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Audio\ output_i2s.cpp:28:0:
    C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Audio\ output_i2s.h:55:14: note: previous specification in 'static void AudioOutputI2S::config_i2s(bool)' here
    static void config_i2s(bool only_bclk = false);
    ^

  5. #5
    Senior Member
    Join Date
    Jul 2020
    Posts
    976
    Yes, pull request #390 is already in the system to fix this in the next release. The latest Audio lib repo already has this - the
    warnings are benign.

  6. #6
    Junior Member
    Join Date
    Sep 2020
    Posts
    11
    Thank you!
    Just to be sure that I understand it correctly:
    -> If I plug any I2S-device to the T4, the audio libary will probaply work. (audio shield for example)
    -> And if I wait for the next software release, it will also work without an additional I2S-device and directly into A2.
    Did you mean it?

  7. #7
    Senior Member
    Join Date
    Jul 2020
    Posts
    976
    Quote Originally Posted by BenJo View Post
    Thank you!
    Just to be sure that I understand it correctly:
    -> If I plug any I2S-device to the T4, the audio libary will probaply work. (audio shield for example)
    -> And if I wait for the next software release, it will also work without an additional I2S-device and directly into A2.
    Did you mean it?
    No need to plug anything in, just configure the i2s1 output object (it will flap the I2S pins (MCLK1/BCLK1/LRCLK1/OUT1A) so you can't use them for anything else)
    You just need something that's clocked to drive the audio interrupts, and this will do it.

  8. #8
    Junior Member
    Join Date
    Sep 2020
    Posts
    11
    I add the I2S output an now it works. Thank you so much!
    Just for better understanding: is there any technical reason, why many example sketches don't has this I2S already prepared? If I'm using a program without any output (like the peak meter), there is normally no need to care about the I2S output and this was the only reason why I needed your help!

  9. #9
    Senior Member
    Join Date
    Aug 2013
    Location
    Gothenburg, Sweden
    Posts
    413
    Perhaps a timerbased AudioUpdateEventClock object could be added to the library to drive the update cycle.

  10. #10
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    24,080
    Quote Originally Posted by BenJo View Post
    I add the I2S output an now it works. Thank you so much!
    Just for better understanding: is there any technical reason, why many example sketches don't has this I2S already prepared?
    ADC input is still experimental on Teensy 4.x. One of the many features it's missing is "update responsibility". That is why you need to add an I2S output to make it work.

    If you use ADC input on Teensy 3.x, this isn't necessary. And eventually when ADC input is improved, it won't be necessary on Teensy 4.x either.

    To explain a bit further about this internal audio library detail, one of the hardware input or output object you use must implement "update responsibility", which means it schedules a lower priority software interrupt every 128 audio samples, which causes the entire audio library to run. Except for USB, all the inputs and outputs do this, so it's not normally something you need to know.

    However, if you use only USB for input / output, you must include at least 1 hardware input or output. Likewise if you try to play a WAV file and do FFT analysis without actually sending the audio to any output. It is exactly the same situation where no hardware object is causing the audio library to update. The USB examples do indeed have an I2S object.

    Examples for ADC input do not because they were developed on Teensy 3.x. And eventually the ADC input on Teensy 4.x will get update responsibility. But it is not an easy thing to implement because NXP didn't provide a path in the clock tree for the ADC to run from the audio clocks (which is also the main reason ADC input wasn't done when Teensy 4.0 was released and still remains an experimental work in progress).

  11. #11
    Junior Member
    Join Date
    Sep 2020
    Posts
    11
    Thank you very much for this detailed explanation!
    Best Regards!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •