A potentiometer is a mechanical device with which a resistance can be set according to a desired value, thus changing the current through it. Potentiometers have many applications, but most often potentiometers are used as faders for audio amplifiers.

The potentiometer doesn’t control the gain of the signal, but it forms a voltage divider, which is why the input signal is attenuated. So in this project I will show you how to build your digital volume controller using the IC PT2258 and interface it with an Arduino to control the volume of the amplifier circuit.

IC PT2258

As I mentioned earlier, the PT2258 is a 6-channel electronic fader IC using CMOS technology designed for multi-channel audio-video applications.

The IC provides an I2C control interface with an attenuation range of 0 to -79dB, 1dB/step, and is available in a 20-pin DIP or SOP package.

Some basic features include,

6 input and output channels (for 5.1 home audio systems)

Optional I2C address (for daisy chain applications)

High channel separation (for low noise applications)

Signal-to-noise ratio > 100dB

Operating voltage is 5 to 9V

How PT2258 IC works

The IC transmits and receives data from the microcontroller through the SCL and SDA lines. SDA and SCL form the bus interface. These lines must be pulled high through two 4.7K resistors to ensure stable operation.

Before we get into the actual hardware operation, here is a detailed functional description of the IC. If you don’t want to know all this, you can skip this part as all functional parts are managed by the Arduino library.

data verification

When the SCL signal is HIGH, the data on the SDA line is considered stable.

The HIGH and LOW states of the SDA line only change when SCL is LOW.

start and stop conditions

When the start condition is activated

SCL is set to HIGH and

SDA changes from HIGH state to LOW state.

When the stop condition is activated

SCL is set to HIGH and

SDA transitions from a low state to a high state

notes! This information is useful for debugging signals.

Data Format

Each byte transferred to the SDA line consists of 8 bits, forming a byte. Each byte must be followed by an acknowledgment bit.

Thanks

Confirmation ensures stable and correct operation. During the acknowledgement clock pulse, the microcontroller pulls the SDA pin high, at which point the peripheral (audio processor) pulls the SDA line low (low).

The peripheral (PT2258) is now addressed and it must generate an acknowledgement after receiving a byte, otherwise the SDA line will remain high during the ninth (9) clock pulse. If this happens, the master transmitter will generate a STOP message to abort the transfer.

This eliminates the need for efficient data transfer.

Address selection

The I2C address of this IC depends on the status of CODE1 (Pin No.17) and CODE2 (Pin No.4).

logic high = 1

logic low = 0

Interface Protocol

The interface protocol consists of the following parts:

a start bit

A chip address byte

ACK=acknowledge bit

a data byte

stop bit

After the IC is powered on, it needs to wait at least 200ms to transmit the first data bit, otherwise the data transmission may fail.

After the delay, the first thing to do is to clear the register by sending “0XC0” over the I2C line, which ensures normal operation.

The above steps cleared the entire register, now we need to set a value to the register, otherwise, the register stores garbage value and we get a freckled output.

In order to ensure proper volume adjustment, it is necessary to send multiples of 10dB and codes of 1dB to the attenuator in turn, otherwise the IC will appear abnormal. The diagram below illustrates this more clearly.

Both of the above methods work fine.

To ensure proper operation, please ensure that the I2C data transfer speed does not exceed 100KHz.

This is how you can transfer a byte to the IC and attenuate the incoming signal. The above part is about learning what the IC does, but as I said before, we will use the Arduino library to communicate with the IC that manages all the hard code, we just need to make some function calls.

Schematic

The above figure shows the test schematic of the PT2258 based volume control circuit. It is taken from the datasheet and modified as needed.

For demonstration, the circuit was built on a solderless breadboard with the help of the schematic shown above.

required components

PT2258 IC – 1

Arduino Nano Controller – 1

Universal Breadboard – 1

Screw Terminal 5mm x 3 – 1

Button – 1

4.7K Resistor, 5% – 2

150K Resistor, 5% – 4

10k resistor, 5% – 2

10uF Capacitor – 6

0.1uF Capacitor – 1

Jumper – 10

Arduino code

#include

#include#include

Next, open the PT2258.cpp file with your favorite text editor, I am using Notepad++.

It can be seen that the “w” of the wire library is a lowercase letter, which is not compatible with the latest Arduino version, and needs to be replaced with an uppercase “W”, and that’s it.

The complete code for the PT2258 fader can be found at the end of this section. Important parts of the program are explained here.

We start the code by including all the required library files. The Wire library is used to communicate between the Arduino and the PT2258. The PT2258 library contains all critical I2C timing information and acknowledgements. The ezButton library is used to interact with buttons.

Instead of using the code image below, copy all the code instances from the code file and format them like we did before in other projects

#include#include#include

Next, make objects for the two buttons and the PT2258 library itself.

PT2258 PT2258;ezButton button_1(2);ezButton button_2(4);

Next, define the volume level. This is the default volume level when the IC starts up.

international volume = 40;

Next, start the UART and set the clock frequency of the I2C bus.

serial.start(9600); Wire.setClock(100000);

It is very important to set the I2C clock, otherwise the IC will not work because the maximum clock frequency supported by this IC is 100KHz.

Next, we use the if else statement to do some tidying up to ensure that the IC communicates correctly with the I2C bus.

If(!pt2258.init()) Serial.printIn("PT2258 startup successfully");Other Serial.printIn("PT2258 startup failed");

Next, we set the debounce delay for the button.

Button_1.setDebounceTime(50);Button_2.setDebounceTime(50);

Finally, start the PT2258 IC by setting the default channel volume and pin number.

/* Start PT with default volume and Pin*/Pt2258.setChannelVolume(volume,4);Pt2258.setChannelVolume(volume,5);

This marks the end of the Void Setup() section.

In the loop part, we need to call the loop function from the button class; this is the specification of the library.

Button_1.loop(); //Library specification Button_2.loop(); //Library specification

The if part below is to reduce the volume.

/* If the condition is true, press button 1 */ if(button_1.ispressed()){ volume++; // Increment the volume counter. // This if statement ensures that the volume does not exceed 79 if (volume >= 79) { volume = 79; } Serial.print("volume:"); // prints the volume level Serial.printIn(volume); /* set the channel The volume of 4 is in PIN 9 of PT2558 IC*/ Pt2558.setChannelVolume(Volume,4); /* Set the volume of channel 5 which is PIN 10 of PT2558 IC*/ Pt2558.setChannelVolume(Volume,5);}

The if part below is there to increase the volume.

// Button 2 as well if(button_2.isPressed()){Volume - ;// This if statement ensures that the volume doesn't go below zero. if (volume <= 0)="" volume="0;" serial.print("Volume:");="" serial.printin(volume);="" pt2258.setchannelvolume(volume, 4);=" " pt2558.setchannelvolume(volume,5);="">=>

Testing Digital Audio Volume Control Circuits

To test the circuit, the following equipment was used

Transformer with 13-0-13 tap

2 4Ω 20W speakers as loads.

Audio source (telephone)

I messed with the mechanical potentiometer and shorted the two leads with two small jumper cables. Now, with the help of two buttons, the volume of the amplifier can be controlled.
#include
#include
#include
PT2258 PT2258; // PT2258 object
ezButton button_1(2); //Button_1 object
ezButton button_2(4); //Button_2 target
int volume = 40; // default volume/start volume
void set() {
serial.start(9600); // UART start
Wire.setClock(100000); // Set the I2C clock to 100KHz
/* Check if MCU can talk to PT */
if(!pt2258.init())
Serial.println(“PT2258 started successfully”);
other
Serial.println(“Failed to start PT2258”);
/* Set button debounce delay */
button_1.setDebounceTime(50);
button_2.setDebounceTime(50);
/* Start PT with default volume and Pin */
pt2258.setChannelVolume(volume, 4);
pt2258.setChannelVolume(volume, 5);
}
void loop() {
button_1.loop(); //Library specification
button_2.loop(); //Library specification
/* If the condition is true, press button 1 */
if (button_1.isPressed())
{
volume++; // Increment the volume counter.
// This if statement ensures that the volume does not exceed 79
if (volume >= 79)
{
volume = 79;
}
Serial.print(“Volume:”); // print volume level
Serial.println(volume);
/* Set the volume of channel 4
In PIN 9 of PT2258 IC
*/
pt2258.setChannelVolume(volume, 4);
/* Set the volume of channel 5
Which pin is pin 10 of PT2258 IC?
*/
pt2258.setChannelVolume(volume, 5);
}
// same for button 2
if(button_2.isPressed())
{
volume – ;
// This if statement ensures that the volume does not drop below zero.
if (volume <=>=>
volume = 0;
Serial.print(“Volume: “);
Serial.println(volume);
pt2258.setChannelVolume(volume, 4);
pt2258.setChannelVolume(volume, 5);
}
}

Leave a Reply

Your email address will not be published.