I spent part of the weekend laying out something very similar! I’m using an ATTiny 84 and an MCP4131 digital potentiometer and it’s more of a function generator like MakeNoise Maths or Buchla 281. Sounds like I’ll want to go with a stateside PCB house (I’m thinking OSH Park.)
Looks nice, but it seems to me if you’re going to stick a microcontroller in an envelope generator, it should have something more interesting to do than ADSR! ADSR is a decent simplified approximation of some real world envelopes, but no more than that; with a microcontroller on the job, so much more varied and interesting envelopes are possible…
I saw that this week! I was wondering to myself if it would need something like an op amp to bring the voltages up. Still unsure whats a good voltage to send for CV. I know 12v is typical for power, but you never know with these things.
but when the switch is closed, the pin is pulled to ground and therefore reads 0 in the check:
loop_mode=!digitalRead(modePin);
Why is it done like this? It seems a little bit backwards, right?
The reason is noise. When the switch contact is open it can read strange results (the state is unknown because there is nothing there), so switches usually need a kind of pull-up or pull-down resistor to work consistently. Arduino digital pins have an internal pull-up resistor that can be enabled by setting the pin to HIGH (digitalWrite(modePin,HIGH); This way you need less components
While reading this page again, I noticed that the proper way to enable the internal pull-up is now to set it as pinMode(modePin, INPUT_PULLUP);. I don’t understand if that then also inverts the signal, so LOW then means true? can someone help me here?
From what I know of the Arduino system, I doubt that pinmode call has any effect on the interpretation of the signal. Low and high will still have their original meanings so unless the pin is pulled to ground the internal pull-up will keep it reading high. How those high and low values are interpreted by the software is up to the program logic. If you want something to happen when the switch is closed then check the pin value and perform the action if the value is low.
Is the single zener to GND going to be enough protection? I know most triggers are in the +5 range but Dieter recommends a full clamp on the A-100 diy page. I like interrupts myself to get around debounce issues.
If you were generating audio frequency signals you’d need an interrupt service routine, and even then you’d be running close to the limit of the microcontroller’s capabilities. For generating an envelope CV or reacting to slow human switch flipping, you can get away with busy loops and polling.
Is the single zener to GND going to be enough protection?
All Arduino inputs are rated for +VCC+0.5 V = 5.5 V which is higher than a typical 5.1 V zener’s max of 5.1+5% = 5.355 V so should be safe, as long as you don’t fry the zener. Assuming 1/4 W components, the series resistor gives you enough headroom for 10 V and a bit over that.
(the inputs do have built-in clamping diodes too – see this post – but they can only handle a milliamp or so, so you’ll need a much larger resistor if you remove the zener).
10k is a good default. You can use higher values, but the analog read samples the input by very briefly charging a (tiny) capacitor, so if you go too high it may not charge up properly, and the channels may start affecting each other. The usual fix for that is to add external capacitors.
I’d go for a 4.7V zener diode to keep the inputs below 5V.
@fredrik, any reason not to use a 15K resistor to keep the current into the protection circuit below 1mA for all voltages between +12V and -12V? What’s the input impedance of the digital inputs?
You might not even need the zener then, as the builtin protection diodes would be able to handle the current even at 12V.
If you expect possible negative input voltages, and want to keep the resistor small (I’d use at least 1K) an additional schottky or germanium diode in parallel with the zener would do the trick. (Schottky and germanium diodes have a lower forward voltage than regular silicon diodes (forward voltage of zener diodes is not always on the spec sheet, but I suspect it is probably at least as high as regular silicon diodes).
The 5.1 V zener should be ok (unless it 's really slow) and if you expect 5 V it won’t conduct under normal operations, but a 4.7 V should work too, it may just produce a tiny amount of extra heat in the diode (if you want to push it, it looks like the logic high threshold is +Vcc×0.6 = 3 V).
Agree that a 15k (or higher) and no zener is likely to be fairly robust. The digital inputs are CMOS gates with very high (“near infinite”) impedance (the Arduino docs say 100M but I suspect they mixed that up with the analog inputs, and I don’t think the AVR data sheet spells it out for the digital inputs.)