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 generation using a pic - help is greatly needed.....

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







audio generation using a pic - help is greatly needed.....
PostPosted: Wed Feb 23, 2005 10:58 am     Reply with quote

I'm looking at using a PIC to either produce sounds itself (range approx 60Hz to 1100Hz) or to get a chip with these sounds already in to play. The PIC has to be able to read from a 16 button keypad and also be able to play up to 8 notes in a sequence after input. Anybody got any ideas - i know the PIC should be able to produce the sound but am not sure how to go about it. (There are a total of 60 sounds that need to be able to be picked from, each between 1 - 2 seconds long - in terms of sampling these sounds there's no way a PIC would be able to store that much data (I think) so I would need to interface with an external memory chip - can thsi be done (I have to use the PIC 16 family as its the only chip-type I have a programmer for).
Am really stuck - anybody got any ideas?

Thanks
Eric Minbiole



Joined: 10 Jun 2004
Posts: 16
Location: USA

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

PostPosted: Wed Feb 23, 2005 11:23 am     Reply with quote

You can definitely play simple notes with a PIC. One of the simplest ways is to connect a Piezo speaker to the PWM output of the PIC. You can vary the PWM frequency to get a good range of notes. (Though 60Hz is a fairly low frequency, and may require a largish speaker.) You can use a traditional speaker as well, but you'll need an impedance matching transformer. (1kOhm input, 8 ohm output will work, avail from Radio Shack.)

I recently did a project similar to this: My wife and I made music boxes as our [spam] favors. It used a PIC16F628 connected directly to a piezo speaker. It stored the song (notes) in internal code, and sounded pretty good.

If you want sampled sounds, it is more challenging. I read a very cool article by Roman Black a while ago. He created a simple 1 bit DAC using a resistor and a capacitor, and was able to reproduce some simple sampled audio. I haven't tried it, but it looks very clever / interesting. Here's the link: http://centauri.ezy.net.au/~fastvid/picsound.htm .

Good luck!
DragonPIC



Joined: 11 Nov 2003
Posts: 118

View user's profile Send private message

tone.c
PostPosted: Thu Feb 24, 2005 10:45 am     Reply with quote

Have you checked tone.c that comes with the CCS compiler.
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

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

PostPosted: Thu Feb 24, 2005 12:44 pm     Reply with quote

http://www.ccsinfo.com/forum/viewtopic.php?t=22010
pinstrum
Guest







PostPosted: Fri Feb 25, 2005 6:12 am     Reply with quote

Eric - Thanks for the advice. Am looking into using the PWN output of the PIC to generate the frequency, am not completely sure but i think i remember reading somewhere that there's a limit on the lowest frequency that can be generated which is around 244Hz

(using max PR2 available as 255 and max pre-scale as 16 you get
pwn freq = ( 1E06 / (256 * 16)) = 244Hz and that's using a 4MHz clock (4MHz allows 4/4 = 1MHz rate at which can execute instructions i think?)
Any ideas on how to get round this little problem - or if i've messed up somewhere and it's not actually an issue.

Also, have already had a look at Roman Black's algorithm but it's quite memory heavy. Am talking 60 notes of around 1.5secs each so that's about 90s of data. using the routine mentioned by christian donner, you can get 17secs on 32k I2C serial eeprom so i would need around 192k eeprom to do this. Also, I not really familiar with how the eeprom interface works - any idea if it would be possible to store a lot of different sample data under seperate memory addresses and call specific data up using the PIC?

DragonPIC - can't check tone.c as don't have the file but thanks anyway

Mark - had a look at your code, nice work there. Is it okay to attempt modifying it for my project? The sound output aspects are there, i would basically have to interface a 16-key keypad with the PIC to get it to play notes rather than tunes on command.
Plan is - 12 keys represent 12 notes (C -> B), 1 key for play, 1 key for reset, one key to switch the octave of the note just input and 1 key spare (was originally going to be attempted to be used to make the notes play at once but that might be later work after i get the main unit up and running. User can input up to 8 notes in requested octaves and then play back, so would need to store the sequence of notes wanted in memory and recall them at will - any thoughts?

Thanks all for your help so far, the responses i've made are not user specific, it's just so you know what bit of my questions are in reply to who.
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

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

PostPosted: Fri Feb 25, 2005 7:02 am     Reply with quote

Modify it as you wish. I make no claims at all. Sounds like it would be a nice fit for what you want.
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