Pages: 1 [2] 3 4   Go Down
Author Topic: Simple Volume Control  (Read 4297 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 57
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you for your answer.
I will check yous suggested link, but this is a protoshield with cu wire on pins, so if that easier I resoldering my shield.

Can you offer a link or a tutorial about the shared spi and spi.transfer?
Logged

Southern California
Offline Offline
God Member
*****
Karma: 5
Posts: 539
I like blinky lights
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

If you Google for something like "arduino multiple spi devices" you'll find a lot of hits. Here's one:

http://tronixstuff.wordpress.com/2011/06/15/tutorial-arduino-and-the-spi-bus-part-ii/

Each slave chip will have its own Arduino pin that goes to its Chip Select pin. All slave chips will share the Arduino MOSI, MISO, and SCK pins. You just set each chips CS pin to low, use SPI.transfer(), then set it back to high:

digitalWrite(chip1_cs_pin, LOW);
SPI.transfer(chip1data);
digitalWrite(chip1_cs_pin, HIGH);

digitalWrite(chip2_cs_pin, LOW);
SPI.transfer(chip2data);
digitalWrite(chip2_cs_pin, HIGH);
Logged

http://en.wiktionary.org/wiki/magagna <-- My last name.  Pretty apt.

Offline Offline
Jr. Member
**
Karma: 0
Posts: 57
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks a lot!
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 57
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Now I resoldering my shield, now I can control the IC.
But this only works on 0 and 255 all other value have a louder or quiter but the quality is criticaly :S
On the value 255 the sound quality is perfect, but all other value is sound makes crackling..
I don't understand what is the problem

Here is my code (based on spi by hand):
int SS1 = 5;
int CLK = 7;
int MOUT = 6;

byte ch1 = B00010001;
byte ch2 = B00010011;
byte ch3 = B00010010;
byte ch4 = B00010000;
byte ch5 = B00010101;
byte ch6 = B00010100;

byte work = B00000000;

void setup() {
  pinMode(SS1, OUTPUT);
  pinMode(CLK, OUTPUT);
  pinMode(MOUT, OUTPUT);
  digitalWrite(SS1, HIGH);
  spi_out(SS1, ch1, 255);
  spi_out(SS1, ch2, 255);
  spi_out(SS1, ch3, 255);
  spi_out(SS1, ch4, 255);
  spi_out(SS1, ch5, 255);
  spi_out(SS1, ch6, 255);
}

void spi_transfer(byte working) {
  for(int i = 1; i <= 8; i++) {
    if (working > 127) {
      digitalWrite (MOUT,HIGH);
    } else {
      digitalWrite (MOUT, LOW);
    }
    digitalWrite (CLK,HIGH);
    working = working << 1;
    digitalWrite(CLK,LOW);
  }
}

void spi_out(int SS, byte cmd_byte, byte data_byte) {
  digitalWrite (SS, LOW);
  work = cmd_byte;
  spi_transfer(work);
  work = data_byte;
  spi_transfer(work);
  digitalWrite(SS, HIGH);
}

void loop () {

}

when arduino power of the sound volume state go to middle posistion and the quality is so bad again. smiley-sad
« Last Edit: April 15, 2012, 11:14:20 am by myDunio » Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 57
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Does anybody can tell me why has the volume control a bad quality when I try to adjust between 0 to 255???
Help me please!

I soldered all A pin to sound signal all B pin the signal gnd and W pins go to the amplifier.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 57
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I tried to swap the signal and ground pins, a tried to swap the spi pins but always the same.
On 0% and 100% the sound quality is perfect all other state has so bad quality smiley-sad
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 506
Posts: 31345
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Your problem is probably with your circuit layout, and lack of decoupling between the analogue circuits and digital circuits.
You should use a star ground system. That is one where the ground lines are not chained but all connected to a single point.
Also short leads are important, and don't route analogue signals close to digital ones.

Let's see both your schematic and a photo of your realisation of the schematic.

Have you put an oscilloscope on the output to see where the distortion is coming from?
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 57
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

My schematic looks like this:

Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 506
Posts: 31345
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I am surprised that you have not got AC coupling. Are you sure that your audio signal is confined in the 0 to 5V range? If not it will distort, unless you connect Vss to a -5V supply.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 57
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Can you tell me this a little more expand?
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 506
Posts: 31345
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

All audio signals are AC signals, that is they have positive and negative peaks with respect to the signal ground.
The way you have your circuit assumes that your AC audio signal has a superimposed DC offset level of 2.5V on it. It is most unlikely that this is the case. So you have two choices:-

1) Make the signal have a 2.5V DC offset on it by taking the ground of your audio to a fixed 2.5V signal generated by two 1K resistors forming a potential divider between +5 and 0 on the arduino. This point will have to be the ground for all subsequent audio signals.

2) Make your circuit able to cope with the negative peaks of the audio circuit by supplying a -5V supply to the Vss pin of your chip.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 57
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I know it is a big wish but could you draw down what i should do. I am not an expert, but if you draw it down i can do it. smiley-confuse
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 506
Posts: 31345
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The simplest is just to connect an other 5V supply. With the +ve being connected to ground and the -ve to Vss.
Do you not want to do that solution?
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 57
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So I do not get the 5v from arduino? Do I need an external 5V Dc supply? Thats all?
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 506
Posts: 31345
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
So I do not get the 5v from arduino?
Yes you do!!!

You need ANOTHER 5V supply that will act as a -5V supply for your chip.
Logged

Pages: 1 [2] 3 4   Go Up
Jump to: