Go Down

Topic: toneAC v1.2 - Twice the volume, higher quality, higher frequency, etc. (Read 74162 times) previous topic - next topic

teckel


Hi,

I've read that piezzo buzzers (magnetic ones too) can generate a "back emf" when they are heavily shocked (Arduino box falling on the ground for instance) which induces enough voltage and current to destroy the microcontroller output. One should add a diode in parallel to the buzzer to prevent this.

What do you think about this aspect?

Thanks in advance ^_^


A piezo can work just about as well as a microphone and a speaker.  So, a shock like dropping or tapping it can generate a large voltage pulse that will back-feed to the microprocessor.  While the voltage is high, the current is probably very low.  So even then, it's not very likely.  However, it's always good to provide some level of protection.

But, installing a diode is not the solution to this.  It's better to install a resistor to limit the back voltage.  With toneAC I suggest using a 100 Ohm resistor, which will limit the voltage and prevent a problem.  It's even more important NOT to use a diode with toneAC as it uses an alternating current and therefore the piezo will only ever "push" and never "pull", nullifying most of the advantages that toneAC has.

In any case, use about a 100 Ohm resistor inline with one of the pins when using a piezo buzzer.

Tim
My platforms Arduino, Teensy 3.2, Arduino Pro Mini, ATmega328
My libraries: NewPing, LCDBitmap, toneAC, toneAC2, NewTone, TimerFreeTone
My projects: https://dogblocker.com & https://baconorbeer.com
My beer: Great Lakes Brewing Co. Lake Erie Monster

mwahahaha


polymorph

First off, thank you for writing this.

I have a few questions, if you don't mind.

What is the maximum reliable frequency this can output? I'm hoping that you'll say it can go up to 150kHz for RFID and some other projects I've got in mind.

Will it work on a Nano V3.0? I'm guessing that it can because both it and the Uno use the 328p.
Steve Greenfield AE7HD
Drawing Schematics: tinyurl.com/23mo9pf - tinyurl.com/o97ysyx - https://tinyurl.com/Technote8
Multitasking: forum.arduino.cc/index.php?topic=223286.0
gammon.com.au/blink - gammon.com.au/serial - gammon.com.au/interrupts

teckel


First off, thank you for writing this.

I have a few questions, if you don't mind.

What is the maximum reliable frequency this can output? I'm hoping that you'll say it can go up to 150kHz for RFID and some other projects I've got in mind.

Will it work on a Nano V3.0? I'm guessing that it can because both it and the Uno use the 328p.


The maximum frequency is VERY high, but depends on the speed you're clocked at.  Here's a link to the maximum frequency based on microcontroller clock speed:

https://code.google.com/p/arduino-tone-ac/wiki/toneAC_Frequency_Limits

So yes, toneAC will work at EXTREMELY high frequencies, even when running at lower clock speeds.  A Nano running at 16 Mhz can produce up to 2.66 MHz output with toneAC.  Even at 1 Mhz, you can generate a 166.66 kHz output.

And yes, Nano v3.0 will work just fine with toneAC, it works with all ATmega chips.  The Nano uses a ATmega328 so it's exactly like the Uno (uses pins 9 & 10).

Tim
My platforms Arduino, Teensy 3.2, Arduino Pro Mini, ATmega328
My libraries: NewPing, LCDBitmap, toneAC, toneAC2, NewTone, TimerFreeTone
My projects: https://dogblocker.com & https://baconorbeer.com
My beer: Great Lakes Brewing Co. Lake Erie Monster

polymorph

Thanks!

Pardon my ignorance, but... what is the resolution? Specifically at the >100kHz range?
Steve Greenfield AE7HD
Drawing Schematics: tinyurl.com/23mo9pf - tinyurl.com/o97ysyx - https://tinyurl.com/Technote8
Multitasking: forum.arduino.cc/index.php?topic=223286.0
gammon.com.au/blink - gammon.com.au/serial - gammon.com.au/interrupts

teckel


Thanks!

Pardon my ignorance, but... what is the resolution? Specifically at the >100kHz range?


The resolution is always 1 bit, it's a square wave.  That's all that toneAC or just about any other audio library will do on the Arduino, a square wave.

I assume you're trying to output a sound sample?  That would require an analog waveform, which the Arduino is not good at all at doing (nor could it ever hope to output anything of any quality at a 100kHz range).

Tim
My platforms Arduino, Teensy 3.2, Arduino Pro Mini, ATmega328
My libraries: NewPing, LCDBitmap, toneAC, toneAC2, NewTone, TimerFreeTone
My projects: https://dogblocker.com & https://baconorbeer.com
My beer: Great Lakes Brewing Co. Lake Erie Monster

polymorph

My apologies, I was not clear.

I meant the frequency resolution. A quick look at the files I downloaded would indicate that the resolution at lower frequencies the frequency resolution is better than at some point where the prescaler must change, and there are larger steps in the frequency.

Kind of like how millis() is milliseconds and has an actual resolution of 1ms, but micros(), although it is microseconds and can be given any number, has an actual resolution of 4us.

Actually I'm looking to use this for an RFID card reader in the 125kHz to 134kHz range. I thought I might try some frequency hunting to look for the tag's actual resonant frequency.
Steve Greenfield AE7HD
Drawing Schematics: tinyurl.com/23mo9pf - tinyurl.com/o97ysyx - https://tinyurl.com/Technote8
Multitasking: forum.arduino.cc/index.php?topic=223286.0
gammon.com.au/blink - gammon.com.au/serial - gammon.com.au/interrupts

teckel


My apologies, I was not clear.

I meant the frequency resolution. A quick look at the files I downloaded would indicate that the resolution at lower frequencies the frequency resolution is better than at some point where the prescaler must change, and there are larger steps in the frequency.

Kind of like how millis() is milliseconds and has an actual resolution of 1ms, but micros(), although it is microseconds and can be given any number, has an actual resolution of 4us.

Actually I'm looking to use this for an RFID card reader in the 125kHz to 134kHz range. I thought I might try some frequency hunting to look for the tag's actual resonant frequency.


That's correct, the steps between frequencies gets larger as the frequency increases.  In about the 125 kHz to 134 kHz range, there will be these frequencies: 123,077, 125,000, 126,984, 129,032, 131,148, 133,333 & 135,593 Hz (basically about a 2 kHz step).  As these are based on the clock frequency of the microcontroller, they will also be off depending on your oscillator and ambient temperature (which is why I gave one below and one above the range you're looking for).

Basically, toneAC can generate frequencies in that range, but if accuracy is important, the ATmega is not an ideal platform as it won't be very granular in frequency and it will vary from board to board based on the microcontroller timer.

Also, I would suggest using the frequencies listed above as they will calculate exactly to a different frequency.  For example, if you told toneAC to generate a 127,000 Hz frequency, it would generate a 129,032 Hz frequency instead.  So, you probably won't get the results you're looking for.  In other words, you should use the above frequencies with toneAC and not any in-between.

I hope this answers your question better.

Tim
My platforms Arduino, Teensy 3.2, Arduino Pro Mini, ATmega328
My libraries: NewPing, LCDBitmap, toneAC, toneAC2, NewTone, TimerFreeTone
My projects: https://dogblocker.com & https://baconorbeer.com
My beer: Great Lakes Brewing Co. Lake Erie Monster

polymorph

Yes, that answers my questions. Those are exactly the sorts of details I was looking for. Thank you!
Steve Greenfield AE7HD
Drawing Schematics: tinyurl.com/23mo9pf - tinyurl.com/o97ysyx - https://tinyurl.com/Technote8
Multitasking: forum.arduino.cc/index.php?topic=223286.0
gammon.com.au/blink - gammon.com.au/serial - gammon.com.au/interrupts

Peter_n

toneAC with Dickson charge pump

I wanted to set my 433MHz TX module to 5V or 12V, to be able to use it at maximum and reduced power.
The Dickson charge pump seems a good solution for that, but it needs two pins with alternating signals.
That is why I decided to use the toneAC, and it works very well. Without load the output is 14V.

The capacitor at the end is 47uF and it is too small. The TX module empties it in 10ms.
The extra bypass diode is to have a voltage close to 5V when the charge pump is not used.
The 470 ohm resistors are to reduce the peak currents, they can be 120 ohm as well. I need to reduce the peak current, because I have a sensitive 433MHz receiver on the same board as well.

The name of the circuit can be "voltage multiplier" or "voltage tripler" or "charge pump" or something like that. This specific circuit is a "Dickson charge pump".

Update: The output is very weak. I changed the resistors from 470 ohm into 220 ohm.
Test with a load of 10k (about 1mA load):
1 kHz : 4.97 V
2 kHz : 7.07 V
5 kHz : 9.42 V
10 kHz : 10.36 V
20 kHz : 10.71 V
50 kHz : 10.83 V
100 kHz : 10.84 V
200 kHz : 10.84 V
500 kHz : 10.81 V
1 MHz : 10.74 V
2 MHz : 10.41 V
A 1000uF capacitor is charged to 13V in 10 seconds. That is enough for the TX module for 300 ms (50% duty cycle) and during that, the voltage is lowered to 10V. That is enough to switch a light on an off, but not for an alarm. I could have used two or three 5V TX modules instead, with different TX power levels.

protoc0l

Great library!  I'm driving a piezo from a 3v cell, so this really helps!

On an Attiny44a, the OC1A/B pins are shared with MOSI/MISO, which works (and piezo chirps when uploading :) ) with the changes I made to the original code.

I need to use the OC0A/B & TCNT0 instead, which is only 8bit, but I need to drive @ ~4000hz, is it possible?  

Can I chain or loop the timer or interrupt to get ~4000hz? Is there an example of this somewhere?

thx!

teckel

Great library!  I'm driving a piezo from a 3v cell, so this really helps!

On an Attiny44a, the OC1A/B pins are shared with MOSI/MISO, which works (and piezo chirps when uploading :) ) with the changes I made to the original code.

I need to use the OC0A/B & TCNT0 instead, which is only 8bit, but I need to drive @ ~4000hz, is it possible? 

Can I chain or loop the timer or interrupt to get ~4000hz? Is there an example of this somewhere?

thx!
toneAC uses timer 1 (OC1A/B) because that timer has the ability to do the automatic alternating push/pull.  Other timers won't allow this.  However, I also have a toneAC2 library which should work quite nicely for your needs.  That is, if you're using a ATmega and not an ATtiny.  Why use a ATtiny anyway?  The price is about the same, the ATmega has lower power modes, and the ATmega is available in a smaller footprint.  I really find no reason for the ATtiny.

Anyway, if it must be an ATtiny for whatever reason, just create your own loop at whatever frequency you want that flips two pins from on to off and vise versa.  That would be very simple and easily run at 4kHz.

Tim
My platforms Arduino, Teensy 3.2, Arduino Pro Mini, ATmega328
My libraries: NewPing, LCDBitmap, toneAC, toneAC2, NewTone, TimerFreeTone
My projects: https://dogblocker.com & https://baconorbeer.com
My beer: Great Lakes Brewing Co. Lake Erie Monster

protoc0l

... Why use a ATtiny anyway?  The price is about the same, the ATmega has lower power modes, and the ATmega is available in a smaller footprint.  I really find no reason for the ATtiny.
Thx for reply, not really married to the attiny, but I do need something that can run @ ~2v, and I can get the t44a for 80 cents (@10). I did see some atmega8's around the same price, but I think the vcc was higher. Will take another look.


Peter_n

2V is low. The ATmega8L starts at 2.7V.

I did see a trick once ( perhaps on Hackaday ) that an ATtiny or ATmega starts at a low voltage and increased its own voltage with a voltage doubler to run normal.

teckel

Thx for reply, not really married to the attiny, but I do need something that can run @ ~2v, and I can get the t44a for 80 cents (@10). I did see some atmega8's around the same price, but I think the vcc was higher. Will take another look.


The ATmega328P can run at 1.8volts and when in low power mode use only 1μA (microamp).  I have a couple projects that I've been running for 3 years from a single set of batteries, and the batteries still have a lot left in them.
My platforms Arduino, Teensy 3.2, Arduino Pro Mini, ATmega328
My libraries: NewPing, LCDBitmap, toneAC, toneAC2, NewTone, TimerFreeTone
My projects: https://dogblocker.com & https://baconorbeer.com
My beer: Great Lakes Brewing Co. Lake Erie Monster

Go Up