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

Thread: Audio teensy froze during AnalogRead

  1. #1

    Audio teensy froze during AnalogRead

    Is there some limitation with using the audio tool and analogRead (different pins)?

    My code freezes whenever it reaches that line that has AnalogRead.

    when I remove the audio design objects the code works well.
    Last edited by donperryjm; 08-23-2019 at 05:39 PM.

  2. #2
    Senior Member houtson's Avatar
    Join Date
    Aug 2015
    there shouldn't be a problem, post an example or it is difficult to help. cheers paul

  3. #3
    The bare minimum that presents the problem. I've added a line Serial.print("Works up to here"); to let me know when the program freezes. Moving line below the analogRead will show that it froze at analogread

    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <SerialFlash.h>
    #include <avr/wdt.h>
    #include "SerialCom.h"
    #include <RunningAverage.h>
    int centerFreq = 6300;
    double _gain = 1.2;
    unsigned int sampleSize = 24;
    // GUItool: begin automatically generated code
    AudioInputAnalogStereo   adcs1;          //xy=200,582
    AudioFilterBiquad        biquad1L;       //xy=400,521
    AudioAmplifier           amp1L;          //xy=542,513
    AudioAnalyzePeak         peakL;          //xy=789,472
    AudioOutputUSB           usb1;           //xy=834.0000114440918,538.0000085830688
    AudioConnection          patchCord1(adcs1, 0, biquad1L, 0);
    AudioConnection          patchCord2(biquad1L, amp1L);
    AudioConnection          patchCord3(amp1L, peakL);
    AudioConnection          patchCord4(amp1L, 0, usb1, 0);
    AudioConnection          patchCord5(amp1L, 0, usb1, 1);
    // GUItool: end automatically generated code
    int monoPeak; //for peak detection
    double mapV = 0.0; //boost voltage
    double afrV = 0.0; //AFR voltage
    double auxV = 0.0; //Aux volt in
    double injectorDuty = 0;
    double low, high;
    int cycles = 10;
    int triggerPin = 3;
    double refVolts = 0.0; //Ref volts
    double revPerSpark = 2.500;
    unsigned long lastTime;
    unsigned long sparkTime;
    volatile double rpm = 0;
    int boostPin = A3;
    const int afrPin = A1;
    const int output5V = A2;
    const int auxPin = A6;
    int timeout = 0;
    int RPMReset = 0;
    const int ledpin = LED_BUILTIN;
    void setup()
    	pinMode(ledpin, OUTPUT);
    	pinMode(3, INPUT_PULLUP);
    	lastTime = sparkTime = micros();
    // for best effect make your terminal/monitor a minimum of 31 chars wide and as high as you can.
    elapsedMillis fps;
    int settingCheckCounter = 0;
    void loop()
    	Serial.print("Works up to here");
    	//---------READ BOOST---------//
    	mapV = 0; //reset
    	mapV = analogRead(boostPin); //A3 ?voltage divider?
    	mapV = mapDouble(mapV, 0, 1023, 0, 5); //map to reference voltage
    	afrV = analogRead(afrPin);
    	afrV = mapDouble(afrV, 0, 1023, 0.00, 5); //map to reference voltage
    double mapDouble(double x, double in_min, double in_max, double out_min, double out_max)
    	if (x > in_max)
    		x = in_max;
    	if (x < in_min)
    		x = in_min;
    	return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
    void SendDataToPC()
    	Serial.println("Works up to this line");

  4. #4
    Senior Member+ manitou's Avatar
    Join Date
    Jan 2013
    The audio lib takes over the ADC controllers. you can't mix analogRead with audio ADCs, see warning in Notes sidebar for ADC in audio gui

Posting Permissions

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