LM386 based stereo audio amplifier with digital volume control using PIC18F2550
Due to its simplicity (requires minimum external components) and high availability, LM386 is very popular among hobbyists for use in low-voltage audio amplification applications. Most of the time a potentiometer is used at the input side of LM386 to provide a volume control in the output speaker. The potentiometer does not control the gain of the amplifier itself, but it creates a voltage divider network at the input, which in fact controls the fraction of the audio signal that is fed to the amplifier. This project is about a stereo audio amplifier using two LM386 ICs with digital volume control for both left and right speakers. So, how would you control the volume digitally? You are right, by replacing the traditional electro-mechanical form of potentiometers with digital potentiometer chips. This project uses MAXIM’s DS1868 dual digital potentiometer chip and a PIC microcontroller to control the volume of a stereo output from two LM386 ICs.
Tons of resources can be found on the internet about LM386 and so I am not going to describe it in detail here. The LM386 IC has got 8 pins which require very few external components to work as a mono amplifier. The circuit below is taken from the datasheet and shows the external components required for constructing a mono-channel audio amplifier with LM386. An external 10K potentiometer at the input is used to control the volume of the output speaker. For a stereo audio amplifier, we need two of this circuit.
The supply voltage range for LM386 is wide (4-18 V). It can be powered with a +9V PP3 battery. For digital volume control feature, we will replace the external 10K potentiometer at the input stage with a digital potentiometer chip. MAXIM’s DS1868 is a dual digital potentiometer chip. Each wiper terminal has 256 positions between the high and low end of the potentiometer. The wiper position is set by an 8-bit control value that is stored into the I/O register of DS1868. The communication with the host microcontroller is done through a 3-wire serial interface. Please read my previous post, ‘How to interface MAXIM’s DS1868 digital potentiometer with a PIC microcontroller‘ for further detail on DS1868.
The block diagram below shows the operation of the stereo audio amplifier with separate volume control for left and right speakers. The DS1868 has two potentiometers and therefore a single chip is enough for two LM386 circuits. The DS1868 is offered in three standard resistance values: 10, 50, and 100 KΩ versions. I am using DS1868-010, which is the 10K version. The stereo audio is fed to the high ends (H0 and H1) of the two potentiometers, while both the low ends are grounded. The input audio signals for the two LM386 stages are derived from the wiper terminals (W0 and W1). The PIC18F2550 microcontroller receives user inputs from tact switches and set the wiper positions accordingly, which in fact control the output volume. A LCD is used to display the individual channel volume level.
The block diagram provided in the the theory section described how this project works. The stereo audio amplification circuit is made up of two LM386 mono amplifiers. The circuit diagram of LM386 based mono amplifier was also described above. The microcontroller, DS1868 digital potentiometer, LCD and tact switches connections are shown below. I am using the StartUSB for PIC board for this project which has got a PIC18F2550 microcontroller loaded with a fast USB bootloader. However, this project can also be done with a smaller size PIC from the mid-range family.
There are three tact switches for user inputs. They are named UP, DOWN, and SELECT in the circuit diagram. UP is to increase and DOWN is to decrease the volume. With the SELECT input, you can set the volume of left and right speakers jointly or individually. As mentioned earlier too, the stereo input is fed to the H0 and H1 pins of DS1868, whereas the L0 and L1 pins are grounded. The two wiper terminals, W0 and W1, are connected to the input pins of the two LM386 mono amplifiers. The LCD is operated in 4-bit mode and the data pins (D4-D7) are connected to RB4 through RB7 port pins. The two LCD control pins, RS and E, are driven by RC6 and RC7 pins of PIC18F2550.
Current Project / Post can also be found using:
- irremote pic18f2550