Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

How to produce drum n' base sound effects

Status
Not open for further replies.

twiart

New Member
Hello guys,I need to produce drum n' base and other sounds effects with a PIC18 to a simple 66mm 8ohm speaker.

Im thinking of using PIC's timer and prescaler to divide the oscillator frequency and then output it to the speaker..is that workable?
 
Last edited:
You're on the right track...

I've never done this, someone who has will probably need to chime in to to correct anything I say thats wrong. First, you'll want to set up an output compare for PWM mode, at a 50% duty cycle. Choose an oscillator and a prescaler such that the output can be set from 0 Hz to at least 11 Khz (preferably 44Khz or so). Then, all you have to do, is load a value into the period register. That value you loaded will set the frequency of the output.

To get the value of what you need to write into the period register, use an uncompressed .WAV file. Just read a byte from it, and write it to the period register. You'll want the wave file to be the same frequency and same number of bits that your period register is.

You'll then want a circuit to change the square wave to a sine wave otherwise it'll sound terrible (unless you want the square wave's sound). If I'm not mistaken, you can just use an RC circuit.

How I would have the software setup:
1. PWM mode disabled, along with interrupt (actually, it won't matter much if you use a PWM mode since you'll need the interrupt to occur I guess)
2. Read multiple values from the wave file and store in a FIFO buffer (if you get a lot of high frequencies in a row you might have a buffer underrun)
3. Write value to PWM register
4. Enable PWM and interrupts
5. At every interrupt, pull a value from the FIFO and write it to the period register
6. Have a process running that constantly pulls data from the .wav file and stuff it into the FIFO as long as the FIFO isn't full and the end of the .wav file has not been reached

Of course, this requires you to figure out how to read a .wav file. Drums, unfortunately, are not just as simple as putting two or three tones together. They are a mash of many many frequencies, some high and some low. If you have one drum sound though, I suppose you could change the frequency of it by multiplying by some number before loading into the timer.
 
Last edited:
how to control speaker volume in C or assembly language?

noggin,thank you for your reply.i have finished coding PWM thanks to your suggestion.Now i can't figure out how to control the volume of the speaker's sound with keypad's keys...i mean press * or # to increase or decrease volume..
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top