# Edge detector

Process

Detects rising, falling, or both edges on a boolean input and generates a timed output pulse.

Edge detector
I
O

# Inputs

IDAbbrevNameTypeDefaultDescription
inputIInputBOOLEANfalseBoolean signal to monitor for edge transitions.

# Outputs

IDAbbrevNameTypeDefaultDescription
outputOOutputBOOLEANfalsePulse output. Goes high for the configured pulse duration when an edge is detected.

# Configuration

IDNameTypeDefaultUnitDescription
directionDirectionENUM0Which edge transitions to detect. Rising detects false-to-true, Falling detects true-to-false, Both detects any change.

Details:

Values: Rising, Falling, Both
pulse_durationPulse durationNUMBER0.1sDuration of the output pulse generated on each detected edge.

Details:

> 0
startup_delayStartup delayNUMBER0sTime after system boot during which edge detection is suppressed. Prevents false triggers from peripherals initializing. Set to 0 to disable.

Details:

≥ 0

# State

IDNameTypeDefaultUnitDescription
prev_inputPrevious input stateBOOLEANfalseStores the previous state of the input to detect transitions.
initializedInitializedBOOLEANfalseTracks whether the block has received at least one input event. The first event establishes a baseline without triggering edge detection.

# Source Code

View Volang source
channel = input::channel()
value = input::value()

extern fn onPulseEnd() {
    output::set("output", false)
}

if (channel == "input") {
    prev_input = state::get("prev_input")
    initialized = state::get("initialized")

    if (!initialized) {
        state::set("prev_input", value)
        state::set("initialized", true)
        return
    }

    startup_delay = config::get("startup_delay")
    if (startup_delay > 0 and time::uptime() < startup_delay) {
        state::set("prev_input", value)
        return
    }

    direction = config::get("direction") // 0=Rising, 1=Falling, 2=Both
    edge_detected = false

    if (direction == 0) {
        edge_detected = value and !prev_input
    } else if (direction == 1) {
        edge_detected = !value and prev_input
    } else {
        edge_detected = (value and !prev_input) or (!value and prev_input)
    }

    state::set("prev_input", value)

    if (edge_detected) {
        callback::clear()
        output::set("output", true)
        pulse_ms = math::round(config::get("pulse_duration") * 1000)
        callback::set(pulse_ms, "onPulseEnd")
    }
}
Detects rising, falling, or both edges on a boolean input and generates a timed output pulse.