First time here? Check out the FAQ!

How do I generate a trigger when a control signal equals a specific value?

0 votes
...Or perhaps I should rephrase the question:

"What's the best way to generate a trigger when a control signal equals a specific value?"

Currently I'm using a ramp signal and I want a trigger when it "equals" a certain value. But these are floating point numbers so they never really "equal" each other except at zero. So I could generate a trigger when the ramp signal is above a threshold or when it is between two values but I only want it to trigger once. As if the two values really did equal each other for a single instant.

This seems like something I'd want to do fairly often. Is there a good capytalk pattern for this?

asked Nov 23, 2016 in Capytalk & Smalltalk by alan-jackson (Virtuoso) (15,840 points)

1 Answer

+1 vote
Best answer

The Equality module tests whether its two inputs are equal to one another within a given Tolerance.

Or in Capytalk, you could create a logical AND by multiplying two tests, for example:

((1 ramp) le: (!Value + !Tolerance)) * ((1 ramp) ge: (!Value - !Tolerance))

Basically, that would test when the ramp is equal to !Value but it's relaxing the condition by widening the range of acceptable values by (2 * !Tolerance).

Would either of these get you close to what you're looking for?

answered Nov 23, 2016 by ssc (Savant) (127,000 points)
selected Nov 24, 2016 by alan-jackson
That's very helpful thanks!

The capytalk I used in the end was:

    (!Value le: (!Comparison + !Tolerance)) *
    (!Value ge: (!Comparison - !Tolerance))
    stayOnFor: 0.001 s

where !Tolerance is set in a SoundToGlobalController as:

    (!BPM / 60) / 1000

so the faster the ramp the larger the tolerance range to ensure it does trigger. I'm dividing by 1000 here because I'm assuming that the sample rate of control signals is 1000hz... but I'm not sure where I got that idea from.