From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

PWM Rise/Fall detection

Solved!
Go to solution

Hi,

 

i'm programing a PWM read from a DI in an FPGA (NI 9425), this card doesn't accept fpga methods, so i need to figure out a way to detect when does it rise/fall, so with a sequence structure i can check the tick in wich this rise/fall ocurred and calculate the length of the high and low from the PWM...

 

Any ideas? I've been thinking all day, out of ideas right now...

 

Thanks!

Joan

 

PD: attached is the structure i have, next to the DI i need to place the rise/fall detector

0 Kudos
Message 1 of 6
(3,763 Views)

Hey Joan,

 

Here's a quick example of an edge detector:

 

Edge Detector.png

 

For a more complete example (does pretty much exactly what your app is doing), please check out the PWM Input example in the NI LabVIEW Example Finder. In case you're not familiar, the Example Finder can be found under Help->Find Examples. From there, navigate to Toolkits and Modules->FPGA->CompactRIO->FPGA Fundamentals->Counters->PWM Input

Cheers!

TJ G
Message 2 of 6
(3,747 Views)

Hi TJ G,

 

nice! Thanks!

 

How could i do it, to stop the tick count just in the rise/fall? I mean, to make the sequence wait until the rise/fall, then advance (pick tick count value) and then wait till the next one... there is no "wait" function in FPGA, isn't it?

0 Kudos
Message 3 of 6
(3,731 Views)

You can set a boolean flag whenever you get a rising or falling edge and use a case structure that will only run when the flag is set. After you run your code in the event sturcture, clear the flag and carry on waiting for the next edge. You do not want to stall your FPGA code, just keep checking the flag on each clock cycle. 

0 Kudos
Message 4 of 6
(3,726 Views)
Solution
Accepted by topic author joanci

It looks like you probably want code that functions more like the example I pointed out. It measures the amount of high time, and the amount of low time for a given period. Is this what you want to do?

 

PWM Example.PNG

Cheers!

TJ G
Message 5 of 6
(3,717 Views)

Wow! That looks great! Thank you very much!

0 Kudos
Message 6 of 6
(3,709 Views)