Adrianotiger / phoneDTMF

Detect DTMF without external devices
31 stars 7 forks source link

maxFrequence returned by nano 2890 #3

Open hayden-t opened 2 years ago

hayden-t commented 2 years ago

this is the same 328 chip as uno ? readme says i need 6000. what gives ?? (thanks)

Adrianotiger commented 2 years ago

My project uses an ESP with 240MHz. The ATMega328 (Uno and Nano) have a 16MHz oscillator. The clock speed should be enough to read it. It is just important that you read the analog input 6000 times on each second.

hayden-t commented 2 years ago

even if i have this most basic script, the analog center reported varies alot, sometimes correct, sometimes volts off.


#include <PhoneDTMF.h>
PhoneDTMF dtmf = PhoneDTMF();

int dtmfPin = A0;

float* pMagnitudes;

void setup()
{

  Serial.begin(9600);
  Serial.println("Ready");

  delay(1000);
  dtmf.begin(dtmfPin);

  Serial.println(dtmf.getAnalogCenter() * (5.0 / 1023.0));
  Serial.println(dtmf.getSampleFrequence());
Adrianotiger commented 2 years ago

you should not measure it when a signal is present.

When you call dtmf.begin(), the center is measured. If you already have a signal, this value can be higher or lower.

The center is regulated automatically on each measurement.

hayden-t commented 2 years ago

no, this is happening with no signal, just 2.5v flatline

hayden-t commented 2 years ago

doing some research i found this library which when i use its analogfastread function my maxfrequence is nearly 4000 https://github.com/avandalen/avdweb_AnalogReadFast

hayden-t commented 2 years ago

looking further at your code it seems the limiting factor for me is not so much the adc sample rate, but the additional code in ProcessSample that is called everytime an analogue read is done. maybe nano is not fast enough

hayden-t commented 2 years ago

i reverted back to standard analog read and commented out the process sample code, it now reports maxfreq at 8929, so would have t optimize that code if possible, i may just buy the decoder board.

Adrianotiger commented 2 years ago

But 8930 is ok to measure the tone

hayden-t commented 2 years ago

except thats with no processing:

/* Call this routine for every sample. */
//El_Supremo - change to int (WHY was it byte??)
  /// <summary>
void PhoneDTMF::ProcessSample(int16_t sample)
{
/*
  float Q0;
  //EL_Supremo subtract adc_centre to offset the sample correctly
  for (uint8_t i = 0; i < TONES; i++)
  {
    Q0 = _afToneCoeff[i] * _afQ1[i] - _afQ2[i] + _fAmplifier * (sample - _iAdcCentre);
    _afQ2[i] = _afQ1[i];
    _afQ1[i] = Q0;
  }
  _fAdcCentre += (float)sample / (float)_iSamplesCount;
*/
#ifdef DTMF_DEBUG
  if (_iDataIndex < 128)
  {
    _aiAnalogData[_iDataIndex++] = sample;
  }
#endif
}