Pages: 1 2 3 [4]   Go Down
Author Topic: toneAC v1.2 - Twice the volume, higher quality, higher frequency, etc.  (Read 11817 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

Library toneAC version 1.2 tested with Uno, Leonardo, Mega 2560, ATmega8 16MHz. Everything is okay.
Library toneAC version 1.2 with option TONEAC_TINY tested with ATmega8 16MHz. Also okay, 140 bytes smaller.

The TONEAC_TINY version has implications for the source code.
If I would use toneAC(1000,5); and switch to TONEAC_TINY, I must change that line. That is not obvious, since it is the same function "toneAC".
The second parameter changes from volume to duration.
Adding a second parameter (an unused volume byte) changes the size saving from 140 to 106.
I don't know what to think of it.

It was an oversight not changing the function name for TONEAC_TINY.  I now changed the function name to toneAC_tiny() when using the TINY code.

Adding the volume in for TINY code makes the TINY savings only 52 bytes on my 1.0.3 compile on Uno.  If it's only 52 bytes of savings I should probably just remove the TINY code totally.

What about a ToneAC page in the Playground section ?

That's the plan, just haven't got to it yet.

Tim
« Last Edit: January 31, 2013, 12:54:19 pm 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

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

Hi. Can you add ADSR with your library sir? smiley

http://en.flossmanuals.net/pure-data/audio-tutorials/envelope-generator/
Logged

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


Can't be done with toneAC as the ATmega controls all the switching.  In order to do ADSR (Attack-Decay-Sustain-Release) we should first create a sine wave instead of a square wave.  To do a sine wave, we need to interrupt the ATmega's PWM switching and adjust the duty, this takes valuable CPU cycles.  Further, to do ADSR we would need to also adjust the amplitude while the note is being played, further using limited CPU cycles.

All of this "could" be done on the ATmega.  But, I'm not sure what the frequency range would be.  It would also be well outside the scope of the toneAC library as it would be quite large, slow (CPU intense), and limit the frequency range by a huge amount.

Further, to really do ADSR correctly, it would need to be able to output the release phase of the previous note as the current note was starting the attack phase.  This really disqualifies the ATmega as an option.

You'd probably need a more powerful processor and one designed to output audio to really do what you're looking for effectively with any amount of fidelity.

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

What about a ToneAC page in the Playground section ?

toneAC in the playground:

http://playground.arduino.cc/Code/ToneAC

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

Des Moines, Iowa, USA
Offline Offline
Jr. Member
**
Karma: 0
Posts: 52
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I don't have the code handy - but waaaay back when I was kid, I remember playing around on my TRS-80 Color Computer with the PLAY command; there was a way, via using certain values (I think random notes played with very, very short durations) with a rapidly decreasing volume level (the CoCo had a 6 bit DAC - so there were 64 volume levels) - you could make an "explosion" or "gun" sound of sort...

Nice to see a CoCo reference here... I recently ported a 1983 Extended Color BASIC program I wrote on the CoCo over to Arduino C (line by line, as literally as possible) and I put in a placeholder for the CoCo's SOUND command. It only took tone and duration, though. There was no built in provision to do noise or volume.

But the Extended Basic PLAY command did allow volume and some great tricks could be done with it. I have been working on a PLAY command, and finding this thread is helpful as it sounds like it would be better to use than what I was working on.
Logged

Embedded Software Engineer
UNO | Leonardo | Due | Teensy | BASIC Stamp
http://www.subethasoftware.com

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

Hi ,
I was trying to use the toneAC library to produce ultrasound in the 20kHz range. Firstly, the library works brilliantly and thank you for that smiley .
The only issue that i have been having is that sound isin't loud enough. I was using a standard 4 ohm buzzer and the sound output coming from it dosnt seem to be loud enough.

I tried using an Amp LM386 circuit to amplify the output .. described here http://web.mit.edu/6.s28/www/schematics/lm386.htm
But i then had to resort to use one of the 2 pins(9 or 10) which brought the clicking soung back. I have an Atmeg168.

Any you help me figure out how can i raise the output volume. I want t be able to detect the sound in a range of abt 10 m.

Lastly, Im fairly new to this smiley-grin
Logged

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

Hi ,
I was trying to use the toneAC library to produce ultrasound in the 20kHz range. Firstly, the library works brilliantly and thank you for that smiley .
The only issue that i have been having is that sound isin't loud enough. I was using a standard 4 ohm buzzer and the sound output coming from it dosnt seem to be loud enough.

I tried using an Amp LM386 circuit to amplify the output .. described here http://web.mit.edu/6.s28/www/schematics/lm386.htm
But i then had to resort to use one of the 2 pins(9 or 10) which brought the clicking soung back. I have an Atmeg168.

Any you help me figure out how can i raise the output volume. I want t be able to detect the sound in a range of abt 10 m.

Lastly, Im fairly new to this smiley-grin


Humans can't hear well in the 20kHz range.  Also, many transducers don't produce much at that frequency either.  You would need an ultrasonic transducer designed for that range as well as a SPL meter to actually measure the sound output in that frequency range.  Basically, you need a different transducer and a different way to measure the volume (not your ears).

As far as the transducer, something like the PROWAVE - 250ST180 would work well, that's what I use.  Keep in mind, when you're creating a 20-25kHz sound, humans can't hear it at all.  So, while it may be able to output 105dB you won't be able to hear it at all.

To measure the volume at ultrasonic frequencies, you'll need a SPL meter.  Depending on your age and how many concerts you've gone to, the max you may be able to hear is probably in the 15kHz to 17kHz range.  Here's a Digital Sound Level Meter.  But, you can get older models on eBay for cheaper.

Hope that helps!

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

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

Hey Thanks for that... im using ultrasound to transfer a code to a phone... So i actually do want to make sue humans cant here it.... 20k is used because the phone microphone has a die out beyond 22k... i been recording the ultrasound and using a fourier transform library on the phone that give be a power output. So i can measure if the sound is being generated. I will try using the transducer you'v mentioned.

Coming back to the amplifier question, how do i connect it to an amplifier. For the time being i am using an 8w 8 ohm buzzer that i got from a set of altec lansing speakers..
 
 
Logged

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

Hey Thanks for that... im using ultrasound to transfer a code to a phone... So i actually do want to make sue humans cant here it.... 20k is used because the phone microphone has a die out beyond 22k... i been recording the ultrasound and using a fourier transform library on the phone that give be a power output. So i can measure if the sound is being generated. I will try using the transducer you'v mentioned.

Coming back to the amplifier question, how do i connect it to an amplifier. For the time being i am using an 8w 8 ohm buzzer that i got from a set of altec lansing speakers..

You can't make it 20kHz and expect humans to hear it.  We can't hear sounds generated at that frequency, it's at the very outer edge of what even a baby can hear, and even then it would be EXTREMELY soft.  Adults max out more in the 15kHz range.  Here's a website for you to test the maximum frequency you can hear.

Therefore, it doesn't matter how big the amplifier is, you're not going to hear a 20kHz signal.

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

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

Thanks tim.

Also.. I do not want to hear the sound. Infact i want to make sure that it cant be head hence i am using this frequency. The only reason i need the amplifier is so that i can increase the volume up to a point that the phone can read it . do a fourier transform and then try and distinguish a particular frequency from another and noise... I can presently do that with a standard audio amplifier circuit but the "Volume" or db value of those frequencies is not high to distinguish them from noise enough beyond a certain distance(1 Meter in the present case) i want to extend it till about 5 M.

So can you suggest how can i connect the two outputs from the Arduino to an amplifier circuit?
Logged

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

Thanks tim.

Also.. I do not want to hear the sound. Infact i want to make sure that it cant be head hence i am using this frequency. The only reason i need the amplifier is so that i can increase the volume up to a point that the phone can read it . do a fourier transform and then try and distinguish a particular frequency from another and noise... I can presently do that with a standard audio amplifier circuit but the "Volume" or db value of those frequencies is not high to distinguish them from noise enough beyond a certain distance(1 Meter in the present case) i want to extend it till about 5 M.

So can you suggest how can i connect the two outputs from the Arduino to an amplifier circuit?

I think it would be easier and cheaper to use a transducer that's designed to output ultrasonic frequencies like the  PROWAVE - 250ST180.  Also, you would need mic that's also tailored for ultrasonic frequencies.  The fall-off from most standard transducers and mics are both quite high beyond 17kHz.  In other words, if you want to transmit and receive at ultrasonic frequencies you should be using drivers and mics that are designed for those frequencies.

Also, making an amp for an alternating signal like with toneAC would be a challenge.  You can't just use two 2N2222 transistors as you also need to alternate the ground as well, which flips between the two.  Not that it's impossible, just much more complex than a typical simple transistor circuit.  Keep in mind that toneAC is designed to be like a voltage amplifier without needing an actual circuit. In essence, it doubles the voltage, which increases the volume.

It would be much easier to just use a single transistor as an amp and keep the polarity always the same by using toneAC to drive just one pin instead of both.  In other words, just use half of the output of toneAC.  The frequency will be the same, and you'll get no volume benefit as it's not doubling the voltage.  But, you don't care about that if you're going to connect the output to a transistor tied to a larger voltage.

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

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

Hello Tim,

thank you very much for toneAC. It is a big step from tone(). I want to use it not for making sound, but producing periodical pulses with different frequencies (5...500Hz). The frequency band is working fine, but when reducing the volume to less than 10 I can see that the pulse width is changing depending of the frequency. I think you did this to bring more power to frequencies that are below the resonance of the piezo? For my project it should be opposite: At lower frequencies I need shorter pulses.

I found the following line in your code "uint8_t _tAC_volume[] = { 200, 100, 67, 50, 40, 33, 29, 22, 11, 2 }; // Duty for linear volume control.". What is the meaning of this? Can I adapt this to realize my task?

Maybe it is possible to change it to something like: toneAC(freq, pulse_length,...) ?

Regards
Thomas

(Sorry for my english but I come from Germany)
Logged

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

I found the following line in your code "uint8_t _tAC_volume[] = { 200, 100, 67, 50, 40, 33, 29, 22, 11, 2 }; // Duty for linear volume control.". What is the meaning of this? Can I adapt this to realize my task?

Maybe it is possible to change it to something like: toneAC(freq, pulse_length,...) ?

The _tAC_volume array modifies the duty cycle depending on the volume you set.  It's not linear because linear doesn't provide an accurate sound output level.  It needs to be more logarithmic to make it sound correct.

If you want more linear steps, you could simply modify the _tAC_volume array to something linear that works for your task.  Not sure how well this would work, as toneAC is designed for audio output.  I would say when using toneAC for other tasks you should always use full volume as the volume is a hack that just happens to work for speakers.

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

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

Hello Tim,

I found a solution without changing your code. I just send a "volume" that is related to the frequency (5...10Hz -> Vol=1; 10...15Hz -> Vol=2 and so on). Over all, I have pulses with ~1ms width in the frequency range from 5 to 100 Hz. Frequencies less than 5Hz are forbidden, because the pulses are getting longer than 1ms. At frequencies higher than 100Hz the pulse length is getting smaller. But this is acceptable.

This was my goal  :-)

Thank you very much for your help.
Logged

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