Discussion:
Detect edge and set boolean variable
(too old to reply)
aenne
2008-08-13 13:40:06 UTC
Permalink
Hello, I am searching for a VI that sets a boolean variable to true each time a rising edge is detected at the input channel and subsequently sets it to false, until the next rising edge arrives. Do you know if there is an Express-VI that I could use for this purpose or can you give me a hint how to program a VI that does what I need? Thanks in advance, Aenne
dan_u
2008-08-13 13:40:07 UTC
Permalink
Hi Aenne,is the input channel boolean? Then you can just use the &quot;Greater?&quot; function from the Comparison palette to compare the latest value with the previous one. See code snippet.<img src="Loading Image..." border="0" alt="Rising Edge" title="Rising Edge" width="212" height="139">&nbsp; Hope this helps,Daniel&nbsp;Message Edited by dan_u on 08-13-2008 03:20 PM


RisingEdge.png:
http://forums.ni.com/ni/attachments/ni/170/348945/1/RisingEdge.png
aenne
2008-08-13 13:40:08 UTC
Permalink
Hi Daniel,&nbsp;thanks for your reply. The input channel is not boolean. So far I have used the DAQmx Creat Channel (CI - Count Edges).vi to count the edges&nbsp;arriving on&nbsp;that channel. So perhaps a possibility would be to check if the counter increases an then set the boolean variable to &quot;true&quot;. How can I implement this? Or is there a &quot;direct&quot; way without using the counter?&nbsp;Thanks again,&nbsp;Aenne
dan_u
2008-08-13 14:10:07 UTC
Permalink
Hi Aenne,&nbsp;yes, this is one possible way to do it.As you plan to use the Count Edges it means you have a digital channel (which is what I meant by boolean in my previous post). If you want to detect all edges of the digital line your sampling has to be faster than the edge frequency.In this case you could also configure it as digital input and use the algorithm proposed in my previous post.&nbsp;Daniel&nbsp;&nbsp;
aenne
2008-08-13 15:10:11 UTC
Permalink
Hallo Daniel,&nbsp;the edge frequency is 1Hz, so detecting all edges shouldn't be a problem. &nbsp;Can you explain a bit more in detail how I can solve my problem with your proposed algorithm? It confuses me that you have a while-loop. Is the Count Edges inside or outside that loop? How can I configure it as digital input?&nbsp;&Auml;nne
dan_u
2008-08-13 15:40:06 UTC
Permalink
Hi &Auml;nne&nbsp;If you use Count Edges this will return the edges between two readings afaik. This means you can just check whether the count is &gt; 0.&nbsp;If you use a digital input and configure it to read single values then you will have to compare the old value with the new value as shown in the code snippet. The DAQmx read will be in a loop anyway (timed loop most likely), just use a shift register in this loop to store the old value.&nbsp;Daniel&nbsp;
Continue reading on narkive:
Loading...