11-24-2021 02:39 PM
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.
11-24-2021 03:16 PM
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…
11-25-2021 04:23 AM
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).
this could be a Waveform aquired from the cDAQ:
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.
11-25-2021 09:13 AM
11-25-2021 11:12 AM
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.
11-25-2021 12:38 PM
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…
11-29-2021 05:52 AM
Thanks for your Input, Gerd.
I refactored that mess and ended up with that: