Miniature Speaker and ATMEGA

Go To Last Post
22 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am directly driving a miniature pc mount speaker (the kind that looks like a piezo buzzer but its actually a speaker with a coil) from one of the AVR pins with a series resistor (100Ω) to limit the current.

 

The ATMEGA is running from batteries at 3V.

 

The speaker is only used as feedback for when a button is pressed.  (~ 200uS 2k beep)

 

I know I should use a diode across the speaker to guard against reverse current, but given the small current and voltage used will it damage the ATMEGA if I don't use it?

 

Thanks in advance

-alx

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


in-lieu of the diode, a jellybean bipolar transistor for current gain (megaAVR output to piezo)

from AVR Butterfly Evaluation Kit - User Guide (page 35, C7)

 

"Dare to be naïve." - Buckminster Fuller

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am not using a Piezo element.  I am using a magnetic speaker.  The kind that has a coil and magnet.

-alx

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

alxgarza wrote:

I am directly driving a miniature pc mount speaker (the kind that looks like a piezo buzzer but its actually a speaker with a coil) from one of the AVR pins with a series resistor (100Ω) to limit the current.

 

The ATMEGA is running from batteries at 3V.

 

The speaker is only used as feedback for when a button is pressed.  (~ 200uS 2k beep)

 

I know I should use a diode across the speaker to guard against reverse current, but given the small current and voltage used will it damage the ATMEGA if I don't use it?

 

Thanks in advance

 

You don't need any diode, since you are correct, the 100Ω resistor is keeping any back current low, the internals of the AVR is more than enough to take care of that.

Give you a hint:

Make a routine to increase the frequency of the beep on the speaker, start with 100Hz and go up to 5kHz or around it.

Make it increase in 100Hz steps each time you press one switch, or decreases 100Hz if another switch.

Try and find the best frequency that particular speaker yell louder.  There is one, is the one that resonates the speaker.

Of course if you don't have an oscilloscope to measure such frequency, you will need to count how many increases or decreases you made through the switches.

Then you can fine tuning such frequency, changing it by 10Hz.

Once you find the right frequency, just use it as fixed on your program.

 

Wagner Lipnharski
Orlando Florida USA

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for the quick reply.  I am driving the speaker at 2KHz, since that it the frequency the datasheet suggests. 

-alx

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

3v / (100 + 8 + 40) is 51mA

 

0.051*3 is .155w

 

Many small speakers are rated at .1w, so your circuit should make a reasonable beep. Otherwise, add a transistor amplifier and remove the resistor to get more like 1.1w. That should be nice and loud.

 

"We trained hard... but it seemed that every time we were beginning to form up into a team, we would be reorganized. I was to learn later in life that we tend to meet any new situation by reorganizing. And a wonderful method it can be of creating the illusion of progress while producing confusion, inefficiency and demoralization." Petronius Arbiter, approx. 2000 years ago.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The speaker volume is soft but acceptable for my use.  

 

My concern was if I needed to add the protection diode.

-alx

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Torby wrote:

3v / (100 + 8 + 40) is 51mA

 

0.051*3 is .155w

 

Tom,

 

3v / (100 + 8 + 40) is 20.3mA.... not 51mA. So the total power dissipated is 60.8mW, but the speaker only gets 8/(100+8+40) of that or 3.3mW... not so loud.

Ross McKenzie ValuSoft Melbourne Australia

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am directly driving a miniature pc mount speaker (the kind that looks like a piezo buzzer but its actually a speaker with a coil) from one of the AVR pins with a series resistor (100Ω) to limit the current.

If direct driving, use a speaker with a higher impedance (not 4 ohms)....The real low ones will look more like a short to the avr, which it can't drive very well.  Maybe a 30 to 100 ohm speaker.  Then you'll get more power, due to a better impedance match.

 

 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


@alx

 

I recommend that you use one of these (or equivalent).

 

Ross McKenzie ValuSoft Melbourne Australia

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

valusoft wrote:

Torby wrote:

3v / (100 + 8 + 40) is 51mA

 

0.051*3 is .155w

 

 

Tom,

 

3v / (100 + 8 + 40) is 20.3mA.... not 51mA. So the total power dissipated is 60.8mW, but the speaker only gets 8/(100+8+40) of that or 3.3mW... not so loud.

 

Um. You'd think my ancient HP could divide.

 

"We trained hard... but it seemed that every time we were beginning to form up into a team, we would be reorganized. I was to learn later in life that we tend to meet any new situation by reorganizing. And a wonderful method it can be of creating the illusion of progress while producing confusion, inefficiency and demoralization." Petronius Arbiter, approx. 2000 years ago.

Last Edited: Tue. Apr 23, 2019 - 02:49 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Torby wrote:

3v / (100 + 8 + 40) is 51mA

 

0.051*3 is .155w

{Calculation corrected in #8}

 

I may not have the sharpest eyesight in the world, but where in any of the above posts is the coil impedance of the OPs loudspeaker specified ?

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

N.Winterbottom wrote:
I may not have the sharpest eyesight in the world, but where in any of the above posts is the coil impedance of the OPs loudspeaker specified ?
You are correct... it isn't. But the ensuing calculations, if nothing else, illustrate the futility in expecting an AVR to drive a PC speaker ("with a coil") at anything other than a murmur. cheeky

Ross McKenzie ValuSoft Melbourne Australia

Last Edited: Tue. Apr 23, 2019 - 10:20 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Torby wrote:

3v / (100 + 8 + 40) is 51mA

 

0.051*3 is .155w

 

I know what happened, your "100" entered as "10", so 3 / 58 = 51mA

Yes, keys fail, we fail, old things should be discarded, or not... wait, I am not old.

Wagner Lipnharski
Orlando Florida USA

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

N.Winterbottom wrote:

Torby wrote:

3v / (100 + 8 + 40) is 51mA

 

0.051*3 is .155w

{Calculation corrected in #8}

 

I may not have the sharpest eyesight in the world, but where in any of the above posts is the coil impedance of the OPs loudspeaker specified ?

 

 

Second equation should have been mA * mA * 8

 

"We trained hard... but it seemed that every time we were beginning to form up into a team, we would be reorganized. I was to learn later in life that we tend to meet any new situation by reorganizing. And a wonderful method it can be of creating the illusion of progress while producing confusion, inefficiency and demoralization." Petronius Arbiter, approx. 2000 years ago.

Last Edited: Tue. Apr 23, 2019 - 06:07 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 illustrate the futility in expecting an AVR to drive a PC speaker ("with a coil") at anything other than a murmur. 

I wouldn't quite say that..at really low ohms, yes, blah.  However, you can get a 200ohm or so speaker, that the pin should be able to drive much better than an 8 ohm speaker.   Of course a transistor is cheap and readily available these days...let the mA out.  Sound the alert!

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Based on my 1970ish calculations of speaker boxes we use to make with tick marine plywood, and concept of power transfer, to achieve the best possible power transfer, the load impedance must be the same as the source impedance.   Considering the AVR I/O internal resistance of around 25Ω, that would be the best value for any load to suck the most power from the tinny black epoxy beast.

 

I know that most of the people here understand the reason for this, but for the ones that never saw this explanation:

 

Imagine a 6V battery the size of a car, that can supply an infinite current without dropping any voltage, with a 10 Ohms resistor in series with the positive wire.

Now lets apply different loads to this 6V powered wires.

 

1) 5Ω.  The (TR) Total Resistance presented to the battery will be 15Ω, the (C) Current will be 6/15 = 0.4A, the (PL) Power over the 5Ω Load will be R*I² = 5 * 0.4² = 0.8W.

2) 8Ω.  The TR = 18Ω, C = 6/18 = 0.3333A, PL = 8 * 0.333² = 0.888W

3) 10Ω. The TR = 20Ω, C = 6/20 = 0.3, PL = 10 * 0.3² = 0.9W

4) 12Ω. The TR = 22Ω, C = 6/22 = 0.2727, PL = 12 * 0.2727² = 0.89W

5) 15Ω. The TR = 25Ω, C = 6/25 = 0.24, PL = 15 * 0.24² = 0.864W.

6) 100Ω. The TR = 110Ω, C = 6/110 = 0.05454, PL = 100 * 0.05454² = 0.29W

 

So you see, the maximum possible power over the load, is exactly when the load resistance (impedance) is the same as the internal source impedance, in the above examples, 10Ω.    As the internal source resistance of the AVR port pin is 25Ω, that is the best value for a load to receive the maximum power from the port.

 

It also means, trying to achieve that, it will need to have 25Ω internal and another 25Ω external, total 50Ω, a 5V powered AVR will supply 5V/50 = 100mA... what we know it will not be very healthy for the poor epoxy boybug.   Even that the internal resistance is 25Ω the current capacity of that pin circuit should never each that current, it was not designed for it.  The 25Ω was the best lower resistance the engineering were able to do, not meaning we could stretch it to the best power transfer concept.  The top current you can think to torture that small epoxy animal is 20mA, what means not going lower than 220Ω of external resistance upon 5VCC.    Of course I already did lower than that, but I have no much feelings when trying to test the Machiavelli's limits on my bench.   There are some designs connecting 7 segments LED displays directly between port pins, no transistors on the common anodes or cathodes, it forces current way over the specs, and AVR will always be AVR, it works. 

Wagner Lipnharski
Orlando Florida USA

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Wow,  ask a techie a really simple question (expecting a really simple answer), and get pages of techno-babble in reply.

 

"Do I need a protection diode?"   No,  the little speaker is not being subjected to energy levels that require protection.

 

" The speaker is only used as feedback for when a button is pressed.  (~ 200uS 2k beep)  "    

Actually, this must be a 200 >> milli <<< Second  2KHz beep.  A 200 >> micro <<< uSecond burst would only be less than one cycle of the 2KHz beep.  Watch your m's and u's, and your 'p's and 'q's will take care of themselves.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Simonetta wrote:

Wow,  ask a techie a really simple question (expecting a really simple answer), and get pages of techno-babble in reply.

well, at least no-one has suggested horn loading the speaker yet ;)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 ask a techie a really simple question (expecting a really simple answer) and get pages of techno-babble in reply

True, it can be droning on & on with seemingly too many details & hypotheses.  Some of this is brought about by poor questions or mentioning something questionable (Does my AVR need a heatsink, it seems to be running hot with 7 volts Vcc?). Someone might also be more adverse to techno-babble, if they are more of a reality tv show fan.

 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Simonetta wrote:

" The speaker is only used as feedback for when a button is pressed.  (~ 200uS 2k beep)  "    

Actually, this must be a 200 >> milli <<< Second  2KHz beep.  A 200 >> micro <<< uSecond burst would only be less than one cycle of the 2KHz beep.  Watch your m's and u's, and your 'p's and 'q's will take care of themselves.

 

I saw that 200uS, but understood as 200 "u" Siemens... and 2KHz is 2 potassium Hz? Kelvin? whatever it may be in techno-to-be babble-gurgling.

Anyway, clearing to 2 kHz and 200 µs, but still short... 

That is the problem when falling into a high-energy-techie-pit without the proper radiation shielding. wink

 

Reference for future reading:

https://www.nist.gov/pml/weights-and-measures/metric-si/si-units

Wagner Lipnharski
Orlando Florida USA

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Simonetta wrote:

Wow,  ask a techie a really simple question (expecting a really simple answer), and get pages of techno-babble in reply.

 

"Do I need a protection diode?"   No,  the little speaker is not being subjected to energy levels that require protection.

 

" The speaker is only used as feedback for when a button is pressed.  (~ 200uS 2k beep)  "    

Actually, this must be a 200 >> milli <<< Second  2KHz beep.  A 200 >> micro <<< uSecond burst would only be less than one cycle of the 2KHz beep.  Watch your m's and u's, and your 'p's and 'q's will take care of themselves.

 

Probably ok without one. 

 

"We trained hard... but it seemed that every time we were beginning to form up into a team, we would be reorganized. I was to learn later in life that we tend to meet any new situation by reorganizing. And a wonderful method it can be of creating the illusion of progress while producing confusion, inefficiency and demoralization." Petronius Arbiter, approx. 2000 years ago.