#Rem
Testing and playing around with sound that could be made
with one of these.
The best way to hook up this is to connect it to the high impedance
connection of a guitar amplifier, the one which you would usually
plug your Strat into. Output impedance is high, and also, the capacitor
will not filter high frequencies if the input impedance of the amplifier
is low. Start with volume all the way down, and turn it up to the best level.
Voltage from this device is higher than the voltage from an electric guitar.
It may be necessary to add a series capacitor to the output, some amplifiers
may not have this, and the DC offset would be a problem if yours is like that.
If so, another 0.1 uF capacitor will work for this purpose.
#endrem
'Variables:
symbol scratch1=b27
symbol counter1=b26
symbol counter2=b25
symbol volcontrol=b24
symbol longcount1=w11
symbol tone1=b21
symbol tone2=b20
symbol wildcard=w9
symbol math1=w8
symbol reedpos=w7
symbol speed=w6
symbol binpointer=b11
symbol dummy1=b10
'Constants:
symbol center=34816 ;was 32768, changed because there was an offset
symbol kick=2780 '2780 These two numbers produce the wave is it is now
symbol gravity=198 '198 They affect amplitude and frequency
'Devices:
symbol led=c.0 ;This goes to a transistor which drives the LED, and also is a sound output.
symbol pulse=c.2 ;This is the PWM, which can also produce sounds, and is also connected.
'Starts here*************
SineMaker:
#rem
This is my effort to produce something close to a sine wave using
the 08M2, which does not have higher math functions like SIN. It
actually worked out surprisingly well, but this microcontroller
probably can't do this fast enough to produce a sine wave as a sound.
It turns out that its highest frequency is just 12 Hz, for a wave that has
64 points in it, and of course, increasing the frequency will reduce
the resolution. I use the "sertxd" to generate a graph of the wave, and
when I have what I want, I save that with the "poke" instruction, and
then play it just by "peeking" it and setting the DAC. This can run much
faster than the generator, up to 90 Hz for waves with 64 points, and almost twice
that for a wave with 32. Fewer points than that, and it's too distorted to
be a good sine wave without a lot of filtering after it's generated.
The 0.1 uF capacitor is a filter which makes the sound more "mellow". I
used a movable jumper to connect it or not to.
If the amplifier is connected while it's sending text, it makes quite a racket,
because both the DAC and the text output are on the same pin on
08M2, and I think that's true of all the Picaxe chips.
To see the chart, use the sertxd instructions and loops by just removing the first character,
which is a semicolon or an apostrophe, and it is processed as an instruction instead of a
comment.
This section runs at 4 Mhz so it can print at the normal baud rate.
#endrem
;sertxd ("test",13,10)
speed=center
speed=speed+kick
reedpos=center
;pause 8000
printasine:
for counter1=0 to 63
if reedpos>=center then
if speed>center then
math1=speed-center
reedpos=reedpos+math1
speed=speed-gravity
else
math1=center-speed
reedpos=reedpos-math1
speed=speed-gravity
endif
else
if speed<=center then
math1=center-speed
reedpos=reedpos-math1
speed=speed+gravity
else
math1=speed-center
reedpos=reedpos+math1
speed=speed+gravity
endif
endif
scratch1=reedpos/2048
;Got it now poke it
binpointer=counter1+32
poke binpointer, scratch1 ;Hopefully "poke" can't work where it is not supposed to.
; for counter2=0 to scratch1 ;Use this for charting a sine wave
; sertxd ("*")
; next counter2
; sertxd (" ",#scratch1,13,10)
next counter1