Introduction: Arduino Powered Gainclone (amplifier)
For those of you that do not know (and I didn't until recently), a Gainclone is an amp that is a 'clone' of the original design of an amp made by 47 Labs called a Gaincard and are based on single chip amplifiers made by National Semiconductor - Namely the LM3886 chip (The original Gaincard used LM3875). These amps produce a superior sound to most anything that you can buy at your local audiophile store and are a fraction of the cost to build. It sounds impossible but you will be wanting to turf your existing amp for one of these in no time!
I won't go too much into the build of the actual amp here but I will give details of my parts and where I acquired them from. There are already a few instructables on building a gainclone and several websites almost dedicated to the subject and I could not even scrape the surface of the possibilities in building one. There are so many different options for the same result. Decide on the amp you want to build, learn how to build it and then come back here for the 'smarts' to put in it.
This is not a beginner project, especially the amp itself. It involves wiring of mains power and can be extremely dangerous to those that are not knowledgeable in this area - Do not take chances. If you are not a competent solderer and don't have a reasonable knowledge of electronics and feel safe playing with mains power, this project might not be for you.
A big thanks goes to ASCAS for the initial inspiration to build one of these amps!
What this instructable is mostly about, is the 'front end' of the amp - In this case it is an Arduino powered sound processor and input switcher.
The main components that allow this to work are:
TDA7439 Sound processor chip
TEA5767 Radio module
DS1307 RTC clock module
The TDA7439 allows the switching of 4 sources to one output, Bass/Mid/Treb control, Input gain and volume control (among others). The functions of the chip are controlled via the i2c bus. It's commonly found in car audio applications but is perfectly suited to this use too. The only downside to it is it's in a DIP30 package which means you cant breadboard it, even worse is that there seems to be no easily obtainable sockets for a DIP30 chip. However, the pin spacing is still solderable by hand. The chips cost a couple of dollars so if you fry one, its not the end of the world.
To make this even easier to use, I have authored an Arduino library so all you need are simple commands to use the functions of the chip.
The TEA5767 is an FM radio module, also controlled by the i2c bus and is extremely easy to use. I would have preferred a DAB (digital) radio but the modules available are limited and somewhat awkward to use at the moment. Maybe in V2....
The DS1307 RTC is included for the sake of it, I just wanted to have a clock :) It's also on the i2c bus.
Step 1: Collecting the Parts
For my actual amp, the main components I used are:
2 X 25V, 100VA Toroids from Element14 - They were on special at the time for $15ea! Sadly, they no longer are.
2 X Power supply boards from AliExpress
2 X LM3886 Amplifier modules, also from AliExpress
However, a search for LM3886 on eBay or AliExpress will turn up a magnitude of results - Take your pick!
For the sound processor, you will need:
TDA7439 IC ~$4
TEA5767 FM Module <$3 ea
16X2 LCD module ~ $5
Ir Remote and reciever - These can be salvaged from old equipment or purchased from ebay
DS1307 RTC module
*A Rotary encoder (somewhat optional)
8 X 0.47uf MKT
4 X 100nf MKT
2 X 22nf MKT
2 X 18nf MKT
2 X 5.6nf MKT
2 X 2.2uf NP
2 X 2K7
2 X 5K5
1 X 10uf Mono
2 X 4K7
0.1" Header terminal strips (for connecting the inputs, LCD etc.
2mm spacing header (for the TEA5767 module, or just use some wire.
If you want Fan Control:
1 X BD681 Darlington Transistor
1 X 1k Resistor
A small power supply - The Datasheet for the TDA7439 states that it's minimum supply voltage is 9v, however, it seems to run ok on 5v when connected via USB. I didn't test this further as I needed the power supply for the fan in my case anyway. You could possibly just use a decent 5v supply.
A way of fabricating the board
* The system is controllable by buttons and an IR remote. The only functionality that is not in both is tuning the radio. This is currently by IR only. So, if you wanted to leave out the Rotary encoder for the most minimalist look, you could just use the IR remote.
Also, the rotary encoder I am using was surplus stock from a massive manufacturing workshop shutdown, hence it is probably worth >$100 but cost me a couple of dollars. It does all the debouncing and signal processing itself, so there is nothing in the code to handle a 'raw' encoder signal. It is also a 1000ppr sensor so there is a divider in the interrupt service routine to reduce it's sensitivity. In theory, there is no reason that a mechanical one would not work but it may require some debouncing on the inputs.
Step 2: Fabricating the Board and Assembly
These days I use a CNC machine to fab my boards but there is no reason this could not be made with toner transfer, positive resist etc. Use what suits you. I will mention however that the TDA7439 is fairly unforgiving for misaligned holes. Take your time when drilling the holes if you are doing it by hand.
The attached file is in Sprint Layout format. There is a free viewer available from Abacom - See the bottom of the page.
Most holes are 0.6mm with the arduino and other header pin holes being 1mm.
Once you have the PCB completed, check it over for any shorted/open tracks/pads and clean up as necessary.
Start assembling the board, starting with the links (in red) then all resistors and capacitors. If you were lucky enough to find a DIP30 socket, install that now too. Install the TEA5767 module, taking note of the orientation of the chip. The silver cylinder part (crystal) is closest to the arduino.
Install the rest of the parts as per the layout.
You can install the RTC off some headers. I used a female header from an arduino shield trimmed down to 4 pins to give it some height. This works well.
From here, it is assumed that you have a functional Gainclone that is tested and verified to work with a simple signal source such as a MP3 player or PC. Please ensure this is the case before adding the board to ensure you can easily isolate any problems encountered.
Step 3: LCD and IR Sensor
Once you know the distance and orientation of the LCD and IR sensor to the main board, you can use some standard IDC ribbon cable to connect the components.
Check the pinout of your LCD - Most are the same but there are generally minor differences. Match the pin identifications for the LCD to the PCB layout. At this time, Identify the pins on the IR sensor. There will be Sig/O, Gnd and Vcc. Gnd and Vcc can go to the corresponding pins on the LCD to simplify wiring, Sig will go to the pin marked IR on the PCB layout.
Step 4: Encoder and Buttons
If you are using a 'smart' rotary encoder like mine, connect your Rotary encoder to the corresponding pins marked A,B,Gnd, 5v.
However, if you are using a simple mechanical encoder, connect the common pin to 5v and A/B to the corresponding pins on the board.
If your encoder also has a 'push' button, connect it's corresponding pins between ground and the pin marked enter.
**Remember, using a mechanical encoder will mean you need to change some settings in the code and likely 'fix' it to allow for debouncing of the contacts. Depending on the popularity of this instructable I may review the code to allow for this.
For those that do have an encoder but not with a push option, use a separate N/O SPST button connected between Gnd and Enter pins.
Connect a N/O SPST button between Gnd and Power pins for a power button.
Step 5: Power Relay
The relay output pin is for controlling power to the toroid(s) when the amp is 'off''. This ensures low power use when 'off' (The arduino is still running on its own hard wired power supply)
This is an active high output that is to drive the Solid state relay natively or you could one of the relay modules available on ebay if you wanted to keep costs down (pic 2)
I had a spare SSR so that's what I used...
Step 6: Power LED
Pins A1 and A2 (marked PWLED) are configured to be used for sinking current for the power LED. This is a bi-state configuration but a single 'on' led can be used rather than have an on and an off led. Connect your LED(S) to one of the 5v/Vcc lines via an apropriate (probably around 1k) resistor and then to these pins. I used a common Annode (+) RGB led but just used red and green.
You could also use these pins in current sourcing mode with a common cathode LED and the corresponing gnd pin adjacent to the A1/2 header, The outputs on these pins are inverted with the power change so it will work fine with no code changes.
Step 7: Power Supply and Fan Connections
Connect your small power supply to the Vin and Gnd pins and connect your fan to the corresponding pins on the board (if using)
If you do not require a fan, you may be able to get away with a 5v power supply. It worked ok in my initial tests but this is outside of spec for the operating voltage of the TDA749 chip and you may encounter problems.
Step 8: Final Connections
Connect the Ant. pin to a suitable antenna jack or just a piece of wire.
Finally, connect all of your inputs to the processor. These are marked Lx and Rx. Input 1 is hard wired to the TEA65767 Radio module but the other 3 inputs can be used as you wish. In my amp I have a 3.5mm jack (AUX), standard component audio (CD) and USB (DAC).
The USB is simply a decased and rewired Sound blaster Play! that can be had for about $20 and the sound quality is quite impressive. It installs as "USB sound device" and needs no drivers, even on Windows XP (eeew).
Step 9: Loading the Code Into the Arduino and Testing.
With the mains power OFF!
All development has been done in the latest Arduino IDE.
You will need the following libraries
Install the libraries into the Arduino IDE as you would any other.
This project also use the EEPROMWriteAnything method
Grab the zip file attached here too :)
Set the time...
Load up the default example sketch in the arduino IDE for the DS1307RTC called 'SetTime' and upload it to the arduino. This will set the time on the RTC module to the current time of your PC. Hint: Open the serial monitor window. This also checks your connections to the RTC and ensures the i2c bus is working... Provided you were successful in programming the time on the RTC, move on to the next step. If not, verify your soldering and ensure the RTC is orientated correctly with the pins labelled.
Now program the Arduino_Gainclone_1_3.ino file to the Arduino from the zip file.
Once loaded, the backlight should come on dimly and you should see a basic display of the time. If at this point you see garble or nothing on the display, double check your wiring to the LCD module.
****Still with the mains power off*****
Power on the controller by pressing the power button, the LCD should light up to full brightness and Welcome you. It will then default to the radio and the power relay should come on.
The LCD may be slow to respond as it's all being powered off USB. Don't fret, it will be fine once you're off USB power.
Learn your IR commands:
Open the arduino serial port monitor and it will print the codes when you push a button on your remote. If it doesn't then you may have hooked up your IR receiver wrong - Check your wiring.
Find the line in the top section of the arduino code corresponding to the button you want to use and enter the code that it produces for that remote button. Once you have all your IR codes entered, you can re-upload the code to the Arduino
If you purchased a 'KEYES' remote off ebay - No need, that's what the code is configured for.
Left = Vol Down/Menu left
Right = Vol up/Menu Right
Ok = Enter
Up = Tune Up
Down = Tune down
* = Power
However, this remote has a slight annoyance in that it does not keep repeating the code when the button is held, it sends a 'repeat last code' type command. This is annoying when changing the volume by a large amount.
Verify the functions of the remote, buttons and encoder to make sure they do what you expect. The ok/enter button enters the menu and then you can use the volume to change the values, enter/ok to select etc. Menus time out after 5 seconds. If the volume is the wrong way round, swap the A/B wires on the encoder and it will go the right way.
If everything checks out, turn off the amp using one either of the power buttons and disconnect the usb cable from the Arduino.
Step 10: The Moment of Truth!
Connect and power on the amp from the mains. Providing everything checks out, after about 2 seconds you should see the time on the display. You can then hit the power button and the amp should turn on and you will be able to listen to some sweet tunes!