LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Edge detection

Solved!
Go to solution

I have found an edge detection example from https://decibel.ni.com/content/docs/DOC-11651, I have modified this so that it work with my Vi.

 

 

I'm using a very slow signal (≈0.14Hz) with noise, at the moment I can detect threshold change, but the next step would be to detect 'any edge' hence I want to detect both rising edge and falling edge of the threshold LED.

 

Unfortunately I can't get get it working fully, the Edge detection LED sometimes misses the threshold LED if the changes are happening too fast.

 

I want the Edge detection LED to be on for a very short time,  so that it has enough time to detect the changes if they are occurring too fast,  is it possible to achieve this?

 

 

 

0 Kudos
Message 1 of 8
(6,789 Views)

Hello D_Raz,

 

In your code if I understand it correctly the "Threshold Detected" LED is essentially lighting up whenever your signal is over the threshold, a constant of 0.5 that you have set in the block diagram. The "Edge detection" LED is then going to light up the moment that your simulated signal crosses your threshold as a rising or a falling edge, and turn off on the next iteration of the loop unless it is the opposing edge.

 

This is because of the way that the shift register takes values from previous loops and puts it into the Y value of the Exclusive OR, to then pass a True or False to the Edge detection LED.

(Some good info on shift registers and their functionality can be found here: http://www.ni.com/gettingstarted/labviewbasics/shiftregisters.htm )

 

As such even if your Threshold Detected LED lights up, your Edge detection LED does not have to light up also, as it will only switch on whenever the rising or falling edge passes a threshold point.

 

A quick point about the code in general; in your simulate signal VI you have configured timing for the task itself, and as such will not also need the Wait(ms) function with a constant of 100 wired to it as this will add an additional 100ms on to the top of your task every time your code iterates. You can delete this function and configure your timing by double clicking on your Simulate Signal express VI and playing with the settings in there.

 

Best regards,

 

Mark W

Applications Engineer

National Instruments UK & Ireland

Best regards,

Mark W
Applications Engineer
National Instruments UK & Ireland
0 Kudos
Message 2 of 8
(6,742 Views)

Thank you for your reply

 

Just clarify this, when ever the value of my signal goes above 0.5 i want the 'threshold LED to come on'

 

When the Threshold led comes on I want to detect that the LED has come on, And i would also want to detect when the Threshold LED has switched off so just to put it context I wan to Detect Rising edge and Falling Edge with respect to my 'threshold LED' (ie detecting a 'toggle'.

 

If the shift register is not a good idea what would you recommed?

 

 

0 Kudos
Message 3 of 8
(6,732 Views)

Hey D_Raz,

 

That is what the "Edge detection" LED is indicating when you choose the "Any Edge" case structure. If you want to track to see whether the change is a rising edge or a falling edge it is just a case of monitoring whether the X value coming from "threshold detected" is greather than Y from your shift register for a rising edge, or whether the Y value is greater than the X for the falling edge.

 

I have attached some code with this to help determine when a rising edge, falling edge or no change occurs, where in the True case there is a select function to help decide based on our greater than function to determine whether it is a rising edge or a falling edge.

 

Are you looking to use this with hardware in the future or just simulated signals?

Best regards,

Mark W
Applications Engineer
National Instruments UK & Ireland
0 Kudos
Message 4 of 8
(6,720 Views)

Dear Mark

 

first of all thank you for your help, I understand how the vi works and that is what exactly what I need for my project however there is one major obstacle and that is the edge detection doesn't always work if you add some noise to the signal( just like example you provided)  this is because if the threshold value changes quickly (on-off-on  etc) edge detection fails to see detect these changes.  the vi you provided has the same problem.  if you click on " any edge" see how the 'edge detection' LED behaves with reference to the 'Threshold LED' it doesn't always catch the edges.  Is there as way where you can make the "edge detection" side of things run faster than the rest of the loop?

 

 

 

Appreciate your feedback

0 Kudos
Message 5 of 8
(6,695 Views)

Hi D_Raz,

 

On my side whenever I run the program the "Edge detection" LED catches every edge each time the line on our waveform chart passes the point at 0.5 and then registers whether it is a rising or a falling edge (on the image attached I have labelled the rising edge as red and the falling edge as green). I'm not sure what you are trying to achieve to be honest, do you want to catch every single rising and falling edge whenever the value is above our 0.5 threshold? ( on the image I have labelled these cases in blue )

 

 

Best regards,

Mark W
Applications Engineer
National Instruments UK & Ireland
0 Kudos
Message 6 of 8
(6,665 Views)

Mark

 

I'm sorry if I haven't been clear, here is a diagram of what I wanted the Vi to do (its encircled in blue).

 

Basically this is what I want to happen.

 

When the Threshold LED lights up I want a signal to be  outputted to my DAQ, I also want a signal when the Threshold LED switched off (from On).

 

So whenever the the threshold LED lights up and then then switched off I want pulses to be sent to my DAQ (one for Threshold LED coming on and one for switching off).

 

Hope this helps.

0 Kudos
Message 7 of 8
(6,645 Views)
Solution
Accepted by topic author D_Raz

Hi D_Raz,

 

Thanks for that, it helped clear up a couple of things.

 

You mentioned that you want to output this signal to a DAQ device, in which case it may be easier to implement this existing code to output that pulse train:

 

https://decibel.ni.com/content/docs/DOC-5763

 

Otherwise you could just use a property node in your code to re-initialize your value to its default setting (which for boolean values is false) via an invoke node ( http://zone.ni.com/reference/en-XX/help/371361J-01/glang/invoke_node/ ) at the start of your loop.

Best regards,

Mark W
Applications Engineer
National Instruments UK & Ireland
Message 8 of 8
(6,625 Views)