Speaker Single Frequency

Goal: Make a speaker output sound.

Purpose: This will demonstrate simple frequency generation by sending pulses at a constant rate.

Clock frequency: 5,000 Hz

Propeller code type: This propeller code is based on spin language only.

Files to download: (right click)

demo_speaker_single_freq

Pics to Download: (click to enlarge)

Note: Only copy and paste from the link above, or formatting issues will occur!

{{
************************************
*       demo_speaker_single_freq   *
*       2008                       *
************************************

Goal: Make a speaker output sound.

Purpose: This will demonstrate simple frequency generation by
sending pulses at a constant rate.

}}

CON

_clkmode     = xtal1 + pll16x     ' Feedback and PLL multiplier
_xinfreq     = 5_000_000          ' External oscillator = 5 MHz

pinSpeaker   = 0                  ' assign which pin the led is on

PUB FreqGen                       ' Main method

dira[pinSpeaker]~~                ' Set pin to output (~ sets I/O to
input and ~~ sets I/O to output, all pins default to input state)

repeat                            ' Endless loop

!outa[pinSpeaker]                 'toggles output of pin low/high
(if low, then high, or if high, then low)

waitcnt(clkfreq / 4 + cnt)            ' Wait 1/4 second -> 2 Hz
(uses the clock frequency of 5 MHz)

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>