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

Thread: Teensy 4.0 S/PDIF3 glitches with Serial output

  1. #1

    Teensy 4.0 S/PDIF3 glitches with Serial output

    I tried a simple program where I just generated a sine wave with AudioSynthWaveform and send it to AudioOutputSPDIF3. It works fine and I can receive the S/PDIF signal and see the sine wave just fine. However, then I added a delay(10) and a Serial.print('.') in a loop and I get a glitch on the sine wave every 10ms. It looks like 12 samples are from some other part of the waveform.Click image for larger version. 

Name:	glitch.jpg 
Views:	9 
Size:	30.5 KB 
ID:	28826

    I am using PlatformIO and viewing my print output on the built-in terminal, but I also tried using TeraTerm to view the serial output with the same results. When there is no terminal output, the sine wave looks good and when there is terminal output, the sine wave has glitches.

    I also tried using Serial1 instead of Serial so that it prints to a real serial port instead of the USB serial port. The sine wave looks fine in that case, so it just seems to be the USB serial port.

    Has anyone else run into this problem?

  2. #2
    Here's my code:

    #include <Arduino.h>
    #include <Audio.h>

    AudioSynthWaveform sinegen; // generate waveform for test
    float SINE_LEVEL = 0.5; // sine amplitude (max is 1)
    float SINE_FREQ = 100; // sine frequency [Hz]

    AudioOutputSPDIF3 spdif1; // SPDIF3 is output on GPIO14
    AudioConnection patchCord1(sinegen, 0, spdif1, 0);
    AudioConnection patchCord2(sinegen, 0, spdif1, 1);

    void setup() {
    AudioMemory(60); // Audio connections require memory to work.
    Serial.begin(115200); // the baud rate is ignored for USB serial
    while (!Serial) {
    // wait for Arduino Serial Monitor to be ready
    }
    sinegen.begin(SINE_LEVEL, SINE_FREQ, WAVEFORM_SINE); // generate sine wave
    Serial.print("starting");

    }


    void loop() {
    delay(10);
    Serial.print('.');
    }

  3. #3
    Senior Member
    Join Date
    Apr 2021
    Location
    Cambridgeshire, UK
    Posts
    395
    Which version of Teensyduino are you using? There’s a fix for this issue in 1.57 beta 3.

    Pro tip: using th code tags (# button) will make your code more readable on the forum.

  4. #4
    I'm using Platformio with the framework-arduinoteensy v1.56 package. Any idea how I can get it to use the 1.57 beta 3? Can I install the beta 3 version into the Arduino IDE and then copy the changed files from the Arduino directories to the Platformio directories?

  5. #5
    Senior Member
    Join Date
    Apr 2021
    Location
    Cambridgeshire, UK
    Posts
    395
    I don't use Platformio myself, so no real idea, but your suggestion of installing the Arduino beta then copying the required change across sounds viable. The only changed file you'd need to fix your stated issue this is output_spdif3.cpp.

  6. #6
    I copied the 1.57 beta 3 output_spdif3.cpp file to overwrite the 1.56 version and then my S/PDIF output was glitch free.

    Thanks so much!

  7. #7
    Senior Member
    Join Date
    Apr 2021
    Location
    Cambridgeshire, UK
    Posts
    395
    Excellent news! You’re very welcome - that’s one of the things a forum is for…

Posting Permissions

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