Closed fcwpinguino closed 9 years ago
Hi Fred, The tone() function works but the CPU clock of your PIC is running to fast to be able to generate a 650Hz signal. Solutions : 1/ change your CPU frequency : System.setCpuFrequency(1000000); to run at 1MHz for ex. 2/ change the frequency to a higher octave : tone(11, 2637, 1000); 3/ use the Sound() function : Sound(pin, note, duration), for ex. Sound(11, E, 1000); 4/ make your own Tone function, maybe like that (not tested) :
void myTone(u8 pin, u16 freq, u16 duration) { u16 f = 1000000/freq; u32 start=millis();
while ( (f--) || (millis()-start<duration) )
{
digitalWrite(pin,1);
digitalWrite(pin,0);
}
}
Regis, I will try this but I do not understand as this was working with out any issues. Thank you
Fred Warden
On Feb 9, 2015, at 6:33 AM, regis notifications@github.com wrote:
Hi Fred, The tone() function works but the CPU clock of your PIC is running to fast to be able to generate a 650Hz signal. Solutions : 1/ change your CPU frequency : System.setCpuFrequency(1000000); to run at 1MHz for ex. 2/ change the frequency to a higher octave : tone(11, 2637, 1000); 3/ use the Sound() function : Sound(pin, note, duration), for ex. Sound(11, E, 1000); 4/ make your own Tone function, maybe like that (not tested) :
void myTone(u8 pin, u16 freq, u16 duration) { u16 f = 1000000/freq; u32 start=millis();
while ( (f--) || (millis()-start<duration) ) { digitalWrite(pin,1); digitalWrite(pin,0); } }
— Reply to this email directly or view it on GitHub.
regis, i tried what you stated above and sound will not work . i tried sound on my windows computer which is running the new IDE 11 and it works fine, tone still did not work but i did not change my cpu speed. it seems after the update on 2/4/2015 is whe nthe issue began. thank you fred
REGIS, my piezo makes a clicking sound but if i put my ear next to it i can hear the tone very low. sound does not work this produces to few parameter when compiling Sound(11, E, 1000);
Hi Fred, Sound or tone use PWM so you need to connect your piezzo to one of the PWM pin. Pinguino x5(k)50 only have 2 CCP pins : 11 (CCP1) and 12 (CCP2) Pinguino 47J53 have 5 CCP pins : 4 for CCP4, 5 for CCP5, 6 for CCP6, 7 for CCP7 and 17 for CCP8. PIC18F47J53 don't have CCP1 to 3, don't ask me why ... As far as I know your board is a Pinguino 47J53 so replace Sound(11, E, 1000) by Sound(4, E, 1000); or Sound(CCP4, E, 1000); and it should work. You can find the 47J53 pin table here : http://wiki.pinguino.cc/index.php/PIC18F47J53_Pinguino#Pin_Table Regards,
regis, i have my 4550 v4.14 connected to pwm 11 using IDE 11 update 2-4-2015 tone will not work tone(11,650,500); or Sound(11,E,1000) , or Sound(CCP1,650,500).
Regis I found something interesting I tried this Sound(11,E,500,10); and this worked on my 4550 using x.4 on my windows 7 I will try later on Linux using IDE 11 recent update
regis, had a chance and tried the Sound(11,E,500,10); with 4550, linux ide 11 recent update and all i get is a clicking sound.
regis, had a chance and tried the Sound(11,E,500,10); with 4550, linux ide 11 recent update and all i get is a clicking sound.
regis, i changed this in Sound.c PWM_setPercentDutyCycle(pin, 50);//change from 100 now this pde works void setup() {
Sound(11,E,200);
}
void loop() {
Sound(11,D,200); delay(100); Sound(11,B,450); delay(100);
} but tone does not work. fred
I've just tried :
void setup() { }
void loop() { Sound(CCP1, D, 200); delay(100); Sound(CCP1, B, 450); delay(100); }
with the very last v11 packages (last update today) and it works both for 47j53 and 45k50, with a piezo and also with pre-amplified little PC loudspeaker. So it should work for a 4550.
For a 4550 pins are :
#define CCP2 11
For a 45K50 pins are :
#define CCP2 17 // RC1
Did you tried to connect your piezo directly on 5V ? Do you have sound ?
Can you try both CCP1 and CCP2 pins ? Still no sound ?
BTW, the last parameter of Sound was the volume and I temporarily removed it. Don't know if it was a good idea. Anyway when you changed PWM_setPercentDutyCycle(pin, 50); to PWM_setPercentDutyCycle(pin, 100); you actually gave a bit more volume to your piezo.
Regis I will when I get home. Thank you
Fred warden
On Feb 12, 2015, at 3:45 PM, regis notifications@github.com wrote:
I've just tried :
void setup() { }
void loop() { Sound(CCP1, D, 200); delay(100); Sound(CCP1, B, 450); delay(100); }
with the very last v11 packages (last update today) and it works both for 47j53 and 45k50, with a piezo and also with pre-amplified little PC loudspeaker. So it should work for a 4550.
For a 4550 pins are :
define CCP1 12
define CCP2 11
For a 45K50 pins are :
define CCP1 18 // RC2
define CCP2 17 // RC1
Did you tried to connect your piezo directly on 5V ? Do you have sound ?
Can you try both CCP1 and CCP2 pins ? Still no sound ?
BTW, the last parameter of Sound was the volume and I temporarily removed it. Don't know if it was a good idea. Anyway when you changed PWM_setPercentDutyCycle(pin, 50); to PWM_setPercentDutyCycle(pin, 100); you actually gave a bit more volume to your piezo.
— Reply to this email directly or view it on GitHub.
Regis, this did not work Sound(CCP1, D, 200); delay(100); Sound(CCP1, B, 450); delay(100);
but this one did
Sound(11, D, 200); delay(100); Sound(11, B, 450); delay(100);
with cycle at 50 not 100. 100 made my piezo click.
regis does Tone work or do we just use Sound now? thank you fred
Regis i now have used this Sound(11, D, 200); delay(100); Sound(11, B, 450); delay(100); pde with my 47j53 my findings. i still need to have the cycle set at 50 in sound.c in order for this to work.
Sound(CCP4, D, 200); delay(100); Sound(CCP4, B, 450); delay(100);
The Datasheet says if the PWM duty cycle = 0% or 100%, the CCPx pin will not be set. duty cycle = 50% is also not so good because it gives a square signal when we'd like to get a nice sine wave. If I have time I will try to make some nice sound this week-end. Sound and Tone work. Sound just call the tone function. tone is the command used by Arduino. With tone you can use the frequency you want and with Sound you only can use pre-defined frequencies. So with Sound you're sure to get some sound, but not with tone. My idea is to use the PWM whenever it's possible and something else when it's not possible. By the way, I found a bug in the oscillator library that made System.setCpuFrequency() not working for Pinguino x550. I've published the new fixed package.
REGIS, bad news i have tried the update on my 47j53 and 4550 and still tone does not work at all. cycle seems to still be an issue in sound.c
regis i now have set cycle to 50 i can get only one tone to work on the 47j53 and on the 4550 i can not get more than one tone to work in a pde.in this PDE sound works (good) but only one of the tones work . void setup() {
Sound(4,E,200);
}
void loop() {
tone(4,70,50); delay(100); tone(4,80,100); delay(100);
}
Regis i have been looking at sound.c with PWM_setPercentDutyCycle(pin, 10); set at 10 play function and Sound works great but tone tone(11, 200, 100); does not work could the issue be in pwm.c?
Hi Fred, I'm re-writing the sound library from scratch with a 44.1 kHz PWM sampling frequency to cover most of the audible frequency spectrum. It means you should be able to play sound with a frequency between 20 Hz and 20 kHz. I also plan to add a wav decoder so that we can play audio file (ripped from a CD), included voice messages. I'm now making some tests with my oscilloscope. I hope it will be ready before the end of the week-end.
Thank you regis but it is just weird why tone will not work Thank you for your efforts
Fred warden
On Feb 14, 2015, at 11:52 AM, regis notifications@github.com wrote:
Hi Fred, I'm re-writing the sound library from scratch with a 44.1 kHz PWM sampling frequency to cover most of the audible frequency spectrum. It means you should be able to play sound with a frequency between 20 Hz and 20 kHz. I also plan to add a wav decoder so that we can play audio file (ripped from a CD), included voice messages. I'm now making some tests with my oscilloscope. I hope it will be ready before the end of the week-end.
— Reply to this email directly or view it on GitHub.
regis, i tried this with the cycle set at 50 in sound.c with this pde at tone worked. i could not go below 3000 or above 10000. i don't know if this helps. void setup() { tone(11, 8500, 1000); }
void loop() {
tone(11, 3000, 100); delay(100); tone(11,4000, 100); delay(100); tone(11,5000, 100); delay(100); tone(11, 6000, 100); delay(100); tone(11,7000, 100); delay(100); tone(11,8000, 100); delay(100); tone(11,9000, 100); delay(100); tone(11,10000, 100); delay(100); }
This is normal. The PWM frequency is based on the Timer2 frequency, which is depending on the peripheral frequency (Fpb). Fpb = Fosc/4 so 12MHz if your Pinguino runs at 48MHz. Datasheet says : PWM Period = [PR2 + 1] * 4 * TOSC * p2 (p2 = Timer2 prescaler). so Pf = PWM Frequency = Fpb / ( [PR2 + 1] * p2 ) Pf is min when PR2 and p2 are max (255 and 16) : Pf min = 12 MHz / 4096 = 2929 Hz Pf is max when PR2 and p2 are min (0 and 1) : Pf max = 12 MHz / 1 = 12 MHz but you also have to deal with PWM resolution : r = log (4* (PR2+1)) / log(2) When PR2 = 255, resolution = 10 bits (1024 values) When PR2 = 0, resolution = 2 bits (4 values)
Regis, before i could use tone(11,400,100); and this would work or am i crazy this never worked? thank you Fred
According the way I programmed the sound library it is impossible until you down-clock your PIC.
how do i do that? my pic 18f4550 has a 20 mhz crystal.
You can change your CPU frequency on-the-fly with : System.getCpuFrequency(the-frequency-you-want); So if you want your Pinguino to run at 1MHz instead of 48MHz just do : System.getCpuFrequency(1000000);
I published a new version of the libraries with the new Audio (I renamed it) library. Go to examples/Analog/Audio and load the tone.pde example to see how it works. You will see e new instruction : Audio.init(CDQUALITY); You can change CDQUALITY to TAPEQUALITY, RADIOQUALITY or TELQUALITY. CDQUALITY is the best. Now you can play sound from 20Hz to 20kHz.
Thank you I will try tonight
Fred warden
On Feb 17, 2015, at 7:57 AM, regis notifications@github.com wrote:
I published a new version of the libraries with the new Audio (I renamed it) library. Go to examples/Analog/Audio and load the tone.pde example to see how it works. You will see e new instruction : Audio.init(CDQUALITY); You can change CDQUALITY to TAPEQUALITY, RADIOQUALITY or TELQUALITY. CDQUALITY is the best. Now you can play sound from 20Hz to 20kHz.
— Reply to this email directly or view it on GitHub.
Regis, I have tried the new library with the 4550 and 47j53 no luck i get no sound. everything compiles and loads. The piezo makes clicking sounds the userled flashes.
fred
Oops ... I forgot the new main.c file. Now it should work.
regis, still not working. The piezo still makes clicking sounds and the userled flashes.
Here it is ...
2015-02-18 12:00 GMT+01:00 Fred Warden notifications@github.com:
regis, main.c is still not showing up?
— Reply to this email directly or view it on GitHub https://github.com/PinguinoIDE/pinguino-libraries/issues/4#issuecomment-74846668 .
regis, no good no sound.
regis, i noticed that in my p8 folder core i still have the sound.c even after updating?even if i delete the sound.c file and do an update it appears. fred
i wired my piezo as per the supplied drawing with the pde.
regis I have been using the tone function in my pde and it has been work since the recent updates . I get the same result in windows and Linux I have tried different pins same result. Tone(11,650,1000);
Thank you Fred