Comparator¶
Description¶
The Comparator object is a class to process both discrete and continuous signals such as measurements from digital inputs or analog sensors. Depending on the configuration it acts like a comparator with or without an hysteresis or a limiter. The intervals can be used to delay state changes for example to debounce a digital signal or filter flicker.
› Inherits: | Object |
---|
Properties¶
input¶
This property holds the input value to compare with the thresholds.
› Type: | Variant |
---|---|
› Signal: | inputChanged() |
› Attributes: | Writable |
output¶
This property holds the output value of the comparator. If state is true
it is equal to outputValueOn. Otherwise it corresponds to outputValueOff.
› Type: | Variant |
---|---|
› Signal: | outputChanged() |
› Attributes: | Readonly |
outputValueOff¶
This property holds the value for the off state. If state is false
output is set to this value. Binding an expression to this property will make the output property being updated as well.
› Type: | Variant |
---|---|
› Default: | false |
› Signal: | outputValueOffChanged() |
› Attributes: | Writable |
outputValueOn¶
This property holds the value for the on state. If state is true
output is set to this value. Contains this value a binding, it is also mapped to output.
› Type: | Variant |
---|---|
› Default: | true |
› Signal: | outputValueOnChanged() |
› Attributes: | Writable |
state¶
This property holds the current state of the comparator.
› Type: | Boolean |
---|---|
› Default: | false |
› Signal: | stateChanged() |
› Attributes: | Readonly |
thresholdValueOff¶
This property holds the lower threshold. The value of the input property has to be less or equal to this value to switch state to false
. If set to undefined
or left blank the value of property thresholdValueOn is used instead, i.e. no value hysteresis functionality is realized.
› Type: | Variant |
---|---|
› Signal: | thresholdValueOffChanged() |
› Attributes: | Writable |
thresholdValueOn¶
This property holds the upper threshold. The value of the input property has to be greater or equal to this value to switch state to true
.
› Type: | Variant |
---|---|
› Default: | 0 |
› Signal: | thresholdValueOnChanged() |
› Attributes: | Writable |
timerIntervalOff¶
This property holds the time in milliseconds for which input has to be less or equal thresholdValueOff to switch state to false
.
› Type: | SignedInteger |
---|---|
› Default: | 0 |
› Signal: | timerIntervalOffChanged() |
› Attributes: | Writable |
timerIntervalOn¶
This property holds the time in milliseconds for which input has to be greater or equal thresholdValueOn to switch state to true
.
› Type: | SignedInteger |
---|---|
› Default: | 0 |
› Signal: | timerIntervalOnChanged() |
› Attributes: | Writable |
Signals¶
inputFallingEdge()¶
This signal is emitted immediately whenever the input signal falls below thresholdValueOff independent of any configured timer intervals. This allows using Comparator for falling edge detection on the input signal.
inputRisingEdge()¶
This signal is emitted immediately whenever the input signal exceeds thresholdValueOn independent of any configured timer intervals. This allows using Comparator for rising edge detection on the input signal.
outputFallingEdge()¶
This signal is emitted whenever the state property changes from true
to false
. If timerIntervalOff is 0
this signal is emitted at the same time as the inputFallingEdge() signal. Otherwise it’s not emitted until the state change actually takes place. This allows using Comparator for falling edge detection on the output signal. If both rising and falling edges need to be detected the stateChanged() signal can be used instead.
outputRisingEdge()¶
This signal is emitted whenever the state property changes from false
to true
. If timerIntervalOn is 0
this signal is emitted at the same time as the inputRisingEdge() signal. Otherwise it’s not emitted until the state change actually takes place. This allows using Comparator for rising edge detection on the output signal. If both rising and falling edges need to be detected the stateChanged() signal can be used instead.
Example¶
import InCore.Foundation 2.5
Application {
// define fake temperature measurement with random values
Measurement {
id: temperature;
data: 25
}
Timer {
running: true
interval: 100
onTriggered: temperature.data += 0.5 - Math.random()
}
// simple Comparator which outputs a boolean indicating whether the temperature exceeds a given threshold
Comparator {
input: temperature.data
thresholdValueOn: 30
onOutputChanged: {
if (output)
console.log("Temperature above", thresholdValueOn)
else
console.log("Temperature below", thresholdValueOn)
}
}
// define a threshold and time hysteresis
Comparator {
id: hystComp
input: temperature.data
thresholdValueOn: 30
thresholdValueOff: 20
timerIntervalOn: 30000
timerIntervalOff: 15000
onOutputRisingEdge: console.log("Temperature exceeded", thresholdValueOn, "for more than", timerIntervalOn, "seconds")
onOutputFallingEdge: console.log("Temperature fell below", thresholdValueOff, "for more than", timerIntervalOff, "seconds")
}
// use Comparator output to count number of seconds which temperature is not in range
Counter {
running: hystComp.output
interval: 1000
onValueChanged: console.log( "Temperature outside allowed range for", value, "seconds")
}
}