View previous topic :: View next topic |
Author |
Message |
filjoa
Joined: 04 May 2008 Posts: 260
|
music with 12F683 |
Posted: Thu Dec 04, 2008 2:52 pm |
|
|
Hi
I try make a little sounds with this PIC but result is not best
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
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
|
|
Posted: Thu Dec 04, 2008 4:04 pm |
|
|
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
|
|
Posted: Thu Dec 04, 2008 5:12 pm |
|
|
Hi
yes problem is because integer
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
|
|
Posted: Fri Dec 05, 2008 8:15 pm |
|
|
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
|
|
Posted: Sat Dec 06, 2008 5:49 pm |
|
|
TONES.c
c:\program files\picc\examples\ex_tones.c
c:\program files\picc\drivers\tones.c |
|
|
|