Try this ...
You'll need to put the piezo circuit on a CCP pin.
It should sound something like this ... http://support.melabs.com/DT/Piezo.wmaCode:Freq VAR WORD Main: FOR Freq = 3000 TO 4000 STEP 10 HPWM 1, 127, Freq PAUSE 1 NEXT Freq GOTO Main
Try this ...
You'll need to put the piezo circuit on a CCP pin.
It should sound something like this ... http://support.melabs.com/DT/Piezo.wmaCode:Freq VAR WORD Main: FOR Freq = 3000 TO 4000 STEP 10 HPWM 1, 127, Freq PAUSE 1 NEXT Freq GOTO Main
DT
Thanks Darrel, I will try it tomorrow with 16f877A which I have. But I would like to ask if this task can be made possible using a smaller PIC without an HPWM, I would like to use 16F676 if possible as it is very easily available and where I am and if this takes off then it will be economical as well.
In the mean time I am attaching the datasheet of the Chinese uC which is controlling the base of the NPN transistor connected to the piezo & coil. The signal comes out from PIN 2, which to me seems just an I/O pin.
Thanks
Yes, of course it can.
It's only 3-4 khz. You can generate that in software easily.
But see if it drives your piezo first.
I was assumming your piezo has a resonant frequency of ~3.5khz.
Last edited by Darrel Taylor; - 8th August 2012 at 16:07.
DT
THANKS Darrel, it worked like a charm with HPWM. Any pointers as to how to do without it.
I tried FREQOUTbut the results were not the same, not even near enough, the pulsing sound is not that prominentCode:FOR Freq = 3000 TO 4000 STEP 10 FREQOUT PortC.2,1, Freq NEXT Freq
FREQOUT makes sine waves and must be filtered, which is not what you need.
Try this ...
Code:PiezoPIN VAR PORTC.2 TMR0IF VAR INTCON.2 Width VAR BYTE OPTION_REG = %11010011 ; TMR0 1:16 Alarm: FOR Width = 161 TO 120 STEP -1 WHILE !TMR0IF TOGGLE PiezoPIN PAUSEUS Width TOGGLE PiezoPIN PAUSEUS Width WEND TMR0IF = 0 NEXT Width GOTO Alarm
DT
Just out of curiosity, can this be achieved without using a microcontroller?
Bookmarks