PDA

View Full Version : FREQOUT 4mhz



Michael
- 15th November 2017, 00:44
I want to drive a piezo buzzer which I haven't done before. Read where FREQOUT may have issues with a 4mhz oscillator?

Goal is to drive one of those button piezos at 6500 hz. Just thought I'd ask before attempting whether there will be problems.

Will I need a driver circuit as well or can the pic drive a piezo directly ? -- THANKS

Scampy
- 15th November 2017, 14:27
If its one of those small 3v - 15v type piezo buzzers then this can be driven directly from the PIC

http://hades.mech.northwestern.edu/images/d/d9/Piezo_Speaker_Circuit.JPG

Some further examples and reading http://www.picbasic.co.uk/forum/showthread.php?t=3076

Can't really help with the frequency part, the buzzer I use as an alarm just runs at whatever its internal frequency is when DC voltage is applied

Michael
- 15th November 2017, 14:48
It's not a buzzer, it's just a transducer. And like I say, FREQOUT (according to manual) is limited at 4mhz and would like to know more.

Michael
- 15th November 2017, 14:50
Ok -- good link -- I'll try the PWM command instead.

mpgmike
- 15th November 2017, 16:57
I seem to recall the FREQOUT command is only accurate at 4 MHz. If you're clocking at 8 MHz, divide the value by 2 (and so forth). The command itself should work at any clock speed. Just take into account any divisor needed to achieve your 6500 Hz.

If you have Mister E PIC Multi-Calc, you can use the Timer Helper to create any frequency the processor is capable of, and at any chosen Fosc.

HenrikOlsson
- 15th November 2017, 19:46
From the manual:

FREQOUT works best with a 20MHz or 40MHz oscillator. It can also work with a
10MHz or 8MHz oscillator and even at 4MHz, although it will start to get very hard
to filter and be of fairly low amplitude. Any other frequency will cause FREQOUT to
generate a frequency that is a ratio of the actual oscillator used and 20MHz.

For simple beep type of tone from a piezo buzzer just use PWM, HPWM or "manually" run the (E)CCP module.

/Henrik.

Art
- 16th November 2017, 11:41
FREQOUT can do dual frequency (polyphonic), and that is a mess at 4MHz.
DTMF works the same way, but I’ve never had a telephony system understand it for a pic clocked less than 20MHz, no matter what I do.
For a single frequency it might be ok, but as said, PWM is non-blocking, can make the sound forever, and a much better choice for a single audio freq.

Michael
- 16th November 2017, 14:13
I may have to use PWM as it appears FREQOUT won't function with my antique 16C72. (I have a boatload of them).

The 16C72 is 8bit.

We'll see -- thanks -- will get back to you no doubt.

Also using a 2N4401 to drive the piezo, would imagine I need it ?

Art
- 16th November 2017, 15:32
I wouldn’t say “need”.
You’d get best results using any of the shrouded ones that will at least be loud at their resonant freq. That would be money better spent than on the transistor I think.
The pic could probably drive a small speaker through a series capacitor. I used a MAX232 as a buffer for a speaker, and small output transformer (MAX232 drives the audio positive and negative).

Michael
- 17th November 2017, 14:00
Not having any luck. I know the piezo is good -- I've tested it.

I'm probably missing something in set up or some register that needs to be modified?

I just put in --
PWM portc.4,50,6500

Piezo is 6500 hz. Hearing nothing.

PIC is 16C72, 8 bit antique.

Michael
- 17th November 2017, 14:07
Don't know if PWM is my only option. FREQOUT can't be used and SOUND is a sine wave right?

Michael
- 17th November 2017, 14:26
and that should be 127, not 50 for duty cycle -- typo

Michael
- 17th November 2017, 14:39
I think it may be this crap piezo I'm using --

https://www.ebay.com/itm/US-Stock-50x-20mm-Thickness-0-33mm-Piezo-Disc-for-Buzzer-Pressure-Sensor-Speaker/371923382451?ssPageName=STRK%3AMEBIDX%3AIT&_trksid=p2057872.m2749.l2649

hard to work with. maybe someone can suggest an inexpensive one that they know works well. need low cost as this may be a product idea. 6500 hz is pretty high as well.

richard
- 18th November 2017, 21:44
Don't know if PWM is my only option. FREQOUT can't be used and SOUND is a sine wave right?
wrong
from manual


SOUND outputs TTL-level square waves. Thanks to the excellent I/O characteristics of the PIC MCU, a speaker can be driven through a capacitor. The value of the capacitor should be determined based on the frequencies of interest and the speaker load. Piezo speakers can be driven directly





I just put in --
PWM portc.4,127,6500

Piezo is 6500 hz. Hearing nothing.


pwm does not do what you have expected

@4mhz clock pwm output is 6500 cycles @200 hz


a 6500hz resonator can be driven at frequencies other than its resonant frequency

your chip has a pwm/ccp module , you could use HPWM

to get maximum noise you can drive the resonator bipolar mode between to output pins antiphased

I notice those resonators you linked have no connecter leads , how good is your soldering ?
they don't work if they have been cooked

Michael
- 20th November 2017, 13:45
Ok Richard thanks. I'll try SOUND and stick with it and yes, those transducers are something I've never dealt with -- they're a pain. Going to try something else.

Michael
- 26th November 2017, 16:39
Do you think these will work on a PIC output with the SOUND command at 2300 hz ? At least they're 5V.

https://www.ebay.com/itm/Gfortune-15PCS-Active-Piezo-Buzzer-Alarm-12mm-Dia-DC-5V-2-Terminals-Electronic/152728575468?epid=12003122131&hash=item238f551dec:g:XSUAAOSwErFZ0-ze


Having problems getting piezo diaphragms and driver circuits to be very loud. barely hear them in fact. --Thank you

mark_s
- 26th November 2017, 18:07
Those are self resonating. They will buzz at 2300hz when 5 volts is applied. Look for "transducer".

Something like this
https://www.ebay.com/itm/AT-12-Piezo-Transducer-1VAC-to-30VAC-90dBA-10-LOT/381293240258?hash=item58c6d91fc2:g:~~gAAOSwZd1Vewu j

Michael
- 27th November 2017, 13:26
I realized that after posting -- thanks. Will try that part you suggested. Can't believe something so simple has been such a headache.

Thanks.

mpgmike
- 28th November 2017, 02:05
Just to try a piezo to see if it works, just use the HPWM 1,127,2000 command and connect your piezo to the PWM output. I found some processors the SOUND command doesn't work so well for. I would be chasing my tail trying what you are with what I was working on.

Once you know the piezo is good for a PWM output, then work on the SOUND software. My opinion, and I reserve the right to be wrong.

mark_s
- 28th November 2017, 22:58
I realized that after posting -- thanks. Will try that part you suggested. Can't believe something so simple has been such a headache.

Thanks.

It also helps to place a 1K resistor in parallel with the transducer when driving with a logic signal. Like the others said use HPWM. Sound and Freqout are blocking commands.

Art
- 2nd December 2017, 11:49
You could eliminate any doubt with the pic by oscillating port b yourself,
and connecting an LED to any of the other port b pins, and changing the delay value.




buffer var byte = 0
TRISB = 0

cycle:

if buffer == $00 then
buffer = $FF
else
buffer = $00
endif
pauseus 1
PORTB = buffer

goto cycle