Skip to content

Commit d3fc2ee

Browse files
authored
Improve responsiveness of Gates & Triggers (#364)
* Rewrite most of Gates & Triggers to reduce overhead in the ISRs, improve knob responsiveness * Don't invert ain; treat k2 as an attenuator, not an attenuverter. Add median filtering for additional debouncing * Minor cleanup * Add a section about fine-tuning short gates * Reduce samples when reading analogue inputs; the median filter de-noises enough that we can speed up sampling. Rename some variables for clarity * Add the formula used to calculate the gate duration * Move median(l) into a new experimental.math module, add mean(l) as well since they're both nice utility functions to have (even if mean() isn't used anywhere _yet_). Move some constants around, use MIN_GATE_DURATION_MS as the lower bound for the gate length, not TRIGGER_DURATION_MS * Move MedianAnalogInput into experimental.knobs * Expose the number of samples * median window size as parameters * Expand the class docstring * Linting
1 parent 37bc050 commit d3fc2ee

File tree

4 files changed

+280
-128
lines changed

4 files changed

+280
-128
lines changed

software/contrib/gates_and_triggers.md

+81-37
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,53 @@ rising/falling edge triggers.
1313
| `b1` | Manual input equivalent to `din` |
1414
| `b2` | Manual toggle input |
1515
| `k1` | Primary gate duration control |
16-
| `k2` | Attenuverter for CV input on `ain` |
16+
| `k2` | Attenuator for CV input on `ain` |
1717
| `cv1` | Gate output for `din`/`b1` |
1818
| `cv2` | Trigger output for the rising edge of `din`/`b1` |
1919
| `cv3` | Trigger output for the falling edge of `din`/`b1` |
2020
| `cv4` | Trigger output for the falling edge of `cv1` |
2121
| `cv5` | Toggle output; changes state on every incoming rising edge |
2222
| `cv6` | Trigger output for the falling edge of `cv5` |
2323

24-
The gate output on `cv1` has a normal range of 10ms to 2s, depending on the position of `k1`. CV input to `ain` can
25-
increase this duration.
24+
Gate/trigger input on `din` should be at least 0.8V. Ideally the trigger duration should
25+
be at least 10ms, though shorter triggers may be usable.
2626

27-
`ain` expects an input range of 0-10V. `k2` acts as an attenuverter for this input signal.
27+
`ain` expects an input range of 0-10V. `k2` acts as an attenuator for this input signal.
2828

29+
The gate output on `cv1` has a range of 50ms to 1s, depending on the position of `k1`. The
30+
knob response is quadratic, giving finer precision at the higher (clockwise) end.
31+
32+
When `ain` receives maximum voltage and `k2` is set to maximum gain, the duration of the gate on
33+
`cv1` is increased by 2 seconds, giving an absolute maximum gate duration of 3 seconds. The following
34+
formula gives the exact calculation of the gate duration:
35+
```
36+
k1 in range [0, 100]
37+
k2 in range [0, 1]
38+
ain in range [0, 1]
39+
MAX_GATE = 1s
40+
MIN_GATE = 50ms
41+
42+
q(x) = (MAX_GATE - MIN_GATE) / 10 * sqrt(x) + MIN_GATE
43+
44+
t = max(
45+
MIN_GATE,
46+
q(k1) + k2 * ain * 2s
47+
)
48+
```
49+
Gate time is rounded to the nearest millisecond.
50+
51+
## Fine-tuning Gate Duration
52+
53+
`k1` offers fairly coarse control over the gate length of `cv1`, especially at low values. If you need to fine-tune
54+
a gate duration in the 50-150ms range you should set `k1` to its minimum value and use a combination of a constant
55+
voltage into `ain` and a relatively low gain set on `k2`. By adjusting the value of your input voltage and turning `k2`
56+
you should be able to fine-tune the gate duration much more accurately.
57+
58+
For example to accurately achieve 60ms gates, patch the output from an adjustable voltage source such as Intellijel's
59+
Quadratt (0-5V) or Molten Modular's Motion Meter (0-10V) into `ain`. Turn `k1` to its minimum setting and leave it
60+
there. Slowly increase `k2` and your voltage source while keeping an eye on EuroPi's display. When the display reads
61+
`Gate: 60ms` stop adjusting `k2` and the input voltage. While fiddly, this method will provide much finer control
62+
for short gate durations.
2963

3064
## Timing Diagram
3165

@@ -36,39 +70,49 @@ minimum).
3670
```
3771
DIN or B1
3872
__________ __________
39-
________| |________| |______________
40-
41-
B2
42-
__
43-
__________________________________________________| |
44-
. . . . .
45-
. . . . .
46-
CV1 . . . . .
47-
.______ . .__________________ .
48-
________| |____________| . |______
49-
. L1 . . . L2 . . .
50-
. . . . . . .
51-
CV2 . . . . . . .
52-
._ . . ._ . . .
53-
________| |_________________| |_______________________
54-
. . . . . . .
55-
. . . . . . .
56-
CV3 . . . . . . .
57-
. . ._ . ._ . .
58-
___________________| |_________________| |___________
59-
. . . . .
60-
CV4 . . . . .
61-
. ._ . ._ .
62-
_______________| |_____________________________| |___
63-
. . .
64-
CV5 . . .
65-
.___________________. .__
66-
________| |_____________________|
67-
.
68-
CV6 .
69-
._
70-
____________________________| |_______________________
73+
________| |________| |___________________
74+
. . . .
75+
B2 . . . .
76+
. . . . __ _
77+
__________________________________________________| |_| |_
78+
. . . . . .
79+
. . . . . .
80+
CV1 . . . . . .
81+
.______ . .__________________ . .
82+
________| |____________| . |____________
83+
. L1 . . . L2 . . . .
84+
. . . . . . . .
85+
CV2 . . . . . . . .
86+
._ . . ._ . . . .
87+
________| |_________________| |_____________________________
88+
.T . . .T . . . .
89+
. . . . . . . .
90+
CV3 . . . . . . . .
91+
. . ._ . ._ . . .
92+
___________________| |_________________| |_________________
93+
. . T . T . . .
94+
CV4 . . . . . .
95+
. ._ . ._ . .
96+
_______________| |_____________________________| |_________
97+
. T . T . .
98+
CV5 . . . .
99+
.___________________. .____.
100+
________| |_____________________| |___
101+
. .
102+
CV6 . .
103+
._ ._
104+
____________________________| |________________________| |_
105+
T T
71106
```
72107

73108
We assume that between the first and second pulses, the combined CV input via `k1`, `k2`, and `ain` has changed,
74-
resulting in different gate lengths (`L1` and `L2`, above)
109+
resulting in different gate lengths (`L1` and `L2`, above). The trigger durations marked with `T` are 10ms.
110+
111+
## Delayed Triggers
112+
113+
If you need a delayed trigger, `cv4` can be used; set the gate duration of `cv1` to the desired delay
114+
duration. `cv4` will fire a 10ms trigger on the falling edge of `cv1`, which will correspond with the
115+
rising edge of `din` plus the delay. Note that using `cv4` in this way will limit the usefulness of `cv1`
116+
and `cv3`, as the gate length will be used to control the delay.
117+
118+
There is no way to add a delay between the signal received from `din` or `b1` and the rising edge of the gate on `cv1`.

0 commit comments

Comments
 (0)