CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Audio tones using PWM, at variable audio freqs?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
dbotkin



Joined: 08 Sep 2003
Posts: 197
Location: Omaha NE USA

View user's profile Send private message Send e-mail Visit poster's website

Audio tones using PWM, at variable audio freqs?
PostPosted: Fri Feb 03, 2006 9:11 am     Reply with quote

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

View user's profile Send private message Send e-mail Yahoo Messenger

PostPosted: Fri Feb 03, 2006 9:21 am     Reply with quote

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

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Fri Feb 03, 2006 9:30 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Feb 03, 2006 9:40 am     Reply with quote

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

View user's profile Send private message Visit poster's website

PostPosted: Fri Feb 03, 2006 3:32 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Feb 03, 2006 5:07 pm     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group