I'm looking for some kind of board or shield that can be controlled by i2c at a very high level.
I don't need hi-fi, sound quality at the level of the AY-3-8910 would be perfect.
I thought about driving a AY-3-8910 directly but after reading a bit it looks anything but easy.
Basically I'd like to be able to say, play a sine/square/triangle wave at xxx.n Hz on channel 1, 2 or 3 during x msecs tone and volume envelops should be available.
Basically, I'd like to be able to play sounds as I did on the Amstrad CPC computers.
But the major point is that it should not block my program while playing.
wow!
What is so difficult ?
I was thinking in a board with one AY-3-8910 or equivalent and another MCU to drive it and talk with the master via i2c, plus some audio stuff in order to drive a speaker directly.
Let me rework the question a bit and lower my expectations.
I'm looking for a (cheap) solution for a tone generator that can be controlled by a minimum of pins from another mcu.
I want to add some very basic sound capabilities to a project I'm doing with an attiny85, so, even i2c is too much because I only have 1 free pin. But serial might work. This is why I'm looking for a "fire and forget" solution, I don't want to tie the "master" mcu, I just want to do something like MySerial.println("A#;3"); and continue doing my job and let the sound "card" play an A# for 3 seconds.
I just don't know what to use on the sound "side".
I've been looking into cheap DACs breakout boards like the MCP4725 and scratching my head over the data-sheet but I'm too noob to understand it, I still don't know if it is feasible to use it or something like it do make sound.
I just want to do something like MySerial.println("A#;3"); and continue doing my job and let the sound "card" play an A# for 3 seconds.
To do that you need something on the other side that picks up that message and does the action. This will need another processor to accomplish. Single chip devices do not exist to do this, unless you want to commission one and have a minimum order of about 100,000, and it will contain a processor of some sorts.
However if you have a MIDI sound module they can accept note on and note off commands.
The chips that play MP3 files normally have a MIDI mode, like this one:- Music shield
You don't need a Uno you can wire it up standalone.
To expensive and needs SPI, remember that I want a module that can play notes controlled only by one pin.
As you say, I'll need a cpu on the module side.
Right now I'm working with a Nano and the Tone Library I got carried away and now can generate 3 independent tones, mix them with 3 resistors, smooth the square wave a bit with a 3 posts RC network and feed the signal into a BC548 and out to a 8ohm 0.5watt speaker salvaged from an old PC.
It works nice tpp, as I said I got carried away and instead of using my time working in the control part (still have to decide if it will be serial or 1-wire) I just spent my fun time for today implementing a function to play the 12 major chords, witch is something that I'll never need but it was fun and they sound (sort of) nice...
As I can get a pro Mini from ebay for about 1.4 USD that is cheap enough for a 3 channel version.
For a micro version I'm thinking about an attiny85, but still haven't tested any Tone lib on that mcu.
I'd like to ask one thing, I'm looking for the best values for the R and C in the RC network in order to get an approximation of a sine wave. I have the values for a 10KHz signal, but don't know how to calculate them for a range from (more or less) 100 Hz to 2KHz.
I've red a lot today about it and found out that the question "how do I convert a square wave in a sine wave" generates about the same consensus as what's the best editor, vi or emacs. But I saw a video of a guy using an oscilloscope in several parts of one of this RC networks, and for me that's good enough, I'll take op-amps when I feel I'm ready.
Can you point me to a calculator for this ? Please.
but don't know how to calculate them for a range from (more or less) 100 Hz to 2KHz.
That is because you can't.
If you have a square wave it contains all the odd harmonics up to infinity. To convert it into a sin wave you have to remove all these harmonics and leave the fundamental. So with such a wide range the fundamental of 2KHz is the 20th harmonic of 100Hz. You get a pretty good square wave with 19 harmonics. If you start suppressing harmonics any lower than 2KHz then the size of the wanted 2KHz signal will be suppressed.
So any simple RC value you calculate will be no good over the whole range. An RC filter is a low pass filter with a roll off of power of 3dBs per octave, that is another way of saying for each doubling of frequency above a "break point" the output drops by half. the break point of a low pass filter is Fb = 1/2PiRC.
See:- Low-pass filter - Wikipedia
Ok. A low-pass filter do the job for 1 frequency, the R and C values are chosen based on that frequency. Is that it?
For a range of frequencies that covers the audio spectrum, is there a solution? I've been looking into ampop based dynamic filters but I haven't yet understood if it is possible or not to add a soft effect to a sound produced in the Nano using the Tone library.
Basically you have a square wave output. To turn that into a sin wave you need to remove all the harmonics above the fundamental. You can't do that using a simple circuit. Possibly the simplest thing to use is a switched capacitive filter. This requires you feed it a clock signal that is some multiple of the frequency you want to filter, typically 100 times. This then could track the audio output.
However this sort of thing is not normally done because the solution is to not use the Tone function at all but to have some sort of D/A converter and output another wave shape directly. The simplest is a triangle wave, it sounds resasionably good and is simple to compute.
Sorry, "ampop" is the Portuguese word, it comes from "Amplificador Operacional".
I've seen arduino sketches using pre-calculated sin tables. But what I don't understand is how those values are used.
Does the "shape" of the wave comes from the pwm "level" we write to the pin?
(I would test this if I had an oscilloscope, I don't, so I have to ask, sorry)
Does this produces a triangle wave on pin 'pin'?
And the frequency is given by the 'xxx' value? If this is it, then the sin tables are just the pwm 'level' and the frequency is controlled by the delay between each pulse (the xxx value)? At the moment I'm not worring if the _delay_ms() function is good enough of fast enough to get the wanted frequency, I'm just thinking if this is the correct method to produce a digital aproximation to the several types of wave.
If you filter the output at the PWM frequency yes, but you will need to increase the PWM frequency to over 25KHz so it doesn't interfere with the audio signal you are trying to modulate onto it.
And the frequency is given by the 'xxx' value?
Well the frequency is the reciprocal of 512 * the 'xxx' value.
At the moment I'm not worring if the _delay_ms() function is good enough of fast enough to get the wanted frequency
Probably not. You can use delay micro seconds and you can step through the triangle in bigger steps than just one.
I'm just thinking if this is the correct method to produce a digital aproximation to the several types of wave.
Yes. You can output what ever shape you like if you use a look up table. Here is a strange shape I made which was one cycle of a sin wave followed by two cycles of saw tooth. Mind you I use interrupts to trigger the next sample and direct access to the timer register to change the PWM width.