super loud click when reprogramming Teensy 4.1 with Audio board.

tigger

Active member
I'm getting a really loud click out of the headphone jack after I load a new sketch into the Teensy 4.1 with Audio Shield board (circuitry).
I have duplicated the circuitry of the TEENSY4_AUDIO (revD) on my custom board. Unfortunately I don't have an actual TEENSY4_AUDIO shield to try.
I only get the loud click after loading the sketch from the Teensy loader. Once the board is programmed, the normal power-up sequence doesn't create this click.
Anyway, is this a common problem?
If so, perhaps there is some known mitigation for such a problem?

I'm enabling the sgtl5000 in setup() like this...


C++:
void setup() {
    (setup pins and serial port here)
    
    delay(10000);  //10s delay to make sure the click noise is coming enable()
    sgtl5000_1.enable();  // loud click happening here, only after loading code from teensy loader.
    delay(10000);
    sgtl5000_1.inputSelect(AUDIO_INPUT_LINEIN);
    sgtl5000_1.dacVolumeRamp();
    sgtl5000_1.lineOutLevel(13);  //3.16V p-p
    sgtl5000_1.lineInLevel(0);    // 3.12V p-p
    sgtl5000_1.volume(0.80);

    (rest of setup here)
}
 
If someone happens to have headphones in their ears when they update the software, they get a very loud surprise--it's quite painful.
I know now not to have my headphones in when I update, and I'd put a warning message in with every unit i'd ship to someone. However, people do forget/ignore warnings ( i have forgotten a couple of times), so it'd be nice to mitigate the problem if i can.
 
Updating firmware is not a normal case, once its finished and working you stop doing it, so perhaps don't wear the headphones while uploading code? Perhaps the update is toggling some pins connected to the audio adapter leading to this, or its due to the reset when powered up?
 
Updating firmware is not a normal case, once its finished and working you stop doing it, so perhaps don't wear the headphones while uploading code? Perhaps the update is toggling some pins connected to the audio adapter leading to this, or its due to the reset when powered up?
Yeah, not wearing the hp is the easy solution (well assuming I can remember to do that when i'm deep in some iteration of another problem :) ).

It is definitely happening when the code calls sgtl5000_1.enable(), because I've isolated it with delays. I've have determined it happens because the code calls enable() when it has already been enabled (from the last power up before entering the bootloader mode).
I was able to get it to NOT make that noise if I skip the sgtl5000_1.enable() call after coming out of the bootloader mode. If it was already enabled then you don't need to enable it again and it works fine.

I don't see a way to tell if the sgtl5000 is already enabled, and the disable() function isn't wired up to do anything, so I can't just call disable() first and then call enable().
What I need to figured out is what register in the sgtl5000 I can read to reliably determine that it has already been enabled, so I can skip the enable() function. At least that's the only thing I can think of.

meanwhile, I'll just have to be careful and include the warning in any update instructions I give with a unit i ship to someone.
 
I found a work around--probably not necessary, but it was a challenge to figure it out...


Code:
// in control_sgtl5000.h
// in public area
    #define SGTL5000_CHECK_PWRON_DEFAULT
    unsigned int read_b4_enable(unsigned int reg); // ws, added to avoid enabling twice after exting bootloader

// in control_sgtl5000.cpp
// added


unsigned int AudioControlSGTL5000::read_b4_enable(unsigned int reg)
{
    unsigned int val;
    Wire.begin();
    delay(5);

    Wire.beginTransmission(i2c_addr);
    Wire.write(reg >> 8);
    Wire.write(reg);
    if (Wire.endTransmission(false) != 0) return 0;
    if (Wire.requestFrom((int)i2c_addr, 2) < 2) return 0;
    val = Wire.read() << 8;
    val |= Wire.read();
    return val;
}

// in my sketch in setup() i added...
    #ifdef SGTL5000_CHECK_PWRON_DEFAULT // defined in control_sgtl5000.h
    // ws added read_b4_enable() to avoid loud click due to calling enable() when already enabled
    // when coming out of bootloader
    #define SGTL5000_0030_PWRON_DEFAULT 0x7060
    unsigned int sgtl_val = sgtl5000_1.read_b4_enable((unsigned int)0x0030);
    if ( SGTL5000_0030_PWRON_DEFAULT == sgtl_val ){ 
        sgtl5000_1.enable();
    }
    else{
        String test_str= verNum_str +  "\n sgtl:\n 0x%04X";
        sprintf(str_oledbuf, test_str.c_str(), sgtl_val);
    }
    #else
        sgtl5000_1.enable();
    #endif
 
Back
Top