piclist 1997\02\27\163140a >
Thread: How to create a tone output?
picon face BY : David W. Duley email (remove spam text)

In a message dated 97-02-27 14:01:08 EST, you write:

I have a simple project I'm working on where I need to have my pic provide
a tone or beep for 1/2 to 1 sec or so.  This is for audibile notification
of a switch closing.  I need to use plain old headphones like those used
with Sony walkman type radios.  I know haow to do everything except have a
PIC generate a "beep".

Can one of you EE guru's help me with what I hope is a simple solution?

Thanks very much in advance.

Beeping is very easy.
Connect a piezo speaker directly between an output pin (one of the port pins)
and ground, or you can use a cheap PM speaker like the ones found in an IMB
PC.  You might want to put a series resistor of about 270 ohm or so to limit
the current from the pin.  You also might want to put a capacitor in series
with a speaker so the speaker won't heat up if you leave the output pin on.

Now for the beep

The basics for tone generation is simple

        Goto Beep

This is Psudo Code of course.
This will generate a tone with a 50% duty cycle of 'DELAY' period.

You will probably want to add a 16 bit counter to limit the length of the

This is a snipit of code I used on a project.  This code uses the RTC to time
the beep duration
       bcf     intcon,7        ;disable RTC interupt
       movlw   .2
       movwf   Time
       clrf    rtc
       bcf     StatFlag,0      ;clear the timeout flag
       bsf     intcon,7        ;enable RTC interupt
       bsf     BuzzPort,Buzzer  ;Turn on speaker port
       movlw   .65
       movwf   wait1
       call    shortdelay
       bcf     BuzzPort,Buzzer  ;Turn off speaker port
       movlw   .65
       movwf   wait1
       call    shortdelay
       btfss   StatFlag,0      ;see if rtc has timed out
       goto    BuzzLoop

shortdelay     ;8 bit delay routine
       movwf   wait1
       decfsz  wait1,f
       goto    shortloop
       retlw   0

You could replace the bsf and bcf (turning on and off the port) with an
exclusive OR.  Anything excusive ored with 1 will generate a push on push off
type response.  eg. 0 xor 1 = 1, 1 xor 1 = 0.  You eliminale a few lines of
code this way.

Hope this helps
Dave Duley
V.P. DreiTek Inc.

See also: www.piclist.com/techref/ios.htm?key=output
Reply You must be a member of the piclist mailing list (not only a www.piclist.com member) to post to the piclist. This form requires JavaScript and a browser/email client that can handle form mailto: posts.
Subject (change) How to create a tone output?

month overview.

new search...