Pages: [1]   Go Down
Author Topic: ATmega328 + 8-bit PWM Out + Envelope = Drum Sound - but how to do the Env?  (Read 1178 times)
0 Members and 1 Guest are viewing this topic.
Brazil
Offline Offline
God Member
*****
Karma: 3
Posts: 616
Wusik Dot Com
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Guys, I need some help with this. I'm doing a small project for a friend who needs two different drum sounds per ATmega328. 8-bit is ok, the only problem is the envelope, as I can't do in software as it would sound terrible (and it does, I tested) since the whole thing is 8-bits.

The drum sounds already works, using PWM for the output, I can even get 6 voices per chip if I wanted, but that's no the case. I need just 2 voices, so I can use the flash to store longer samples.

If you want to check some of the code of the 6 voices drum sounds, here's the link of the project I created:
https://github.com/Beat707/BeatVox
There's some youtube videos, just search on google for BeatVox

Now, here's what I want to do, to create the envelope using another PWM output, and have a Transistor(s) take care of the Envelope/VCA. I have seen circuits for VCAs for modular synths, but I want something dirty cheap and simple, to combine both outputs and have the second determinate the volume output. I know that there will be some DC problems, but maybe I could use a third PWM output to add DC as the Envelope lowers.

I will try to draw some pictures later this weekend to show what I have in mind. And yes, each PWM output will have its own filter to convert to a Voltage output, instead of a PWM output.

Anyway, thank you for any help.

Best Regards, WilliamK
Logged


Brazil
Offline Offline
God Member
*****
Karma: 3
Posts: 616
Wusik Dot Com
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Ahh, to convert PWM to Voltage I'm using this simple solution:

http://provideyourown.com/2011/analogwrite-convert-pwm-to-voltage/

Logged


Brazil
Offline Offline
God Member
*****
Karma: 3
Posts: 616
Wusik Dot Com
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Here's my current list of Transistors, the ones I got in-house. ;-)

   12  x 2N5087 PNP - 100ma
   20  x PN2222 NPN - 600ma
   30  x 2N3904 NPN - 200ma
   30  x 2N3906 PNP - 200ma
   200 x BC547B NPN - 45V - 0.1A
   10  x ULN2803A DIP-18 Transistor Array (8 in/outs) 500ma

I remember using the PN2222 as a voltage controller and a potentiometer, but the test with the PWM had tons of noise, but I have to test again, to be sure I did it right. Since I have NO CLUE on what I am doing, any help would be much appreciated.  smiley-red
Logged


Brazil
Offline Offline
God Member
*****
Karma: 3
Posts: 616
Wusik Dot Com
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm also thinking on using an ATtiny85 and just have a single voice per chip, plus use it in 8Mhz internal mode. That will simplify things up, and I can get those chips for very little money, and its easier to import. Brazil import laws are stupid, you end up paying up to 200% the price just on transportation - customs and other fees...  smiley-cry  It sucks BIG time...  smiley-sad-blue
Logged


Brazil
Offline Offline
God Member
*****
Karma: 3
Posts: 616
Wusik Dot Com
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

A question. Can't I combine two 8-bit PWM outputs to form a single 16-bit output? This way I could do the envelope in software, and have it applied to the output. I just have to figure out how it would work. ;-)
Logged


Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 548
Posts: 27372
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

WilliamK,
Check out some of the videos here


This guy organfairy seems to have all kinds of boxes, one being an envelope generator.
He shows the schematics too with explanations of what the part do.

I think I'd be inclined to run your sound thru a 12-bit DAC, input it as the reference voltage, and use SPI to send in the 12-bit gain.
That works well with analog signals if you have a dual supply DAC so the output can swing around 0V and not have to mess with DC offsets and capacitive coupling to mess with your sound.

http://www.analog.com/en/circuits-from-the-lab/cn0036/vc.html
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Brazil
Offline Offline
God Member
*****
Karma: 3
Posts: 616
Wusik Dot Com
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks bud, I will check this one out.  smiley-cool
Logged


Brazil
Offline Offline
God Member
*****
Karma: 3
Posts: 616
Wusik Dot Com
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Here's something interesting:

http://embeddednewbie.blogspot.com.br/2011/02/review-of-arduino-dac-solutions.html

Resistor/PWM hybrid DAC

This is a good explanation on how to combine two PWM outputs in order to double the bit resolution. So combining two 8-bit arduino PWM outputs you can get a 16-bit PWM output! Remember Arduino's limits if you plan on going down this road. I mean, the Atmega chip is just 8-bit...

Logged


Brazil
Offline Offline
God Member
*****
Karma: 3
Posts: 616
Wusik Dot Com
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I will test this one out soon. The idea is simple, to have the 8-bit sound, and the envelope just multiples from 0 to 255. Just need to test how fast the processor can cope with the math, for at least 1 voice. I will also test with the ATtiny85, since there are enough PWM ports for the same test.
Logged


Pages: [1]   Go Up
Jump to: