LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

calculate time that PWM Signal is 0

Hello Community,

I have a problem that has been bothering me for a while.

It should not be so hard. But somehow I can't get it to work error free for a long time :

 

I have a PWM signal (300Hz, DutyCycle 0,1 - 0,9). This signal is captured by a cDAQ system.

Sample frequency and read sample can vary (but at least 5k samples per second).

This PWM signal is sometimes turned off (pulled to 0 or ground) for 0.1 sec to 3 sec.


I would like to calculate how long (in seconds) this signal is 0.


I would like to calculate this live. So while the data is being acquired.
If for 10 seconds the PWM was not 0 for more than 0.1 second, I would like to output -1.

I would like to calculate this for multiple signals at the same time.

 

My function (see attachment LV2014) calculates the PWM timeout mostly well.
But for longer measurements (for example 10h) I sometimes get wrong results ( for example 10,5 seconds PWM Low, in the PWM raw data there is no 10s PWM=0).

 

I hope my description was understandable.

 

It would be great if someone could find the error in my approach or has an idea for a better solution.
I really hope someone can help me with this.

0 Kudos
Message 1 of 7
(1,074 Views)

Hallo Held,

 


@M.Lichtenheld wrote:

I have a problem that has been bothering me for a while.

It should not be so hard. But somehow I can't get it to work error free for a long time :


It could help to provide an picture of a typical PWM signal and tohe timing you want to calculate indicated in that picture…

 


@M.Lichtenheld wrote:

I would like to calculate how long (in seconds) this signal is 0.


Count how many consecutive samples are "0", then multiply by dt…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 7
(1,069 Views)

Of course,

 

this is the my typical PWM Signal:

 

after 10 seconds there are 0.5s of 0.

After the 0.5s of 0 my Function should output "0,5".

 

If there are more then 11s of PWM my function should output "-1"(for no Low-Time detected).

30s.png

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

this could be a Waveform aquired from the cDAQ:

pwm then low.png

So at the end of this Waveform, we are at LOW. in the waveform aquired after get maybe we got PWM again. And then I could calculate the time with out PWM.

 

Hope this helps.

 

 

 

 

 

 

0 Kudos
Message 3 of 7
(1,033 Views)

Hi held,

 

as I mentioned before: count how many consecutive samples are low level/0.

I also recommend to convert your voltage analog signal into a boolean signal by using a simple comparison…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 7
(1,022 Views)

Thanks Gerd,

thats exactly what i do as first step.

See attached code.

 

The problem seems to occur later. Maybe when start of the low level and end of the low level are not in the same acquisition cycle.

0 Kudos
Message 5 of 7
(1,008 Views)

Hi held,

 


@M.Lichtenheld wrote:

The problem seems to occur later. Maybe when start of the low level and end of the low level are not in the same acquisition cycle.


Yes!

Maybe because of uninitialized shift register…

Maybe because of not storing/using information about last falling edge position from previous calls…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 6 of 7
(1,003 Views)

Thanks for your Input, Gerd.

I refactored that mess and ended up with that:

 

Lichtenheld_0-1638186707903.png

 

Lichtenheld_1-1638186745831.png

 

0 Kudos
Message 7 of 7
(972 Views)