Creating sound tones with TTL logic

 

I've got a question. Have any of you guys ever used TTL / PWM to make music tones from a micro?
I've recently added a 8w amp to my drumbot:
https://www.robotshop.com/letsmakerobots/node/13763
And am trying to make musical notes from driving the amp with TTL logic.
I'm using bascom basic, and the "sound" command as shown below.
My problem is that as I understand sound. We hear from 20 hz to 20 khz.
So I've tried setting the pulses at various levels between 20 and 20k, as well as tried various durations.
When I use 1000, and 1000, as well as 65535, and 10000 I get decent tones.
With small changes to these settings, they sound the same. And any other values I get horrible fax modem noises.
I also tried making my own loops to drive the amp with frequencys in this range. But the output is the same.
So now I'm thinking I might need to make an DAC circuit to properly get (at least) 8 bit sound from this setup.
Thanks for any advise.

Example

Dim Pulses As Word , Periods As Word

Pulses = 65535 : Periods = 10000                           'set variables

Speaker Alias Portb.1                                       'define port pin

DO

Sound Speaker , Pulses , Periods                           'make some noise

'periods/pulses range from 1-65535
LOOP
END

1bit square waves will

1bit square waves will produce a reasonable sound, check out this project as an example. If your micro clock is running pretty fast, then you can do some quite clever sine-wave emulation too, but this is certainly not necessary for producing simple (or even many more complex) tones.

Apparently the Sound function in Bascom is a little unreliable, but I can’t say I’ve used it myself. Perhaps you’d be better off using a timer routine to handle sound waveform generation.

What core frequency is your Mega32 running at?

RE

$crystal = 8000000  ’ internal resonator

I read the posts on the Allura project. This gave me a couple new ideas. I’ll try a different routine to drive the amp with a timer.

I’ll reply again after I try it. Thanks!!!

 

One more thing, I’m going to test with a different speaker as part of this. Just to see if there’s a noticeable difference.

 

 

RE

I still haven’t found a good solution that makes the notes sound like notes. (its all fax modem sounding)

So I bought a Bascom book from the manufacturers website, and they list sample code to make a little 8 switch piano.

The catch is they don’t use the “sound” command I’ve been messing with. So I’m gonna try this new code and move forward from here.

But if this doesn’t work then I’ll go a different direction to add additional musical sounds from this robot.

 

Thanks!!!