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

Thread: Popping noise coming from teensy when connected to audio board

  1. #1

    Popping noise coming from teensy when connected to audio board

    I have been working on a pretty big FM synthesizer project for the past couple of months now. I am using a teensy 4.1. I have been limited on pins and have resorted to only using pins 7,8,13,18,19,20,21,23 for the audio board, which has worked just fine on its own. I ran my code with everything connected and encountered humming and popping and terrible electrical noise from the teensy so I turned it off and ran a simple sine wave through it, and now I am getting constant clicks and pops from the board. I tried replacing the audio board but had the same problem. If anyone would happen to have any ideas on how to fix this I’m all ears! (Setting the amplitude of the sine wave lower did not fix it btw)Click image for larger version. 

Name:	IMG_0070.jpg 
Views:	32 
Size:	272.1 KB 
ID:	28083

  2. #2
    Senior Member
    Join Date
    Jul 2020
    Posts
    1,858
    Could be a code issue. Perhaps you forgot to up the AudioMemory enough as the system became more complicated?

    Anyway post your code if you want help on this.

    I'd be a little worried by the long wires for the I2S bus to the audio adapter - piggybacking the boards is superior for signal
    integrity particularly of the MCLK line. Make sure both ground pins are connected between Teensy and adapter.

  3. #3
    Apologies for the unusual/sloppy code, just needed something functional for the time being. Thanks for the help!

    Code:
    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <SerialFlash.h>
    #include <LiquidCrystal.h>
    #include "Variables.h"
    
    #define REDLITE 33
    #define GREENLITE 36
    #define BLUELITE 37
    
    // GUItool: begin automatically generated code
    AudioSynthWaveform       waveform1;      //xy=231,240
    AudioOutputI2S           i2s1;           //xy=390,239
    AudioConnection          patchCord1(waveform1, 0, i2s1, 0);
    AudioConnection          patchCord2(waveform1, 0, i2s1, 1);
    AudioControlSGTL5000     sgtl5000_1;     //xy=403,300
    // GUItool: end automatically generated code
    
    
    LiquidCrystal lcd (16, 22, 24, 25, 28, 29);
    
    namespace mux
    {
      byte s0 = 6;
      byte s1 = 9;
      byte s2 = 10;
      int muxIn0 = A2;
      int muxIn1 = A3;
      int muxIn2 = A12;
    }
    
    namespace shiftReg
    {
      const int dataPin = 12;  
      const int clockPin = 14;  
      const int latchPin = 11;  
      
      const int numBits = 8;
    
      byte lastState = LOW;
      unsigned long lastStateChange = 0;
    }
    
    namespace globEnc
    {
      byte encoder0PinA = 0;
      byte encoder0PinB = 1;
      int encoder0Pos0 = 0;
      int encoder0PinALast0 = LOW;
      int n0 = LOW;
    
      byte encoder0PinC = 2;
      byte encoder0PinD = 3;
      int encoder0Pos1 = 0;
      int encoder0PinALast1 = LOW;
      int n1 = LOW;
    
      byte encoder0PinE = 4;
      byte encoder0PinF = 5;
      int encoder0Pos2 = 0;
      int encoder0PinALast2 = LOW;
      int n2 = LOW;
    }
    
    namespace opCtrl
    {
      float ratioVal[21] = {0.16667,0.1818,0.2,0.2222,0.25,0.2857,0.33333,0.4,0.5,0.25,1.0,1.5,2.0,2.5,3.0,3.5,4.0,4.5,5.0,5.5,6.0};
      float ratio0 = 1.0;
      float ratio1 = 1.0;
      float ratio2 = 1.0;
    }
    
    namespace ctrls
    { 
      byte fmLoc1;
      float amp1;
      float fdbk1;
      byte fdbkLoc1;
    
      byte fmLoc2;
      float amp2;
      float fdbk2;
      byte fdbkLoc2;
      
      byte fmLoc3;
      float amp3;
      float fdbk3;
      byte fdbkLoc3;
    
      float coarse;
      float fine;
      float amp0;
      float fdbk0;
      byte fdbkLoc0;
    
      int att;
      int hol;
      int dec;
      int sus;
      int rel;
    
      int fulatt;
      int fulhol;
      int fuldec;
      int fulsus;
      int fulrel;
    }
    
    void setup () 
    {
      Serial.begin (115200);
      
      AudioMemory (300);
      AudioNoInterrupts ();
      sgtl5000_1.enable ();
      sgtl5000_1.volume(0.45);
      waveform1.begin (WAVEFORM_SINE);
      waveform1.amplitude (0.45);
      waveform1.frequency (264);
    
      usbMIDI.setHandleNoteOff (midiNoteOff);
      usbMIDI.setHandleNoteOn (midiNoteOn);
    
      using namespace globEnc;
      
      pinMode (encoder0PinA, INPUT);
      pinMode (encoder0PinB, INPUT);
      pinMode (encoder0PinC, INPUT);
      pinMode (encoder0PinD, INPUT);
      pinMode (encoder0PinE, INPUT);
      pinMode (encoder0PinF, INPUT);
      
      using namespace mux;
     
      pinMode (s0, OUTPUT);
      pinMode (s1, OUTPUT);
      pinMode (s2, OUTPUT);
    
      using namespace shiftReg;
      
      pinMode (dataPin, INPUT);
      pinMode (clockPin, OUTPUT);
      pinMode (latchPin, OUTPUT);
    
      lcd.begin (20, 4);
    
      lcd.print ("RGB 20x4 Display  ");
      lcd.setCursor (0,1);
      lcd.print (" Multicolor LCD ");
      
      pinMode (REDLITE, OUTPUT);
      pinMode (GREENLITE, OUTPUT);
      pinMode (BLUELITE, OUTPUT);
    }
    
    
    void loop () 
    {
      usbMIDI.read ();
      
      updateMux ();
      
      encoder ();
    
      sRegister ();
    
      lcdHello ();
    }
    
    void updateMux () 
    {
      using namespace mux;
      
      using namespace ctrls;
      
      for (byte state = 0; state < 8; state++)
      {
        digitalWrite (s0, HIGH && (state & B00000001));
        digitalWrite (s1, HIGH && (state & B00000010));
        digitalWrite (s2, HIGH && (state & B00000100));  
        
        switch (state)
        {
        case 0: amp2 = analogRead (muxIn0);
                amp3 = analogRead (muxIn1);
                fulatt = analogRead (muxIn2);       
        break;   
        
        case 1: fdbk1 = analogRead (muxIn0);
                fdbk3 = analogRead (muxIn1);
                fulrel = analogRead (muxIn2);
        break;  
        
        case 2: amp1 = analogRead (muxIn0);
                rel = analogRead (muxIn1); 
                fuldec = analogRead (muxIn2);
        break;
        
        case 3: fdbk2 = analogRead (muxIn0);       
        break;
        
        case 4: amp0 = analogRead (muxIn0);
                sus = analogRead (muxIn1);  
        break; 
           
        case 5: coarse = analogRead (muxIn0);
        break;  
          
        case 6: fdbk0 = analogRead (muxIn0);
                dec = analogRead (muxIn1);  
                fulsus = analogRead (muxIn2);                    
        break;
           
        case 7: fine = analogRead (muxIn0); 
                att = analogRead (muxIn1);  
        break;   
        }
      }
    }
    
    void sRegister ()
    {
      using namespace shiftReg;
      
      digitalWrite(latchPin, LOW);
      digitalWrite(latchPin, HIGH);
    
      for (int x = 0; x < numBits; x++) {
    
        if (millis () - lastStateChange > 100) {
          byte currentState = digitalRead (dataPin);
          
          if (currentState != lastState) {
            lastStateChange = millis();
            lastState = currentState;
            
            if (currentState == LOW) {
              Serial.print(x);
              Serial.print(": ON");
              Serial.println();
            }
          }
        } 
        digitalWrite (clockPin, HIGH);
        digitalWrite (clockPin, LOW);
      }
    }
    
    void encoder ()
    {
      using namespace globEnc;
    
      using namespace opCtrl;
      
      n0 = digitalRead (encoder0PinA);
      if ((encoder0PinALast0 == LOW) && (n0 == HIGH)) 
      {
        if (digitalRead (encoder0PinB) == LOW) 
        {
          encoder0Pos0 = encoder0Pos0 + 1;
          if (encoder0Pos0 > 30)
          {
            encoder0Pos0 = 30;
          }
        } else {
          encoder0Pos0 = encoder0Pos0 - 1;
          if (encoder0Pos0 < 1)
          {
            encoder0Pos0 = 1;
          }
        }  
        if (encoder0Pos0 < 15) {
          float x = encoder0Pos0;
          x = x / 15.0;
          Serial.println(x);
        } 
        if (encoder0Pos0 > 15) {
          float x = encoder0Pos0;
          x = x - 15.0;
          Serial.println(x);
        }      
      }
      encoder0PinALast0 = n0;
    
      n1 = digitalRead (encoder0PinC);
      if ((encoder0PinALast1 == LOW) && (n1 == HIGH)) 
      {
        if (digitalRead (encoder0PinD) == LOW) 
        {
          encoder0Pos1 = encoder0Pos1 + 1;
          if (encoder0Pos1 > 30)
          {
            encoder0Pos1 = 30;
          }
        } else {
          encoder0Pos1 = encoder0Pos1 - 1;
          if (encoder0Pos1 < 1)
          {
            encoder0Pos1 = 1;
          }
        }  
        if (encoder0Pos1 < 15) {
          float x = encoder0Pos1;
          x = x / 15.0;
          Serial.println (x);
        } 
        if (encoder0Pos1 > 15) {
          float x = encoder0Pos1;
          x = x - 15.0;
          Serial.println (x);
        }         
      }
      encoder0PinALast1 = n1;
      
      n2 = digitalRead (encoder0PinE);
      if ((encoder0PinALast2 == LOW) && (n2 == HIGH)) 
      {
        if (digitalRead (encoder0PinF) == LOW) 
        {
          encoder0Pos2 = encoder0Pos2 + 1;
          if (encoder0Pos2 > 30)
          {
            encoder0Pos2 = 30;
          }
        } else {
          encoder0Pos2 = encoder0Pos2 - 1;
          if (encoder0Pos2 < 1)
          {
            encoder0Pos2 = 1;
          }
        }  
        if (encoder0Pos2 < 15) {
          float x = encoder0Pos2;
          x = x / 15.0;
          Serial.println (x);
        } 
        if (encoder0Pos2 > 15) {
          float x = encoder0Pos2;
          x = x - 15.0;
          Serial.println (x);
        }    
      }
      encoder0PinALast2 = n2;
    }
    
    void lcdHello () {
      float brightness = analogRead (A13);
      
      float r = brightness * 0.2481;
      
      //float g = brightness * 0.1036;
      float g = brightness * 0.2481;
      float b = brightness * 0.2481;
      //Serial.println(b);
       
      analogWrite (REDLITE, r);
      analogWrite (GREENLITE, g);
      analogWrite (BLUELITE, b);  
    }
    
    void midiNoteOn (byte channel, byte note, byte velocity)
    {
      Serial.println (note);
       
      float a = 440; 
      float freq = (a / 32) * pow (2, ((note - 9) / 12.0));
    
      using namespace ctrls;
      
      float total = coarse + fine;
    
      freq = freq * total;  
    }
    
    
    void midiNoteOff (byte channel, byte note, byte velocity)
    {
      Serial.println ("noteOFF"); 
    }

  4. #4
    Senior Member
    Join Date
    Jul 2020
    Posts
    1,858
    You call AudioNoInterrupts() and never call AudioInterrupts().

Posting Permissions

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