Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Microcontroller Music - Harmonic Distortion.

Status
Not open for further replies.

lord loh.

Member
I was recently trying to get an AVR play music. I successfully managed to get the AVR playing 3 octaves from about 130Hz to about 2KHz. However, the output from the AVR is a square wave, which results in a vary harsh sound from the speaker.

I was using the LM380 Power amplifier.

There was a strange thing that I noticed. The power amplifier gave sound output when the input voltage was below 20mV p-p. However, there was no sound output when the input voltage was increased. Then Again there was some sound heard when the input was directly fed from the AVR (0-5v) to the LM380.

How do I get a lower distortion sound from the AVR?

Please Help... :-(
 
lord loh. said:
How do I get a lower distortion sound from the AVR?

You don't, you add a lowpass filter between it's output and your power amplifier, this helps to reduce the harmonics - even better if you have one that can be adjusted for the particular note you're playing in real time.

You might consider using a digital to analogue converter?, and outputing sinewaves instead of square, but you still need a low pass filter anyway.
 
If you're just using squarewaves then you don't need an audio amplifier, a simple complementary pair of MOSFETs acting as a push pull buffer will be far more efficient, add a simple low-pass filter and you have a little class-D amplifier.
 
If you don't like distortion then don't play square-waves.
A square-wave with the same p-p amplitude as a sine-wave has twice the power of the sine-wave. So the harmonics of a square-wave have the same amount of power as the fundamental sine-wave of the square-wave.
 
Use hardware PWM for audio on an AVR. The higher the PWM frequency the better. Using a tiny15 you can use it's high speed PWM to generate a 100khz square wave at 8 bits resolution for the duty cycle, passing the output through a lowpass filter with a cutoff frequency of about 20khz will give you moderatly acceptable output. Using a scheme like this you'll likley be able to get a 'clean' signal at 1/8 to 1/16th of the driving frequency (100khz) So for a 100khz PWM signal you're not going to get a clean output much above about 5khz.. That's at the upper limits of what an AVR can do.
 
The LM380 seems to have a fixed voltage gain of 50. Chances are that when you drive the chip directly it's going into some weird nonlinear/saturation. If you were to scope out the waveforms, they probably wouldn't make too much sense.

A small D-A converter is probably the best bet. That with DDS (google it) will probably give you some reasonable results.
 
Years ago I heard 8-bit long distance telephone calls. The quality with voice was horrible. I don't want to think about music like that.
 
audioguru said:
Years ago I heard 8-bit long distance telephone calls. The quality with voice was horrible. I don't want to think about music like that.

8 bit audio is fine, if the 8 bit phone was poor it's the system used, and NOT the number of bits. The Commodore Amiga used 8 bit sampled sound, and the audio quality was fine, even through a HiFi system - certainly compared with PC's of the day which didn't have sound at all!.
 
8 bits isn't good enough for really hi fidelity music, but only because the dynamic range isn't very good. It's fine for simple waveforms. ulaw encoding can increase the dynamic range but it's not as good as increasing the number of bits. The music you're going to get out of an AVR is never going to be much better than clicks and beeps. It's possible to do simple polyphonic music but the quality will never really be very good.
 
Dr.EM said:
It's easy to hear what 8-bit is like just by convering an audio file on your PC to 8bit 44.1khz stereo wav. I expect with a lot of modern, extremely compressed music, it wouldn't even be that evident!

No it wouldn't, the Amiga's 8 bit audio was quite satisfactory, and probably better than most car stereos?.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top