Squarewave coupled onto ADC on V1 board, but not on protoype. What's different?

twinotter
Posts: 2
Joined: Thu Apr 12, 2018 2:48 pm

Squarewave coupled onto ADC on V1 board, but not on protoype. What's different?

Postby twinotter » Mon Dec 30, 2019 5:17 am

I'm digitizing a short audio signal using IO36 (A1_0) at 20Khz with the code below. It works on an Adafruit Huzzah32, but not on my prototype board. I'm trying to figure out why.

I'm seeing a 347 Hz square wave coupled to the actual audio signal. The square wave does not show up on the pin on an oscilloscope, but the audio signal does as expected. I've checked both boards with the same code loads (minus MISO and MOSI which changed places). Both are ESP32-WROOM-32. The prototype is on an Adafruit Feather (huzzah32). The other was bought from Mouser. Both seem functional in every other way. Both codeloads compiled in Arduino 1.8.9 with 1.0.4 of the esp32 boards from espressif, board set to ESP Dev Module.... Any ideas of what I should even look at?

Thanks!
Rudy

Digitization code:

Code: Select all

// ideally replace this whole thing with an IIS read, with frequency of the bus set to your sample frequency
unsigned long sampletime = 0;
void sampleSound() {
    unsigned long currenttime;
    
    for (int i = 0; i < SAMPLES; i++)
    {
      if ( i == 0) sampletime = micros(); // this could be a problem if you hit this routine too fast... but it should work out. and it keeps our spacing accurate
      
      currenttime = micros();
      if (currenttime < sampletime) {
        // wait
        if (currenttime < sampletime - 4) {
          // for longer delays, give control back to the system
          delayMicroseconds( sampletime - currenttime - 1 ); // ensures we will wait in the while loop for a moment
        }
        while (micros() < sampletime) { // wait until sampletime
          // this would be a good place for an ASM NOP instruction
        }
      }

      vReal[i] = analogRead(ADC_PIN);

      sampletime = sampletime + sampling_period_us;
    }
}

twinotter
Posts: 2
Joined: Thu Apr 12, 2018 2:48 pm

Re: Squarewave coupled onto ADC on V1 board, but not on protoype. What's different?

Postby twinotter » Mon Dec 30, 2019 7:04 pm

I spent some time with this on the oscilloscope and realized that the problem is my status line from a LIPO charging circuit. It's connected to I34 which is the VDET_1 line input and one of the inputs to SAR ADC1. That is where the square wave is coming from - in this case oscillating between High and High-Z. The battery is not attached. The square wave frequency (and duty cycle) is coming about because of the capacitor across where the battery would be attached. The LIPO charger is a MAX73831 and it's trying to show that charge is complete (because voltage is above the charge voltage) and that there is no battery (presumably because the charge voltage drops below a threshold). It probably shouldn't behave that way, but that's another story.

I still don't know why the signal is coupling onto the ADC channel. I've verify that the digitizer is set to the correct channel. This is a WROOM module, so there is a coupling cap between my chosen input (IO36 / SENSOR_VP) and another input. But that input is SENSOR_CAPP, not VDET_1.

Any ideas why this signal is coupling across to my input?

In the meantime, I'm trying set the input to have a pullup, which should mask the High-Z state from the LIPO Stat output...

Who is online

Users browsing this forum: No registered users and 14 guests