Skip to content

Instantly share code, notes, and snippets.

@qsuscs
Last active December 10, 2015 22:39
Show Gist options
  • Save qsuscs/4504149 to your computer and use it in GitHub Desktop.
Save qsuscs/4504149 to your computer and use it in GitHub Desktop.
Test your ears.
CON
_clkmode = xtal1 + pll16x ' 16x the input freq
_xinfreq = 5_000_000 ' 5 MHz crystal
speaker = 11 ' where the speaker is connected
OBJ
pst : "Parallax Serial Terminal" ' this is for debugging
VAR
WORD freq ' actual frequency
WORD d ' difference between the frequencies
LONG fx ' frequency value for the frqa register
PUB main
dira[speaker]~~ ' speaker is an output
d := 10 ' initial value
pst.start(115_200) ' initialize serial connection with 115_200 baud
ctra[30..26] := %00100 ' use as NCO
ctra[5..0] := speaker ' output for the NCO
repeat freq from 10 to 20_000 step d ' frequencies go from 10 Hz to 20 kHz, delta will be adjusted on the fly
pst.dec(freq) ' print the frequency on the terminal
pst.str(String(pst#NL)) ' ...and a newline
case freq ' adjusting the freq delta
10..99 : d := 10
100..299 : d := 20
300..499 : d := 50
500..999 : d := 100
1_000..4_999 : d := 500
5_000..20_000 : d := 1000
fx := ($8000_0000 / (clkfreq / freq)) << 1 ' converting freq for the NCO
frqa := fx ' set the freq
waitcnt(clkfreq+cnt) ' wait a second
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment