Pages: 1 [2]   Go Down
Author Topic: Controlling volume from speakers  (Read 2693 times)
0 Members and 1 Guest are viewing this topic.
Toledo, OH
Offline Offline
Sr. Member
****
Karma: 19
Posts: 455
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
If you do have a problem using the library with the ATmega644, let me know.  There's specific defines in the library for that chip so it should work.  But, I don't have one to test so if there's a problem I'd like to know.

I just tried it on my 644P based board and just using a O-scope and one of your example sketches I could see the clocking on two pins. Different pins then what your library states, but I'm using a Bobuino pin 1284P/644P mapping scheme rather then the older standard Sanguino pin mapping, or whatever ever pin mapping you may have used as you developed the library. As there is no 'official Arduino' pin mapping defined one needs to be able to backtrack to the port/pin number used by the various timers sometimes.

Anyway thanks for adding the 1284P/644P support.

Lefty

The Bobuino maps pins differently than Arduino.  I believe it's pin 8 and 30 for the Bobuino.

Basically, toneAC uses the PWM pins assigned to timer 1.  You need to look at the datasheet or contact the manufacture to see which pins are OC1A and OC1B and connect to those pins.  The Arduino maps the 1284P/644P to pins 12 & 13.  Other systems may map to other pins.

Tim
Logged

Arduino Uno - Teensy 2.0 - Teensy 3.0 - Raspberry Pi Model B w/512MB RAM
My libraries: NewPing library - LCDBitmap library - toneAC library - NewTone library

Toledo, OH
Offline Offline
Sr. Member
****
Karma: 19
Posts: 455
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I tried the library out but even the loudest sound sounds so weak. smiley-sad

X9C103P is a digital potentiometer available in my country, is this okay to be used for volume control?

Sounds like you've connected to one of the correct pins, but not the other.  No matter what system you connect to, you need to connect to the OC1A and OC1B pins.  These could be mapped to any pin number.  I have no idea what derivative Arduino you have, but you need to get the datasheet or with the manufacture and tie to those pins.  The OC1A and OC1B pins are the timer 1 PWM pins, and that's always what toneAC uses.

If you figure out which pins are used, let me know what system you have and what the pins are so I can note it in the library.

Tim
Logged

Arduino Uno - Teensy 2.0 - Teensy 3.0 - Raspberry Pi Model B w/512MB RAM
My libraries: NewPing library - LCDBitmap library - toneAC library - NewTone library

Cebu City
Offline Offline
Newbie
*
Karma: 0
Posts: 34
Hi im new to arduino!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I tried the library out but even the loudest sound sounds so weak. smiley-sad

X9C103P is a digital potentiometer available in my country, is this okay to be used for volume control?

Sounds like you've connected to one of the correct pins, but not the other.  No matter what system you connect to, you need to connect to the OC1A and OC1B pins.  These could be mapped to any pin number.  I have no idea what derivative Arduino you have, but you need to get the datasheet or with the manufacture and tie to those pins.  The OC1A and OC1B pins are the timer 1 PWM pins, and that's always what toneAC uses.

If you figure out which pins are used, let me know what system you have and what the pins are so I can note it in the library.

Tim


http://www.e-gizmo.com/KIT/gizduino+%20164,324,644.html
this is the arduino atmega644 that I am using.
Here is it's pdf file inside the attachment.

* gizduino+ hardware manual.pdf (753.13 KB - downloaded 6 times.)
Logged

Cebu City
Offline Offline
Newbie
*
Karma: 0
Posts: 34
Hi im new to arduino!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

nevermind changing the pins for the atmega 644, i got it working already. smiley

but i didn't seem to get what I wanted with this approach. Although I can control it's volume now I get spiky volume output.

Here is my code:
Code:

#include <toneAC.h>

int senseMic = 0; //analog pin of gizduino //pin14
//int speakerPin = 5; //analog pin of gizduino

void setup(){
  //pinMode(senseMic, INPUT);
 

  Serial.begin(9600);
}

void loop(){
   //Serial.println(analogRead(senseMic));
  //delay(1000);
  int mapData = 0;
  int val = analogRead(senseMic);
 // Serial.println(val);
  mapData=map(val,350,52,200,20);
  //If wind is blown
  Serial.println(mapData);
 
   if (mapData > 20 || mapData < 29) {
    //Play tone
    toneAC(300,5);
  }
   else if (mapData > 30 || mapData <39) {
    //Play tone
    toneAC(300,6);
  }
     else if (mapData > 40) {
    //Play tone
    toneAC(300,7);
  }
 
  //no wind is blown
  else{
    toneAC();
  }

}

I tried adding delay and erased the spiky output that i'm hearing but it is so slow on changing volume. hmm..
Logged

Toledo, OH
Offline Offline
Sr. Member
****
Karma: 19
Posts: 455
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

nevermind changing the pins for the atmega 644, i got it working already. smiley

but i didn't seem to get what I wanted with this approach. Although I can control it's volume now I get spiky volume output.

Here is my code:
Code:

#include <toneAC.h>

int senseMic = 0; //analog pin of gizduino //pin14
//int speakerPin = 5; //analog pin of gizduino

void setup(){
  //pinMode(senseMic, INPUT);
 

  Serial.begin(9600);
}

void loop(){
   //Serial.println(analogRead(senseMic));
  //delay(1000);
  int mapData = 0;
  int val = analogRead(senseMic);
 // Serial.println(val);
  mapData=map(val,350,52,200,20);
  //If wind is blown
  Serial.println(mapData);
 
   if (mapData > 20 || mapData < 29) {
    //Play tone
    toneAC(300,5);
  }
   else if (mapData > 30 || mapData <39) {
    //Play tone
    toneAC(300,6);
  }
     else if (mapData > 40) {
    //Play tone
    toneAC(300,7);
  }
 
  //no wind is blown
  else{
    toneAC();
  }

}

I tried adding delay and erased the spiky output that i'm hearing but it is so slow on changing volume. hmm..

You need to connect to the timer 1 PWM pins for your derivative Arduino device.  The datasheet will tell you.  I list the official Arduino pins, I can't list every Arduino derivative.

Your sketch is doing just what you tell it to do, which is not what you want.  You need AT LEAST a 2 ms delay for a 500 Hz note to be played.  The way you have it, there's not enough time to actually produce the note you're requesting.  Basically, the problem isn't library, it's your sketch.

Tim
Logged

Arduino Uno - Teensy 2.0 - Teensy 3.0 - Raspberry Pi Model B w/512MB RAM
My libraries: NewPing library - LCDBitmap library - toneAC library - NewTone library

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

Quote
Debate this topic with the people who challenged me about it being 10v AC on this thread:

http://arduino.cc/forum/index.php/topic,141844.0.html

PeterH, PaulS & sbright33 specifically.
I don't see anything in that thread to support your assumption that they were disagreeing with what I said. Yes some questioned the -5V bit but no one said it was wrong. It does not generate -5V BUT the speaker "SEES" +/- 5V.

Quote
which I see you've modified from your post so it seems you're already questioning yourself.
No I haven't, I am explaining more of the theory to you. You seem to be latching onto words you don't fully understand.

Quote
50% is the loudest, but 25% will be lower volume. 
No it sounds different but the peak volume is the same because the peak amplitude is the same. There are a different mix of harmonics in the 25% wave than the 50% wave so maybe your ears are not responding equally to the different harmonic mix. You seem to have a very simplistic view of an audio signal.

Quote
I don't have a horse in this race,
That saddens me, I would have thought you would want to understand what you have done.

Logged

Toledo, OH
Offline Offline
Sr. Member
****
Karma: 19
Posts: 455
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Debate this topic with the people who challenged me about it being 10v AC on this thread:

http://arduino.cc/forum/index.php/topic,141844.0.html

PeterH, PaulS & sbright33 specifically.
I don't see anything in that thread to support your assumption that they were disagreeing with what I said. Yes some questioned the -5V bit but no one said it was wrong. It does not generate -5V BUT the speaker "SEES" +/- 5V.

I suggest you read that thread again.  Here's their quotes if you had a problem finding them:

Quote from: PeterH
So it gets 5V in alternate directions, instead of 5V one way and then 0V for half a cycle? In effect it's 5V AC rather than the 2.5V AC of the standard output. Yes, I can see how that would increase the output.

Quote from: sbright33
Or you could use a 10c transistor to amplify the 2.5v AC signal.

Quote from: vasquo
But I still don't get how you'll generate a -5 volts (with respect to ground), to achieve a +5V - (-5V) = 10V range

Quote from: PaulS
I'm missing something, I guess. How will two +5V to 0 to +5V pins toggling out of phase result in a -5V output?

These people are clearly saying that the tone library is normally 2.5 volts and toneAC can't be 10 volts.  They're not being as argumentative as you, but they are challenging your argument.  Also, if you read my comments you'll see that I was clearly stating that the speaker sees it as a +/- 5 volt signal.  We're on the exact same side dude!  But, they wanted to argue that it was only 5 volts, they couldn't understand that the speaker would see it as +/- 5 volts, and wanted to argue that the normal tone library was only 2.5 volts.  I didn't care to argue so I didn't.  But, it's obvious you're looking for an argument.  This sounds like a great debate that you all can get involved in.  Argue your differences with those that care instead of being a troll here, you're not helping this thread.

Quote
which I see you've modified from your post so it seems you're already questioning yourself.
No I haven't, I am explaining more of the theory to you. You seem to be latching onto words you don't fully understand.

Yeah, *I* don't understand.  Yet, I wrote the library and you didn't.  How about you and the people listed above come to a consensus and then let us all know who doesn't fully understand.  *I*, the guy who wrote the library, doesn't care which of you are more right.  The concept is exactly the same, twice as much voltage is getting to the transducer, and it's therefore much louder.

Quote
50% is the loudest, but 25% will be lower volume.  
No it sounds different but the peak volume is the same because the peak amplitude is the same. There are a different mix of harmonics in the 25% wave than the 50% wave so maybe your ears are not responding equally to the different harmonic mix. You seem to have a very simplistic view of an audio signal.

Yeah, that's me, simplistic.  The guy who wrote the library and tested the sound pressure level with a SPL meter (not my ears) and created a linear volume control for the library that works.  Have you even tried the library?  Have you listened to it with your ears?  Or measured the output with a sound pressure level meter as I have?  It doesn't seem you have, as if you did, volume level 1 and 10 are clearly quite a bit different in SPL, to my ears, yours, and to a meter designed to measure SPL.  But, maybe your superior ears will hear volume level 1 and level 10 as the same SPL.  You can then call my library worthless and delete it, I won't be offended.  But, you probably shouldn't comment on something you haven't tried.  Who knows, maybe you can still learn something?  Unlikely, I'm sure, but you never know.

Quote
I don't have a horse in this race,
That saddens me, I would have thought you would want to understand what you have done.

It would seem that you should want to know what *I* have done, not the other way around.  I wrote the library on purpose, it wasn't an accident as you seem to want to imply.  I didn't discover something, this is common knowledge, and I'm surprised that the tone library wasn't written to work like toneAC in the first place.  Or, wasn't rewritten correctly by someone far smarter than myself, like you maybe?

Honestly, how about you just go troll somewhere else.  I've already given you the people who have an alternate view and tried to express that we have the same view (speaker sees it as +/- 5v).  If you're looking for an argument, take it up with them.  Maybe after you can come back and let us know who got schooled.  Can I express anymore how little *I* care who is right?  I think it boils down to perception, or semantics at best.

Tim
« Last Edit: January 29, 2013, 10:54:06 am by teckel » Logged

Arduino Uno - Teensy 2.0 - Teensy 3.0 - Raspberry Pi Model B w/512MB RAM
My libraries: NewPing library - LCDBitmap library - toneAC library - NewTone library

Pages: 1 [2]   Go Up
Jump to: