Loading...
Pages: [1]   Go Down
Author Topic: DS1881 Volume Control  (Read 644 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello everyone,

I seem to be having a problem using the DS1881. After trying to get it to work for hours, I am turning to everyone here. smiley I am trying to use the DS1881 as a volume control and I can't seem to figure out how to get it working properly. I was setting the VOL variable and it would turn on the speakers at -1 but that was the only volume change that would happen otherwise it was always muted. I have read the datasheet and it seems that it is me that is not working correct. smiley-wink There is code that is commented out as I was trying different ideas to see if it would work.

Does anyone have any suggestions for me?

Code:
#include <Wire.h>

int CEVolume = 6;
int volButton = 8;
int val = 0;     // variable for reading the pin status
int vol = 0;
int stringOne;

void setup()
{
  Wire.begin();

  Serial.begin(9600);
  pinMode(CEVolume, OUTPUT);
  digitalWrite(CEVolume, HIGH);
 
  pinMode(volButton, INPUT);
  vol = 34;

}

void loop()
{

  val = digitalRead(volButton);
  if (vol == 63)
  {
    vol = 34;
  }
  if (val == HIGH)
  {
    vol--;
    changeVolume();
  }
  Serial.println(vol);
  delay(1000);
}



void changeVolume()
{
  digitalWrite(CEVolume, LOW);
  Wire.beginTransmission(0x28);
    Wire.write(B01010000);
    //stringOne = String(vol, HEX);
    Wire.write(B00001111); //Command Byte - Pot 0
    //Wire.write(B01111111);
    Wire.write(B01001111); //Command Byte - Pot 1
    //Wire.write(B10000111);
    Wire.write(0x87); //Command Byte - Config Reg
  //int x = Wire.endTransmission();
  //Serial.println(vol, DEC);
  Wire.endTransmission();
  digitalWrite(CEVolume, HIGH);
}
Logged

Netherlands
Offline Offline
Tesla Member
***
Karma: 90
Posts: 9401
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


do you have a link to the datasheet of the DS1881?

Wire.beginTransmission(0x28); has a return value that you do not check ...

Code:
void loop()
{

  if (digitalRead(volButton) == HIGH) vol--;
  if (vol >= 63) vol = 34;
  if vol <= 0) vol = 34;

  changeVolume();

  Serial.println(vol);
  delay(1000);
}

Can you explain how changeVolume() works as it nowhere uses the vol parameter?
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Whoops, meant to include the link to the datasheet.
http://datasheets.maximintegrated.com/en/ds/DS1881.pdf

I had the changeVolume looking like this

Code:
void changeVolume()
{
  digitalWrite(CEVolume, LOW);
  Wire.beginTransmission(0x28);
    Wire.write(B01010000); //slave address byte
    Wire.write(vol); //Command Byte - Pot 0
    Wire.write(vol); //Command Byte - Pot 1
    Wire.write(0x87); //Command Byte - Config Reg
  Wire.endTransmission();
  digitalWrite(CEVolume, HIGH);
}

I was letting the vol variable go from 34 to negative numbers and it wasn't until vol reached -1 that any sound would come out of the speaker and it was loud. I couldn't get different levels out of it and once I reset vol back to 34, would it be silent again.

So with that not working, I was manually adjusting the volume. From what I understand from the datasheet, there were 4 commands to adjust the pots.

The first one is the slave address, then pot0, pot1, and then the command bytes. I left the command byte to the default setting which should be Configuration Option 2 table so the steps are from 0-33 and 34 is mute. The first two bytes are for the pot address (00 for pot0, 01 for pot1).

That is where I am at right now.

I was manually adjusting the pot0 to see if it was the code that was the issue, I was trying B00100001, which should be mute (34). Hardly any sound came out of the speaker at this point, so I tried B00001111 (15) and still hardly any sound came out of the speaker.

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I attached the schematic that I am using. I am using a OPA134UA.

This is my first time using fritzing, sorry if it is hard to read. smiley-wink  The purple wire comes from an input from the computer speaker output and the speaker is driven by a TDA7297. A analog pot does work on the stereo amp but I am trying to get it digitally controlled so I know it is not the amplifier that is the problem.
Logged

Pages: [1]   Go Up
Print
 
Jump to: