DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I count pulses in a channel?

Solved!
Go to solution

Hello,

 

I have a channel consisting of 0's and 1's (data is from a proximity sensor) and was wondering if there is an easy way to count the events (i.e. pulses) in DIAdem (Advanced)? At its simplest, I just need a method to count the number of rising edges in the channel.

 

Would a script be the way to do this? If so, is there any example code around demonstrating how to scan rows in a channel?

 

Thanks,

 

PorridgeMan.

0 Kudos
Message 1 of 5
(5,833 Views)

Hello PorridgeMan,

 

i prefer a combination like this:

 

Call ChnDifferentiate("[1]/time","[1]/Pulses","/DifferentiatedX","/DifferentiatedY") '... XW,Y,E,E
Call ChnCalculate("Ch(""[1]/boolean"")=abs(Ch(""[1]/DifferentiatedY"") > 10)") '... FormulaTxt
call msgboxdisp(cch("[1]/boolean",4)) 'getting the sum

 

I think it´s pretty easy

 

MS_DC

0 Kudos
Message 2 of 5
(5,830 Views)
Solution
Accepted by PorridgeMan

Hello!

 

@Martin: IMHO your aproach can work but must not because of the input data and the right compare value (10 in your case).

If the input data is not a pure 0-1 step you can get more the one value higher than 10 for one rising edge.

The compare value depends on the time distance and the channel values and it is not easy to calculate it in advance.
The other disadvantage I see is that you need a X channel, wich is not realy necessary to solve the problem.

I think my code will be more robust (IMHO as I mentioned).

 

@PorridgeMan: Yes, it's a shame that it still need some steps in DIAdem to solve this common problem.

First: To do it by script is possible but in general to slow. My aproach is to insert one 0 value at the beginning

of a copy of the input channel and compare this to the input channel. If one value is below 0.5 (the half of the maximum of you values) 

and the other is higher I set a 1 otherwise 0 in a result channel. Even in more complicated cases the compare value could

be calculated or exchanged by an moving average value.

 

Here is the code:

Option Explicit

' Copy data
Call ChnCalculate("Ch(""[1]/Dif"")=Ch(""[1]/Pulses"")")
' Insert one 0 at the beginning
Call DataBlInsertVal("[1]/Dif",1,1,0,0)
' Compare and convert result to 1 or 0
Call ChnCalculate("Ch(""[1]/Result"") = IIf((Ch(""[1]/Pulses"") < 0.5) And (Ch(""[1]/Dif"") > 0.5), 1, 0)")
' Sum is result
Call MsgBox(Cch("[1]/Result",4))

 

 

Hope this helps

 

Matthias

Matthias Alleweldt
Project Engineer / Projektingenieur
Twigeater?  
Message 3 of 5
(5,813 Views)

Hi PorridgeMan,

 

In case what you're really after is converting your tachometer pulses to an RPMs channel or an angular velocity channel, here's a script that will do that.

 

You might also check out the following example application that this functionality was pulled out of:

 

http://zone.ni.com/devzone/cda/tut/p/id/3549

 

Brad Turpin
DIAdem Product Support Engineer
National Instruments

0 Kudos
Message 4 of 5
(5,795 Views)

Hi TwigEater,

 

Thankyou, your method was what I was after.  I humbly suggest inserting a 1 rather than a 0 into the first row of the copied channel, to avoid creating a fictional rising edge when the first value in the original channel is a 1. Viz:

 

' Copy digital channel to another to allow comparison between current and previous values.

Call ChnCalculate("Ch(""[1]/Previous Bit Values"")=Ch(""[1]/Bit Values"")")

' Insert one 1 at the beginning

Call DataBlInsertVal("[1]/Previous Bit Values",1,1,1,0)

' Compare and convert result to 1 or 0

Call ChnCalculate("Ch(""[1]/Rising Edges"") = IIf((Ch(""[1]/Bit Values"") = 1) And (Ch(""[1]/Previous Bit Values"") = 0), 1, 0)")

' Display the sum of detected rising edges in a message box.

Call MsgBox("The number of rising edges detected is: " & Cch("[1]/Rising Edges",4) & ".",vbOKOnly)

 

Thankyou everyone for your input. Much appreciated,

 

PorridgeMan. 

Message 5 of 5
(5,771 Views)