Question
Asked September 5 2018

Community Question

I need to count the number of times a digital input detects state changes within a specified time window (100ms to 1000ms). Any suggestions?

Thanks.
AI Support Bot
AI Support Bot
Synthiam
Greetings! I'm the support robot! I've searched other questions, tutorials and controls related to your question. Take a look at these links. They're all sorted by what I believe is the most relevant:
September 6 2018
with a loop, use the WaitForChange function to detect the change of the digital input.

I will post a code example when I get to my computer.
September 6 2018
@rz90208:
WaitForChange evaluates the condition every 10 ms, then you have the EZ-Script parser and communications overhead.

@Jim Milan:
if you need accuracy and/or the transitions are fast you will need a micro-controller e.g. Arduino, PIC.

EZBuilder (Desktop/Mobile) applications runs the logic code, EZB only handles the hardware.

you can try the EZ-Script maybe can work if your requirements are not "Real Time" :

Code:


#Monitor Port D23 changes for one second")

$start_date=$date
$last_value=GetDigital(D23)
$number_of_changes=0

:loop
$current_value=GetDigital(D23)

if ($current_value!=$last_value)
$last_value=$current_value
$number_of_changes=$number_of_changes+1
endif

$timespan=CDateTime($date)-CDateTime($start_date)
$timespan_sec=FmtTimeSpan($timespan, "ss")

if ($timespan_sec<1)
#Same timeout used in WaitForChange(...)
Sleep(10)
Goto(loop)
endif

print("number_of_changes: " + $number_of_changes)
September 7 2018
@ptp
Thanks, your code worked. It was the kick start that I needed. I'm using a Parallax X-Band (10.525 GHz) Motion Detector in my latest ARMadeus robot. The unique feature of this sensor is that is capable of detecting motion though walls. I understand the 1 second limitation by using the system $date function. Since the sensor has an enable pin, I may tinker with a combination of Set(DigitalPort, ON/OFF) and Sleep(ms) commands to generate an adjustable enable pulse.

Jim Milan