Multi-mode AD envelope generator with an AVR, plus example circuit

Started by idiot savant, October 15, 2016, 01:04:37 AM

Previous topic - Next topic

idiot savant

Here's a multi mode AD envelope generator built using an AVR. I used an ATTiny85, but the ATTiny45 should work just fine as well.

I'll post a Zip archive for anyone that wants to take a look at the code. The code function here destroys text formatting.

This program is written in C, and will drop right in to AVR Studio. I have extensively commented throughout, so it should be quite easy to follow.


This envelope generator has 3 modes available via a rotary switch:

Simple gated mode: Press the switch, and the attack cycle starts, release the switch, and the decay cycle will start.

Discrete triggered mode: Press the switch, and the attack cycle runs fully and holds at MAX. Press again, and the decay cycle will run fully and hold at its minimum.

Looping mode: Press the switch to enable or disable the LFO. Both attack and decay knobs will control the speed and waveshape.


The output is PWM, and can be run through a LPF, or LED, or whatever for interfacing with your circuit.

Fastest attack/decay time is around 65ms, or 15Hz-ish. Slowest is around 0.06Hz, so 16-ish seconds.


Here's a schematic:




Here's a simple VCA circuit to show the use of the AD generator:


This isn't a ready made stompbox per se, but it will showcase the functions of the AD.



Here's a link to an archive of the two schematics and the code for the project:
https://drive.google.com/file/d/0BzdyH8_QSjbXMkpzNzc3bkxtdW8/view?usp=sharing



As an aside, this code contains what I consider to be the "Cadillac" of debouncing routines. Anyone having trouble with debouncing should check this out for that reason alone.

I've seen a number of simple debouncing routines posted here using hardcoded delays. This is fine assuming your processor has nothing else to do, and you can waste millions of cycles in delays. Unfortunately, it's a pain if you want to perform other functions, or debounce multiple switches.


This debouncing code is from Peter Dannegger at AVRFreaks. A credit and link to his article is included in the code.

It's based on the vertical counter concept, and is capable of debouncing 8 switches independantly. It also works symetrically, so both on and off transitions are covered. It's small, fast and pretty much bullet proof.


Anyways, I hope you guys enjoy this little program, and find some fun ways to use it, or improve it. If you have any comments, or suggestions, I'd love to hear them.


Thanks!
:)

ElectricDruid

Nice work.

How much noise do you get from the simple RC filtering? What's the PWM rate?

You could improve it by changing the second stage so that the resistor is ten times larger and the cap ten times smaller. This decreases the loading that the second filter places on the first and improves the response overall.

Not that I'm against PWM-as-DAC outputs or simplicity at all. I'm all for it. People underestimate what you can get away with, and often design things to some technical specification with no idea how good or bad it sounds.

HTH,
Tom

idiot savant

Thanks for the comments! :)

PWM is run at 31.25kHz. In the VCA circuit shown, and my MS20 and Polivoks filter circuits I didn't have any perceptible noise at all. Though the filter circuits themselves help reduce some of the possible noise.

Good point made about the reconstruction filter. In the original i was using 1k/10uf. I've since moved to 10k/1uf, though I haven't noticed any drastic improvement with the circuits I've tested it with. Depending on how you're using it, you're totally right that it may be more important to think of loading in some cases. Possibly some circuits might benefit from an active filter stage instead.

With regards to noise, so much can be eliminated or mitigated just with proper grounding. So far I've been surprised how well it works even with just the simple filter.