How to Build a Digital Volume Controller Using PT2258

Publisher:光明2599Latest update time:2023-06-06 Source: elecfansKeywords:PT2258 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

A potentiometer is a mechanical device that allows you to set the resistance to the desired value, thereby varying the current passing through it. Potentiometers have many applications, but most often they are used as volume controllers in audio amplifiers.


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


Integrated Circuit PT2258

poYBAGL0x5iAAsNqAAQ2fA_aIDo141.png

As I mentioned before, the PT2258 is an IC used as a 6-channel electronic volume controller using CMOS technology designed for multi-channel audio-video applications.


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


Some basic features include,

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

Selectable I2C address (for daisy-chain applications)

High channel separation (for low noise applications)

Signal-to-noise ratio> 100dB

Operating voltage: 5 to 9V

How the PT2258 IC works

pYYBAGL0x5SARv0GAACk6UFoAKU525.png

This IC sends 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 the functional parts are managed by the Arduino library.


Data Validation

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

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

poYBAGL0x5CAZQZyAABfKD69ajY130.png

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 low state to high state

poYBAGL0x4uAZWUYAABHnKtr_JI026.png

NOTE! This information is very useful for debugging signals.

Data Format

Each byte transmitted to the SDA line consists of 8 bits to form a byte. Each byte must be followed by an acknowledge bit.


Acknowledgements

Acknowledgement ensures stable and correct operation. During the acknowledgement clock pulse, the microcontroller pulls the SDA pin high, while the peripheral device (audio processor) pulls the SDA line low (LOW).

pYYBAGL0x4eAaxNtAABhRm5m32g852.png

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

poYBAGL0x4OAYHsOAABYeEv1tBM786.png

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).

poYBAGL0x4CAOTchAAANUsL8IBc232.png

Logic High = 1

Logic Low = 0

Interface Protocol

The interface protocol consists of the following parts:

A start bit

One chip address byte

ACK = Acknowledge bit

One data byte

Stop bits

pYYBAGL0x3uAGzAcAACC4K60oWM109.png

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

After the delay, the first thing to do is to send "0XC0" over the I2C lines to clear the registers, which ensures normal operation.

poYBAGL0x3aAYb_gAABh6k7KiyM607.png

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

To ensure proper volume adjustment, multiples of 10dB and 1dB codes need to be sent to the attenuator in sequence, otherwise the IC will behave abnormally. The following figure illustrates this more clearly.

pYYBAGL0x3KADHhMAACqlh4XBVo871.png

Both of the above methods work fine.

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

This is how you can transmit a byte to the IC and attenuate the incoming signal. The above part is to learn the functionality of the IC but as I said before we will use the Arduino library to communicate with the IC which will manage all the hard code and we just need to make a few function calls.

Schematic

pYYBAGL0x26AQPjcAAEiv9bYf5g164.png

The figure above shows the tested schematic of the PT2258 based volume control circuit. It was taken from the datasheet and modified as required.

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

Required Components

PT2258 Integrated Circuit – 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 Wires - 10

Arduino Code

#include

#include

#include

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


You can see that the "w" in the wire library is a lowercase letter, which is not compatible with the latest Arduino version. It needs to be replaced with an uppercase "W". That's it.


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


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


Instead of using the code image below, copy all the code instances from the code file and format them as we have done 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.


intVolume = 40;

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


SerialNumber.Start(9600);

Wire.setClock(100000);

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


Next, we do some housekeeping using if else statements to ensure that the IC is communicating correctly with the I2C bus.


if (!pt2258.init())

Serial.printIn("PT2258 started successfully");

Other

Serial.printIn("Failed to start PT2258");

Next, we set the debounce delay for the button.


Button_1.setDebounceTime(50);

Button_2.setDebounceTime(50);

Finally, start up 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 section, we need to call the loop function from the button class; this is the library's specification.


Button_1.loop(); //Library specification

Button_2.loop(); //Library specification

The if part below is to reduce the volume.


/* If the condition is true, then button 1 is pressed */

if (button_1.ispressed())

{

Volume++; //Increase volume counter.

// This if statement ensures that the transaction amount does not exceed 79

if (volume >= 79)

{

Volume = 79;

}

Serial.print("Volume: "); // Print volume level

Serial.printIn(volume);

/* Set the volume of channel 4

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 to increase the volume.


// The same goes for button 2

if (button_2.isPressed())

{

Volume - ;

// This if statement ensures that the volume does not drop 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

68362dd7e45f24f5267aef8409504f17_poYBAGL0x2aAfUXDAAdSIoxTai8104.png


To test the circuit the following equipment was used

Transformer with 13-0-13 tapping

2 4Ω 20W speakers as load.

Audio source (telephone)

I messed around with the mechanical potentiometer and shorted the two leads with two small jumper cables. Now with the help of two buttons I can control the volume of the amplifier.
#include
#include
#include
PT2258 PT2258; //PT2258 object
ezButton button_1(2); //Button_1 object
ezButton button_2(4); //Button_2 object
integer volume = 40; //Default volume / starting volume
void setup() {
Serial.start(9600); //UART start
Wire.setClock(100000); //Set I2C clock to 100KHz
/* Check if MCU can talk to PT*/ if (!pt2258.init()) Serial.println("PT2258 started successfully"); else Serial.println("Starting PT2258 failed"); /* 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 condition is true, then button 1 is pressed */ if (button_1.isPressed()) { volume++; //Increment 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 Which is pin 9 of the PT2258 IC */ pt2258.setChannelVolume(volume, 4); /*Set the volume of channel 5 Which is pin 10 of the PT2258 IC */ pt2258.setChannelVolume(volume, 5); } //Same for button 2 if (button_2.isPressed()) { volume - ; // This if statement ensures that the volume does not go below zero. if (volume <= 0) volume = 0; Serial.print("Volume: "); Serial.println(volume); pt2258.setChannelVolume(volume, 4); pt2258.setChannelVolume(volume, 5); } }














































[1] [2]
Keywords:PT2258 Reference address:How to Build a Digital Volume Controller Using PT2258

Previous article:How to control the speed of an AC fan using PWM generated by Arduino
Next article:Tutorial on Designing Active Tone Control Circuits

Recommended ReadingLatest update time:2024-11-16 10:32

Can we get better audio amplifiers? Yes, with Gallium Nitride!
Audio is a complex application, especially for the various levels of the audiophile field. The highest-end audio equipment is often expensive, and different types of audio amplifiers attract many users who believe that their choice can best reproduce the true meaning of the original recording. Although there are man
[Embedded]
Can we get better audio amplifiers? Yes, with Gallium Nitride!
High-Power Audio Amplifier Solution Using Parallel Boost Converters
Audio amplifiers for high-power portable speakers, such as cart speakers, are often powered by lithium-ion batteries, which can range from a single cell to several cells in series. Designers often use a boost converter to generate the voltage for the audio amplifier, because the power consumption of the speaker can
[Embedded]
High-Power Audio Amplifier Solution Using Parallel Boost Converters
Detailed explanation of various current sensing amplifier application circuit designs
  Managing thermal conditions in electronic products becomes more important as modern, compact devices pack more performance and functionality into smaller packages. Even "big" projects such as base stations or servers have significantly higher performance than their predecessors. Monitoring the current consumed is a p
[Test Measurement]
Detailed explanation of various current sensing amplifier application circuit designs
4W audio amplifier circuit powered by TIP41
This 4W audio amplifier circuit is powered by 2 transistors TIP41. The circuit is very simple and contains Darlington output transistors which provide more than enough output current to drive a 3 ohm speaker. The 4W audio amplifier circuit is very simple and contains Darlington output transistors that pro
[Embedded]
4W audio amplifier circuit powered by TIP41
TDA1514 amplifier circuit with 50W audio output power
TDA1514 is a high-fidelity audio amplifier that can output 50W audio power. The power supply voltage is between 10V and 30V. It can be used as a home amplifier. The TDA1514 integrated circuit is a high-fidelity power amplifier that can be used as a building block in radio, television and other audio appli
[Embedded]
TDA1514 amplifier circuit with 50W audio output power
Stereo power audio amplifier circuit based on LM4756
This is the circuit diagram of a stereo power audio amplifier using power IC LM4756. This IC is capable of providing dual output channels with 7W for each channel. Like other audio amplifier circuits, this circuit requires only a few external components to work. Circuit Application: PCB Design:
[Embedded]
Stereo power audio amplifier circuit based on LM4756
ROHM develops world's smallest CMOS operational amplifier, ideal for applications such as smartphones and small IoT devices
- Low input offset voltage and low noise contribute to improved accuracy of sensor circuits - ROHM, a world-renowned semiconductor manufacturer (headquartered in Kyoto, Japan), has developed a CMOS operational amplifier "TLR377GYZ" in an ultra-small package that is ideal for amplifying sensor dete
[Analog Electronics]
ROHM develops world's smallest CMOS operational amplifier, ideal for applications such as smartphones and small IoT devices
Integrated operational amplifier amplification ability detection circuit
  1. Detection circuit   The integrated operational amplifier amplification capacity detection circuit is shown in Figure 2-51. The integrated operational amplifier is connected to a +15 V power supply and the multimeter is set to the DC voltage 50 V position.   2. Detection method   (1) First, open the input of the
[Test Measurement]
Integrated operational amplifier amplification ability detection circuit
Latest Embedded Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号