Skip to content

Instantly share code, notes, and snippets.

@bigs
Created January 31, 2017 05:18
Show Gist options
  • Save bigs/6afe1b4959113adb2c62553ce1b87b06 to your computer and use it in GitHub Desktop.
Save bigs/6afe1b4959113adb2c62553ce1b87b06 to your computer and use it in GitHub Desktop.
// pulse threshold (v)
Param threshold(1.5);
// clock mul (pos) or div (neg) factor
Param factor(1);
History last(0.);
History ticks(0.);
History childTicks(0.);
History clockLength(0.);
History childClockLength(0.);
ticks += 1;
childTicks += 1;
// pulse detection
if (in1 >= threshold &&
last < threshold) {
clockLength = ticks;
if (factor > 0) {
childClockLength = clockLength / factor;
} else if (factor < 0) {
childClockLength = clockLength * abs(factor);
} else {
childClockLength = clockLength;
}
ticks = 0;
}
// pulse generation
output = 0.;
if (childTicks >= childClockLength) {
output = 5.;
childTicks = 0.;
}
// shift last value
last = in1;
out1 = output;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment