Squarewave coupled onto ADC on V1 board, but not on protoype. What's different?
Posted: 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:
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;
}
}