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

music with 12F683

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



Joined: 04 May 2008
Posts: 260

View user's profile Send private message

music with 12F683
PostPosted: Thu Dec 04, 2008 2:52 pm     Reply with quote

Hi

I try make a little sounds with this PIC but result is not best Crying or Very sad

This PIC stay running at 4Mhz and I connect it to a little speaker phone, and if I make this:
Quote:

while(TRUE)
{
output_high(PIN_A0);
delay_ms(500);
output_low(PIN_A0);
delay_ms(500);
}


I listen bips's...

Now I have generated some frequencies, but I can't make this correct Confused

For example:

C4 264 Hz
C4# 278 Hz
D4 297 Hz
D4# 313 Hz
E4 330 Hz
F4 352 Hz
F4# 371 Hz
G4 396 Hz
G4# 417 Hz
A4 440 Hz
A4# 470 Hz
B4 495 Hz


Now I try converting this in square wave:

264 Hz=>> T=0,003787879 sec (period) after I divide it's value by 2 and have up wave in 0,001893939 sec and down wave in 0,001893939

In milliseconds I have delay_ms(1.89393939); correct?

So if I make this code:
Quote:

while(TRUE)
{
output_high(PIN_A0);
delay_ms(1.89393939);
output_low(PIN_A0);
delay_ms(1.89393939);
}


I should listen +- sound C4... but I don't hear nothing.

Someone can help me generate these sounds?

kind regards
Ttelmah
Guest







PostPosted: Thu Dec 04, 2008 4:04 pm     Reply with quote

Delays _only_ accept integer values.
Look at delay_us, and recalculate for this.
Remember though that the loop, and I/O itself takes _time_. You will need to adjust your values to allow for this.

Best Wishes
filjoa



Joined: 04 May 2008
Posts: 260

View user's profile Send private message

PostPosted: Thu Dec 04, 2008 5:12 pm     Reply with quote

Hi

yes problem is because integer Laughing Laughing

now I have:

Quote:

while(TRUE)
{
i=0;
do {
output_high(PIN_A0);
delay_us(1893); //C4 = +-264Hz
output_low(PIN_A0);
delay_us(1893);
i++;
}while (i<=600);


i=0;
do {
output_high(PIN_A0);
delay_us(1683); //D4 = +-297Hz
output_low(PIN_A0);
delay_us(1683);
i++;
}while (i<=600);
}


now I know when I put "while(i<=600)" I have sound during +-1second.

someone know an easy way for I can control sound time ring?

kind regards
filjoa



Joined: 04 May 2008
Posts: 260

View user's profile Send private message

PostPosted: Fri Dec 05, 2008 8:15 pm     Reply with quote

Hi

now I have make one music but I need make all notes like this?

Quote:

void C4() //Dó
{
output_high(PIN_A0);
delay_us(1894);
output_low(PIN_A0);
delay_us(1894);
}

void C8() //Dó
{
output_high(PIN_A0);
delay_us(947);
output_low(PIN_A0);
delay_us(947);
}


if I have delays define like this: "const long C_NOTE[4] ={ 262, 523, 1047, 2093};"

How I can call my music note in main function for make some like that?

Quote:


while(TRUE)
{
i=0;
do {
D4();
i++;
}while (i<=150);

i=0;
do {
D8();
i++;
}while (i<=350);
}


regards
Guest








PostPosted: Sat Dec 06, 2008 5:49 pm     Reply with quote

TONES.c

c:\program files\picc\examples\ex_tones.c

c:\program files\picc\drivers\tones.c
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