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

Thread: Pitch Detection on an ADC input

  1. #1
    Senior Member
    Join Date
    Feb 2015
    Posts
    160

    Pitch Detection on an ADC input

    Has anyone gotten pitch detection to work on an ADC input pin?

    I am trying to do this and all I get out of serial is garbage, and then it freezes.

    Here is the code I am trying:

    Code:
    #include <Audio.h>
    #include <SPI.h>
    #include <Wire.h>
    
    #define kSerialSpeed 115200
    
    AudioInputAnalog              adc(A6);
    AudioAnalyzeNoteFrequency     notefreq;
    
    AudioConnection               patchCord1(adc, 0, notefreq, 0);
    
    void setup() {
      AudioMemory(30);
      notefreq.begin(.15);
      Serial.begin(kSerialSpeed);
    }
    
    void loop() {
    
      if (notefreq.available()) {
        float note = notefreq.read();
        float prob = notefreq.probability();
        Serial.printf("Note: %3.2f | Probability: %.2f\n", note, prob);
      }
    
    }
    I have tried various values for the threshold with no luck. Also tried various clock speeds. I know of the bug at 72Mhz for the ADC input. Also have tried a second Teensy! Peak detection seems to work fine, but no go for noteFreq.
    Last edited by tenkai; 08-22-2016 at 02:02 AM.

  2. #2
    Senior Member
    Join Date
    Oct 2013
    Location
    Rogersville MO
    Posts
    253
    Are you using Paul's circuit to bias the ADC input?

  3. #3
    Senior Member
    Join Date
    Feb 2015
    Posts
    160
    Not Paul's circuit, but I am biasing the ADC input to be within 0-3v3. I realize that the ADC input is by default 0-1.6v, but I changed the ADC input library to use external 3v3 as reference.

    I verified that the teensy is recognizing the signal by mirroring the ADC input to the DAC and the waveforms are similar:

    Click image for larger version. 

Name:	IMG_8251.jpg 
Views:	54 
Size:	162.4 KB 
ID:	7912

    Top is DAC output, Bottom is the wave that is being sent to the ADC (through an op amp circuit designed to convert bipolar 5v to 0-3v3)

    Regardless, even if there is nothing connected, the above code never makes it past notefreq.begin(.15)

    Can someone else try this for a sanity check for me?

  4. #4
    Senior Member
    Join Date
    Feb 2015
    Posts
    160
    As a data point, I can use FFT just fine and analyze signals that way, but noteFreq does not work for me.

  5. #5
    Senior Member
    Join Date
    Oct 2013
    Location
    Rogersville MO
    Posts
    253
    My hardware is using Paul's bias circuit on A2, using A2 instead of A6 everything is working.

    Note: 1092.84 | Probability: 0.96
    Note: 1092.60 | Probability: 0.99
    Note: 1092.79 | Probability: 0.99
    Note: 1092.03 | Probability: 0.99
    Note: 1092.40 | Probability: 0.99
    Note: 1092.33 | Probability: 0.99
    Note: 1092.44 | Probability: 0.99
    Note: 1092.31 | Probability: 0.99
    Note: 1092.52 | Probability: 0.99
    Note: 1092.67 | Probability: 0.99
    Note: 1092.39 | Probability: 0.99
    Note: 1092.41 | Probability: 0.99
    Note: 1092.57 | Probability: 0.99
    Note: 1092.18 | Probability: 0.99

  6. #6
    Senior Member
    Join Date
    Oct 2013
    Location
    Rogersville MO
    Posts
    253
    Arduino 1.6.11
    T1.30 beta 3

  7. #7
    Senior Member
    Join Date
    Feb 2015
    Posts
    160
    What frequency are you running at?

    I think I must have something funky going on in my installation. I will have to re-install everything tomorrow and see where we are at.

    Good news is that in all this, I wrote code to set the reference voltage for the ADC pin. I did a pull request, but I think I actually need to do a bit more testing first.

  8. #8
    Senior Member
    Join Date
    Feb 2015
    Posts
    160
    I can get this to work fine now with regular arduino and T1.29. I usually use Platform IO and I think there is something funky going on there!

Posting Permissions

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