|
|
After having a good look through the hardware documentation, I realised that the 8bit Timer 0 output could run as high as 8MHz - that would be too much for any speaker, so what would the effects on the RCXs speaker be?
I wrote a few test programs to have a go. Hmmm, lots of hissing. Whooo grating scratching noises. Oh dear, nothing at all. Try again - lots of times.
What I eventually found worked was
- Set speed/8
- Set reset counter on A
- Set Output High on A
- Set Output Low on B
- Set A=32
This will create an extremely high frequency square wave. Now, by varying B between 0 and 16, we can control how wide the peaks of the square are. This affects the amplitude of the speaker (Eureka). Note you can't actually hear any sound yet - the square wave has a frequency of 65KHz, which is inaudible, although might annoy your pets (If they're bats).
What we have to do next is use another square wave made out of the super high frequency wave. Easy enough to do - just enable and disable the timer very quickly. I did this with a couple of nesting loops to get a zapping sound (i.e. frequency value goes from high to low by using the frequency value as the limits of a dummy inner loop - take a look at the next page and things will become clear).
The next page is the source code to the zapping program. It gives a quite discernable amplitude variation (although not perfect, could do with a bit of tweaking).
|
|