Pulser #2 — Pulse Generation
For a pulser, a 5ms pulse at a freely selectable frequency is practical. It serves as a CV trigger signal.
The basic sequence is as follows: Per clock period, a loop is traversed once. Within the loop, two sub-loops run in succession. The first loop generates the HIGH segment, the second loop generates the LOW segment. How long each segment lasts is controlled by a counter that counts down to 0. The larger the counter, the longer the segment.
The duration of individual instructions is fixed and known, and you can additionally specify how many wait cycles should be inserted after an instruction.
Using the counter, you can thus determine with an accuracy of 8ns how long a loop should run.
In the concrete implementation, in addition to counting down the counter, 7 wait cycles are inserted, so that the total duration of one counter loop is 8 × 8ns, i.e. 64ns.
For the clock, I orient myself on MIDI Clock and therefore use a resolution of 24 PPQ. All timing calculations are derived from this.
Pulse Duration
The pulse duration should be 5ms. One counter loop takes 64ns, so 78,125 iterations are needed.
Pause Duration
The parameter you can set on the pulser is BPM. Taking the 24 PPQ into account, this yields a frequency. At 120 BPM, for example, that's 48 Hz. The frequency directly determines the period duration — in this case 20,833,333 ns. The pause is then the period duration minus the pulse duration. At 120 BPM, that's 15,833,333 ns, which rounds down to 247,395 iterations.
Pulse Train
That was all a bit of abstract number juggling, but in summary, there are two counters — the pulse counter and the pause counter. One is fixed and derives from the pulse length, and the other derives from the BPM setting. These counters are counted down to 0 one after the other — first the pulse counter, then the pause counter. This produces one tick pulse each time, and the process repeats indefinitely.
Since the PIOs run very stably without interference from the rest of the system, this allows for precise clock signal generation.
