Topics

uBITX AGC - Adafruit TPA2016, A Success! #ubitx

Nick VK4PP
 

Hi Group.
Now, I haven't tried many AGC solution on the uBITX, only 2, the VK3YE, and ADAFRUIT TPA2016 I2C module.
The VK3YE solution I found messed with the audio quality, made it all scratchy, and still didnt handle local 100w stations well...
Now after playing with the TPA for a few days I am very happy with the results.
Audio has good depth and AGC is reponsive, also gives a nice increase in gain.
One trick to others who want to impliment this, you will need to add some code to the Adafruit library to implement the enableNoiseGate(false); function.
We need to turn the NoiseGate off or else the AGC will not ramp up with only background noise and you will not hear anything until a loud signal comes on.
Also the speaker output is NOT grounded, you need to isolate you SPK jack so that the - from the TPA2016 are direct to the speaker with no chassis grounding...
Best part in my opinion, is that ALL the AGC related settings are customisable if your want, if not, just use the voice settings from the datasheet, I have and they work great!

Stereo 2.8W Class D Audio Amplifier - I2C Control AGC - TPA2016


I will post up some code tonight... and a few pics....

73, Nick VK4PLN

John <passionfruit88@...>
 

Nick,

I am interested in the TPA2016 option too as I want an AGC and have low volume on the upper bands. That would kill two birds with one stone.

I am curious, since it is a class D amplifier, did you have to take special steps to prevent hash getting in the receive path?

Also, where did you buy the unit and the mic compressor one too?

All the best,

73, John

Nick VK4PP
 

Hi john, both boards from eBay...
I am really happy with the setup, AGC is performing very well in my opinion...

John <passionfruit88@...>
 

Thanks Nick.

73, John

bobolink
 

It’s a pretty complex device Data Sheet
i guess somebody could come up with device configuration for menu settings:
AGC fast, slow, data
That will work with the Bitx 
Placed an Adafruit on order.
tnx 

Art Olson
 

Nick

Did u post some code or did I miss your posting

73
Art -N2AJO 


On Feb 5, 2018, at 9:11 AM, rwhinric@... wrote:

It’s a pretty complex device Data Sheet
i guess somebody could come up with device configuration for menu settings:
AGC fast, slow, data
That will work with the Bitx 
Placed an Adafruit on order.
tnx 

Michael Monteith
 

Which 2 boards?  I know the one is the TAP2016.  What's the other?

73, Michael
KM4OLT

On Fri, Feb 2, 2018 at 06:13 pm, Nick VK4PLN wrote:
Hi john, both boards from eBay...
I am really happy with the setup, AGC is performing very well in my opinion...

 

Nick,
Did you ever post the sketch for the TPA2016 AGC?

Aug
AG5AT

Fred Buecker
 

The other board was a VK3YE that he said did not work very well.

-Fred
KC3HMS

On Feb 5, 2018 9:47 AM, "Michael Monteith via Groups.Io" <michael_r_monteith=yahoo.com@groups.io> wrote:
Which 2 boards?  I know the one is the TAP2016.  What's the other?

73, Michael
KM4OLT
On Fri, Feb 2, 2018 at 06:13 pm, Nick VK4PLN wrote:
Hi john, both boards from eBay...
I am really happy with the setup, AGC is performing very well in my opinion...

Nick VK4PP
 

/*************************************************************************
  VK4PLN's AGC Code. Adafruit TPA2016
Add call to setupTPA2016(); to main code setup() in ubitx_20 after initOscillators();
**********/
 
#include <Wire.h>
#include "Adafruit_TPA2016.h"
 
Adafruit_TPA2016 audioamp = Adafruit_TPA2016();
 
void setupTPA2016() {
  
  audioamp.begin();
  // See Datasheet page 22 for value -> dBV conversion table
//  Serial.println("Right off, Left On,");
  audioamp.enableChannel(false, true);
 
  // Noise Gate Threshold: Below this value, the AGC holds the gain to prevent breathing effects.
  //Select the threshold of the noise gate (1,4,10,20mV) (0-3)
//  Serial.println("Noise Gate Threshold,");
  //Disable NoiseGate, we want to hear everything, even weak signals....
  audioamp.enableNoiseGate(false);
  audioamp.setNoiseGateThreshold(0);
  
  // Fixed Gain: The normal gain of the device when the AGC is inactive.
  // The fixed gain is also the initial gain when the device comes out of shutdown mode or when the AGC is disabled.
  // value 6 seems to work ok... based on datasheet. Where gain is from -28 (dB) to 30 (dB)
// Serial.println("Setting Fixed Gain");
  audioamp.setGain(-12); //-27 is ok? -12 is too high local stations arnt clipped...
 
    // Compression Ratio: The relation between input and output voltage.
  // AGC can be TPA2016_AGC_OFF (no AGC) or
  //  TPA2016_AGC_2 (1:2 compression)
  //  TPA2016_AGC_4 (1:4 compression) * Datasheet - Voice
  //  TPA2016_AGC_8 (1:8 compression)
//  Serial.println("Setting AGC Compression");
  audioamp.setAGCCompression(TPA2016_AGC_8);
 
  // Limiter Level: The value that sets the maximum allowed output amplitude.
//  Serial.println("Setting Limit Level");
  audioamp.setLimitLevelOn();
  // or turn off with 
  //audioamp.setLimitLevelOff();
  audioamp.setLimitLevel(30);  // range from 0 (-6.5dBv) to 31 (9dBV) (8.5dBv(30) as per datasheet)
 
  //Maximum Gain: The gain at the lower end of the compression region
//  Serial.println("Setting AGC Max Gain (18-30db - (0-12)");
  audioamp.setAGCMaxGain(12);
 
  /*
   *   For voice systems the attack time should be in the 2-ms region, with a hang time of about 0.3 sec,
   *   followed by a gradual recovery time of up to 1 sec. 
   *   http://www.qsl.net/va3iul/Files/Automatic_Gain_Control.pdf
   *
   */
  
  // See Datasheet page 23 for value -> ms conversion table
//  Serial.println("Setting AGC Attack (0.1-6.7ms - (0-63))");
  audioamp.setAttackControl(3);
  
  // See Datasheet page 24 for value -> ms conversion table
//  Serial.println("Setting AGC Hold (0.0137-0.8631ms - (1-63))");
  audioamp.setHoldControl(0);
  
  // See Datasheet page 24 for value -> ms conversion table
//  Serial.println("Setting AGC Release (0.0137-0.8631ms - (0-63))");
  audioamp.setReleaseControl(4);
}

Nick VK4PP
 

Also, need to add this new function to Adafuit library after the existing enableChannel function:

// Turn on/off Nosie Gate
void Adafruit_TPA2016::enableNoiseGate(boolean ng) {
 
  uint8_t setup = read8(TPA2016_SETUP);
  if (ng)
    setup |= TPA2016_SETUP_NOISEGATE;
  else 
    setup &= ~TPA2016_SETUP_NOISEGATE;
  
  write8(TPA2016_SETUP, setup);
}

Nick VK4PP
 

And the line for the header file:

void enableNoiseGate(boolean ng);

 

Thanks Nik,

One more thing.  It appears we need a function:

setNoiseGateThreshold(0);

that you may have also added.

Aug
AG5AT

Hank W6IR <w6ir@...>
 

Where did you insert the board?

Nick VK4PP
 

My Appologies.
In my haste I pasted in the wrong function, I will get the correct one tonight...

I connected the board to the TDA side of the volume control, basically eliminating the TDA chip completely.

Please be aware that the output from the TPA2016 is to be connected directly to the speaker, and NOT grounded at all, this is due to the fact that these outputs are Bridge Tied Load which means you must connect the speakers directly - do not try to connect these outputs to another amplifier!

73 and good luck.

Nick VK4PP
 

in .h file:
void setNoiseGateThreshold(uint8_t thresh);

in .cpp file
void Adafruit_TPA2016::setNoiseGateThreshold(uint8_t thresh){ //Added by VK4PLN
if (thresh > 3) return; // max threshold is 3 (20mV)
 
uint8_t agc = read8(TPA2016_AGCLIMIT);
  
  agc &= ~(0x20);  // mask off bottom 5 bits
  agc |= thresh;        // set the limit level.
 
  write8(TPA2016_AGCLIMIT, agc);
}

73

Mike Doty
 

Hi Nik,
I have two questions for you in regards to using the TPA2016 module.  First question is are you taking the audio input to the module directly from the volume pot wiper? That was my take on an earlier post you made.  I have two modules and both behave the same.  One module I connected as just a stock amplifier, with no connections to the I2C bus, and the audio output is extremely low.  In order to hear a 50uV 1KHz signal I have to turn the volume control to maximum.  The second module I have configured with the I2C connections to the Arduino Nano and have the Vcc line for the I2C connected to the 3.3V port.  The Vdd line is connected to 5V.  I have the same results - extremely low audio.  I'm using the left channel for input and output.  My speaker is not grounded in either case. 

The second question is more of a request.  Would you post your modified Adafruit library files in the File section here on Groups IO?  I thought I had your library modifications figured out but now I'm not completely certain.  Before I start chasing my tail in the wrong direction I'd like to know that at least the files I've modified and am using are not part of the problem.

Thanks for your work, I certainly appreciate it.
--73-- Mike  --  W0MNE

Nick VK4PP
 

Hi mike, I'll put the files up soon...
I did have the same issue with low audio. That is what the noise gate threshold is for, we want to set it very low(0) so that it lets even weak signals and static through... Then play with the gain setting in the software...
I'll try put up a bit more details as to my exact setup, but you are on the right track.

Nick VK4PP
 

Mike Doty
 

Thanks for taking the time to reply and posting the library files, Nik.  I certainly appreciate it.  I have replaced the files in my TPA2016 library with your modified files and recompiled my sketch.  The results are still the same - almost no audio.  As I said in my last post, connecting the TPA2016 module as a basic amplifier, with no firmware control, the audio is very low.  There is no background noise and only signals at S9 or better can be heard.  The same module installed in a BiTX40ver3 as a basic amp to replace the LM386 works well.  To me the issue appears to be low drive in to the TPA2016.  I'll keep digging and I'd definitely like to see more detail in regards to your implementation. 

Thanks again -- Mike