EEVblog Electronics Community Forum

Electronics => Microcontrollers => Topic started by: superUnknown on July 29, 2013, 01:17:09 pm

Title: Overloaded output? Arduino mega (Atmel)
Post by: superUnknown on July 29, 2013, 01:17:09 pm
I've been hooking up a speaker thru a pot and directly to PWM pins on an Arduino. I've noticed that it's loud for a few seconds and then is rather faint thereafter. There's still output, just less volume. When I try a new pin, same thing...
I've hooked it up according to the book "Arduino Cookbook" What gives? Have I fried the pins permanently? What is happening on a MCU level?
Title: Re: Overloaded output? Arduino mega (Atmel)
Post by: c4757p on July 29, 2013, 01:55:25 pm
1) Probably. 2) What kind of speaker?
Title: Re: Overloaded output? Arduino mega (Atmel)
Post by: Psi on July 29, 2013, 02:14:52 pm
Connect to the i/o through a 200R resistor, that will stop the speaker from drawing too much current.

Another thing to investigate is backemf being generated by switching the inductor (speaker).
Maybe you're getting some high voltage ringing which is damaging things.
Title: Re: Overloaded output? Arduino mega (Atmel)
Post by: superUnknown on July 30, 2013, 12:59:08 am
Datasheets   2403-260-00001
Product Photos   2403 260 00001
Standard Package   2,688
Category   Audio Products
Family   Speakers
Series   -
Type   Magnetic
Frequency Range   300Hz ~ 20kHz
Impedance   8 Ohm
Sound Pressure Level   73dB
Power - Rated   0.5W
Power - Max   1W
Height   3.61mm
Size / Dimension   15.00mm L x 11.00mm W
Shape   Rectangular
Title: Re: Overloaded output? Arduino mega (Atmel)
Post by: c4757p on July 30, 2013, 01:14:17 am
Ohm's law. 5V across 8 ohms is 5/8 = 625 mA. Average current if you're PWMing could hover around 300mA, more likely about 100mA. Absolute maximum, as in "never ever ever draw this much", per pin on most ATmegas is 40mA. Yes, you're overloading the everliving shit out of the chip.

Either connect it through a 200R resistor as Psi suggested, or use a small audio output transformer as was often done in the past when driving a low-impedance speaker from a low-current, relatively high-voltage (from the speaker's point of view) circuit.

Even better, use a cheap audio amplifier chip like LM386.

My guess is that the "Arduino Cookbook" is intending that you use a high-impedance speaker. My suggestion is to replace it with a dinner cookbook.
Title: Re: Overloaded output? Arduino mega (Atmel)
Post by: xrunner on July 30, 2013, 01:18:36 am
Ohm's law. 5V across 8 ohms is 5/8 = 625 mA. Average current if you're PWMing could hover around 300mA, more likely about 100mA. Absolute maximum, as in "never ever ever draw this much", per pin on most ATmegas is 40mA. Yes, you're overloading the everliving shit out of the chip.

Yep - beat me to it. Use a transistor driver is another idea.
Title: Re: Overloaded output? Arduino mega (Atmel)
Post by: amyk on July 30, 2013, 07:34:00 am
I've been hooking up a speaker thru a pot and directly to PWM pins on an Arduino. I've noticed that it's loud for a few seconds and then is rather faint thereafter. There's still output, just less volume. When I try a new pin, same thing...
You've fried the output driver transistors. Taking a look at some die photos (http://www.flylogic.net/blog/?p=15) is a good idea to familiarise yourself with how very tiny they are; they're the structures next to the bond wires, which are themselves thinner than a hair. They can not source or sink much current at all.
Title: Re: Overloaded output? Arduino mega (Atmel)
Post by: superUnknown on August 14, 2013, 11:26:40 pm
Cool! Thanks all!