On 08/10/2011 18:25, Peter Johansson wrote: > I am a lifelong on-and-off amateur electronics hacker who has recently > gotten back on with microcontrollers. As such I have started > collecting junked electronics for parts and I have a pile of speakers > -- raw 3" drivers, a bunch of low-end cabinets, and a few older > mid-range cabinets -- I have been wanting to do something with. I > also have a few generic TDAxxxx amps from scrapped TVs I have working > on breadboards. > > Yesterday I got the idea to use these as halloween decorations -- whip > up a simple WAV file player and place them around the yard. The > speakers will be placed in construction-grade trash bags and then > concealed. I have a number of rejuvenated rechargeable battery packs > (NiMH, Li-ion, SLA) for power to avoid mains current and wires. The > WAV file will live on an old 64 MB uSD card in a hacked uSD -> SD > adapter. > > The initial plan was to use a simple R-2R resistor ladder DAC to an > op-amp buffer/pre-amp and then into one of the TDA amps. As I was > breadboarding this, I realized it requires quite a number of > components, and thought things might be a whole lot simpler just > driving the speaker with PWM and a MOSFET. It didn't take much > research before the light bulb came on and I realized, "Oh, so that's > what a Class D amplifier is!" > > So I did a little bit of research on simple uC/PWM-driven, Class D > amplifiers and didn't come up with much. This maks sense given that > an analog/comparator driver makes a whole lot more sense when you are > dealing with an analog input signal. But since I will be storing a > digital signal to begin with, and I am in no way concerned with > fidelity, the uC approach seems to make a lot more sense. > > I'm looking at a simple, single rail, single mosfet design. Nothing > more than uC PWM pin -> gate driver -> MOSFET -> L/C filter -> > speaker. Hardly optimal, but I think this should get the job done. > > What I am unsure about are PWM frequency and inductor selection. 200 > kHz seems an oft-referenced frequency in the analog designs, but it is > easy enough to use much higher frequencies with hardware PWM > generation in the uC. I would also like to try to use some of the > inductors I have been salvaging as well -- most of which are unmarked > -- and I am guessing that I might just want to select a PWM frequency > based upon the inductors I have available. > > I do not have an inductance meter, but I have been thinking about > building one, and this might be the time. Most of the L-meter designs > I have seen are fixed-frequency, fixed-current but what I think what I > really want is an L-meter that can vary frequency and current, sending > the results back to a PC so that I can graph inductance vs. frequency > and determine saturation at various frequencies. This should be not > terribly difficult with Perl/Python and some graphing libraries -- but > has anyone done this yet? > > But in any case, is this actually necessary? Would just hand-tweaking > PWM frequency and capacitor values for optimal sound quality be at all > possible? I figure if I start with a low voltage, current-limited > power supply and a large speaker I'm not likely to fry anything before > I get values into the ballpark. > > Class D really does seem to be the way to go in this application since > quiescent current will be practically zero (in the dead-time between > sounds) in addition to providing good efficiency when actually driving > the speaker. > > Many thanks in advance for any comments/suggestions/URLs I missed! > > -p. I wrote a Wave to PWM audio to play sound on the PC speaker in Modula-2=20 on a 286. Native (DOS only used to load the program and PC speaker=20 really can only be turned on/off). The frequency just needs to be > 2x=20 the max audio frequency. 5bit resolution is really poor but=20 recognisable. 8bit can be reasonable. 10bit PWM resolution is quite=20 good. Unless you are doing HiFi, 16bit is overkill. Higher means less/easier filtering but more FET switching loss. You can=20 just rely on the mechanical filtering of the loudspeaker for a simple=20 application where speaker & supply is close to FET! For better output range and no DC offset you need 4 fets in bridge, but=20 only one or other of the low side FETs needs PWM drive. (or 2 x PNP=20 transistors and two FETs, use 4 PIC pins) About 80KHz is minimum for really good non-HiFi. For HiFi you might want=20 higher PWM frequency. Ensure PWM harmonics are not on an AM station. If=20 in doubt put all in screened box :-) --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .