TeensyViewAudio, partial function with 72MHz

Status
Not open for further replies.

Fimmo

Member
I would like to use a fft-display at my project. I used the example code TeensyViewAudio and adapted it to my ST7735 display, using the ST7735_t3 library.

Function is given, but I observe a not explainable issue.
I'm using a Teensy3.2 with audioShield C and compiling with Arduino IDE 1.8.5 and Teensyduino 1.55.
It compiles without any error.

If I use 48MHz clock for Teensy, function is given, but the audio is distorted with continous interruptions (sounds like modulated with abt 50Hz). The loop-time is displayed with 12 to 17ms, processor usage max is displayed with 180.

After compiling with 72MHz clock, and programming without cycling power, audio is clear and processor usage lowers to 125.

After cycling power, with 72MHz compiled sketch, only display is working, audio is supressed. (The LED on the Teeny breakout doesn't light up.)

After newly programming with the 48MHz compiled sketch function is given, but again with distorted audio. When now reprogrammed with the 72MHz sketch without cycling power, audio is ok, and all works good.

Teensy and audioshield are stacked with headers.

How to solve the problem? Please help....
Thank you in advance.
Fimmo

Code:
/******************************************************************************
  TeensyViewAudio.ino
  Example using the TeensyView with the Teensy Audio board

  adapted to ST7735 display
******************************************************************************/
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

// GUItool: begin automatically generated code
AudioInputI2S            audioInput;
AudioAnalyzeFFT1024      LeftFFT;
AudioAnalyzeFFT1024      RightFFT;
AudioOutputI2S           audioOutput;
AudioConnection          patchCord1(audioInput, 0, LeftFFT, 0);
AudioConnection          patchCord2(audioInput, 0, audioOutput, 0);
AudioConnection          patchCord3(audioInput, 1, audioOutput, 1);
AudioConnection          patchCord4(audioInput, 1, RightFFT, 0);
AudioControlSGTL5000     audioShield;
// GUItool: end automatically generated code

const int myInput = AUDIO_INPUT_LINEIN;
//const int myInput = AUDIO_INPUT_MIC;


#include <ST7735_t3.h>                    // 1.8" TFT Module using ST7735 chip
uint16_t myColor = 0xffe0;  // orange

///////////////////////////////////
// TeensyView Object Declaration //
///////////////////////////////////
// pin setup for display
#define PIN_RESET 5     // tied to 3.3V
#define PIN_DC    20
#define PIN_CS    21    // tied to GND
#define PIN_SCK   14
#define PIN_MOSI  7

ST7735_t3 tft = ST7735_t3(PIN_CS, PIN_DC, PIN_MOSI, PIN_SCK, PIN_RESET);

void setup()
{
  // Set up audio stuff:
  // Audio connections require memory to work.  For more
  // detailed information, see the MemoryAndCpuUsage example
  AudioMemory(20);
  delay(500);
  // Enable the audio shield and set the output volume.
  audioShield.enable();
  audioShield.inputSelect(myInput);
  audioShield.volume(0.6 ); //Pass-through volume
  delay(500);

  // Configure the window algorithm to use
  LeftFFT.windowFunction(AudioWindowHanning1024);
  //-----
  RightFFT.windowFunction(AudioWindowHanning1024);
  //-----
  // init TFT
  tft.initR(INITR_BLACKTAB);                // initialize a ST7735S chip, black tab
  tft.setRotation(3);                       // turn arround 180 degrees, ribbon left
  tft.fillScreen(0x0000);                   // clear screen with Black
  delay(500);

  //  L/R letters
  tft.setCursor(15, 74);
  tft.print("L");
  tft.setCursor(108, 74);
  tft.print("R");
} // end of setup()

unsigned long  last_time = millis();
uint8_t   overlayCounter = 0;
float       lastLoopTime = 0;
uint16_t         lastCPU = 0;
uint16_t         lastMem = 0; 

float leftBands[40] = {
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};

float RightBands[40] = {
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};

void loop()
{
  float loopTime;
  int i;
  
//------ calc loopTime ---------------
  unsigned long this_time = millis();
  if (this_time > last_time)
  {
    loopTime = (this_time - last_time);
  }
  last_time = this_time;
   
//--- Update data every 20 frames for readability
  overlayCounter++;
  
  if (overlayCounter > 30)
  {
    lastLoopTime = loopTime;
    lastCPU = AudioProcessorUsageMax();
    AudioProcessorUsageMaxReset();

      overlayCounter = 0;

  }
  
  // delete areas
  
  //fillRect( x,  y,  w,  h, color);
   tft.fillRect(22,24,84,60,0x0000);        // Black, Clear block of waterfall
   tft.fillRect(30,0,26,9,0x0000);          // clear value loop time
   tft.fillRect(107,0,26,9,0x0000);         // clear value cpu usage
   
   
//--- Draw left bands ----
  for (i = 0; i < 40; i++)
  {
    if (leftBands[i] > 0.5) leftBands[i] = 0.25;  // maxValue=62, if greater reduce to half
    tft.drawLine(62 - i, 81, 62 - i, 81 - (leftBands[i] * 127), myColor);
  }

//--- Draw Right bands ---
  for (i = 0; i < 40; i++)
  {
    if (RightBands[i] > 0.5) RightBands[i] = 0.25;
    tft.drawLine(65 + i, 81, 65 + i, 81 - (RightBands[i] * 127), myColor);
  }

//--- Overlay info ---
  //  loop time
   tft.setCursor(0,0);
   tft.print("Loop=");
   tft.print((uint8_t)lastLoopTime);
   tft.print("ms");
  
// Teensy Audio info
   tft.setCursor(83, 0);
   tft.print("cpu=");
   tft.print(lastCPU);
   tft.print("%");
// each time new FFT data is available 

//--- fetch left data -----
  if (LeftFFT.available()) 
  {
    for (i = 0; i < 40; i++) 
    {
    leftBands[i] = LeftFFT.read(i);
    }

  }

//--- fetch right data -----  
  if (RightFFT.available())
  {
    for (i = 0; i < 40; i++) 
    {
      RightBands[i] = RightFFT.read(i);
    }
  }

//--------------------------  
}     //end of loop
 

Attachments

  • TeensyViewAudio.ino
    4.7 KB · Views: 34
Last edited:
Problem is solved:
Don't compile with 'LTO', use only 'faster' and all works well. Advice from Mr. Stoffregen himself.
There seems to be a bug in the LTO routines, wich makes problems at higher clockrates.
Cheers
 
@Frank B
If you know, that the sourcecode is not good, than please tell me, what particular point is missed or poor. I would like to understand and to avoid the possible issue.
 
Status
Not open for further replies.
Back
Top