View previous topic :: View next topic |
Author |
Message |
dbotkin
Joined: 08 Sep 2003 Posts: 197 Location: Omaha NE USA
|
Audio tones using PWM, at variable audio freqs? |
Posted: Fri Feb 03, 2006 9:11 am |
|
|
I have an application that generates a square wave audio tone at some frequency (say 500 to 1000 Hz or so) selected by the user. It works, but it sounds pretty ragged. I'd prefer to use the PWM to create a nicer sounding tone with a sine wave or at least something much less harsh than a square wave.
I've used the PWM to generate an audio frequency square wave, that's easy. Yes, I could just LPF the square wave using a few passive components, but it's bugging me that I can't figure out how to do this. It's my woeful lack of mathematical education, I'm sure. Anyway -- I have so far not been able to find any examples of using PWM to generate an audio sine wave with a variable audio frequency. Pointers? Suggestions? Thanks in advance. |
|
|
MikeValencia
Joined: 04 Aug 2004 Posts: 238 Location: Chicago
|
|
Posted: Fri Feb 03, 2006 9:21 am |
|
|
You can just put a digital to analog converter IC chip and hook the input of it to a PIC output.
I feel you on the lack of math know-how. I don't remember anything from school past basic arithmetic, and heck, even when i was in school, i didn't really know what it all meant. I just followed it like a cookbook recipe.
It seems that app notes are all you would really need to get something to work. |
|
|
dbotkin
Joined: 08 Sep 2003 Posts: 197 Location: Omaha NE USA
|
|
Posted: Fri Feb 03, 2006 9:30 am |
|
|
MikeValencia wrote: | You can just put a digital to analog converter IC chip and hook the input of it to a PIC output. |
I could, yes, but I'm trying to see if I can do this without adding hardware. I'm currently using the CCP output pin with a bit-banging routine to generate the audio. Adding a DAC would more than double the cost of the product, and even adding some passive LP filtering would require a PCB redesign that I'd rather avoid. It's not a super-critical need, but it would be really nice to have, and like I said -- it's bugging me that I haven't been able to figure this out. |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Fri Feb 03, 2006 9:40 am |
|
|
Holtek is a good option if you want to generate good audio tones without PIC overhead.
If you don't want to add some hardware, Mark posted this code, it shows how
to do it using the CCP module.
http://www.ccsinfo.com/forum/viewtopic.php?t=22010
Humberto |
|
|
yerpa
Joined: 19 Feb 2004 Posts: 58 Location: Wisconsin
|
|
Posted: Fri Feb 03, 2006 3:32 pm |
|
|
I haven't run Mark's code, but it looks like it just produces square waves, not sine or complex waveforms, i.e. no amplitude envelope. I have also looked for a PWM method. It should be possible. |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Fri Feb 03, 2006 5:07 pm |
|
|
yerpa wrote:
Code: |
I haven't run Mark's code, but it looks like it just produces square waves, not sine or complex waveforms, i.e. no amplitude envelope.
|
The poster is asking for an easy way to get a sweet sound to improve the "ragged" 500-1000 Hz
square wave tones, I think that it can be achieved using PWM + a LPF, that's why I pointed him to
see Mark code to start with.
Of course there will be a lot of way to do it, it will be nice to see how to do an amplitude envelope using
a PIC taking care that "the collar will not cost more than the dog" as we says in Spanish.
Humberto |
|
|
|