View Full Version : Solved Creating an oscillator with a microcontroller?
09-02-2011, 05:11 AM
I'm new to these forums, but here goes:
I had the ability to use a Basic Stamp microcontroller (breifly) at a recent camp I went to, and so when starting a recent project my thoughts turned towards it.
Would I be able to use any of the microcontrollers to create an oscillator that can change frequency rapidly based on input by the user? So, say, go from 2Hz and to 4Hz (its a very low frequency oscillator) fast enough to where the transition would be inaudible? (I probably should mention it will be used in an audio device)
I'm not yet sure on what sort of frequency or amplitude ranges I will need, but if this is possible what are the limits of the controller?
09-02-2011, 06:15 AM
You could certainly use a Basic Stamp (or a Propeller) to generate a sine wave in the range of 2Hz to 4Hz using table lookup of the sine values, then run that through a simple digital to analog converter. There will always be some error when you shift frequencies, particularly large shifts, but you should be able to keep that mostly inaudible. Details matter. For example, how many I/O pins can you allocate to the DAC (a resistor ladder type is the simplest)? How fast does the frequency have to shift and by how much? What else would the Stamp have to do? How would you specify to the Stamp program what frequency to use?
09-02-2011, 07:21 AM
2Hz to 4 Hz is generally regarded to be below the audio frequency band. For example you wont even get it through a normal audio amplifier. You would not hear it if you could.
Is that what you meant? What do you need this for?
I would probably do tbis with a technique known as Direct Digital Synthisis (DDS) which is a simple loop writing samples from a table of sine wave values out to 8 or so pins. On the pins is a simple resistor network that creates the anog values required. Search these forums and the net for DDS to see how to do it.
But then the Propeller can output audio frequencies with far less pins search around the Prop forum for DAC.
09-02-2011, 09:22 PM
I'm not looking for audio range oscillations; I'm going to be using this to control an audio filter, where the peaks of the sine wave will correspond to the "beat" of a note. Assume I wish to process a continously sustained audio signal (say, a guitar with a sustainer) and "play" quarter notes at 120 bpm in 4/4 time. For those of you who are unfamiliar with music theory, in 4/4, the beat falls on the quarter note, so 120bpm means 120 quarter notes per minute.
120 Beats/minute x (1 note/beat) x (1 minute/60 seconds) = 2 notes per second, so a 2Hz frequency.
I think the range I will need is 0.2Hz-27Hz (From around whole notes at 50bpm to 32nds at 200bpm), but thats a best case scenario. The transition needs to be fast enough to be musically sound; what is the fastest transition between extreme ranges?
The Microcontroller will be controlled by a digital "pot" to select the bpm, and footswitches to select the note duration. Right now I think that i will need a total of 8 footswitches; 6 to select between whole to thirty-second notes, one to select a "triplet" option, and one to "dot" the note (extend its duration by half). The outputs will be the 8 bits for the oscillator, and however many will be needed to control a 3 digit readout, and then a way to light an LED next to the footswitch that is "on." I'm thinking I need to create a graphic at this point haha, I'll try to draw one up. The rest of the circuit will be analog, the microcontroller is just going to be the oscillator.
A friend of a friend mentioned using the DAC resistor ladder, that seems like an excellent idea, thank you!
All-in-all, a Propeller would be a better option?
09-02-2011, 09:55 PM
A Stamp (BS2) executes basic operations in about 150us to 250us. That's maybe as much as 4000 simple statements per second. At 25Hz, you'll probably process about 16 waveform samples per cycle, maybe less. It might work. On the other hand, it would sound better to have more samples per cycle and to have enough oomph to smooth out the transitions, so I'd recommend the Propeller. Have you looked at this (http://www.openstomp.com/wiki/index.php?title=Main_Page)? It has much of what you need and you can easily modify the software to get the effect you want.
09-02-2011, 10:21 PM
Ah, that is very cool. I've been using Line6 products for my guitar, that looks to be a really good alternative. The only issue is the interface is not what I need, and I want to build this myself (I'm not yet out of highschool, I want to get some experience under my belt before college). I will bookmark that for any other later ideas I have though, thanks!
As for now, it seems the Propeller is my controller of choice, and I just need to do some more research in the meantime. Thanks so much for the help!
09-02-2011, 11:24 PM
The nice thing about the Open Stomp is that it's all open source ... schematics ... code ... etc. You're free to use the pieces that work for your needs and leave out the rest.
Look at some of the "sticky threads" at the top of the thread list for the Propeller Forum. There are all sorts of beginner's links.
09-02-2011, 11:30 PM
Will do, thanks.
Just want to mention you all have been infintitely more helpful than the people on the other forum I've been using for this project; they've been a nightmare, this has been almost too easy haha. So thanks again!
Once I get this thing up and going I will make a project thread in the appropriate forum.