06-14-2010 06:08 AM
Hello,
i'm using a counter/timer PXI-6624 in Visual Studio C++ with Meassurment Studio.
i want to count edges on a signal within a high period of a gate signal.
in the dokumentation i found the inputs "CTR n SRC", "CTR n GATE" and "CTR n AUX".
my idea is simply configure the counter 0 to count edges on SRC by gating via GATE.
may be there is a example for my problem in the ni installation, but mostly i don't understand the abtract description.
to find the right example, you have to know the name of the function you want to use.
can somebody tell me the right examplename for my problem?
which configuration call i have to use?
a little less important as my first problem is a similar one.
i want to count edges on a signal between a start trigger and a stop trigger.
SRC -> signal
GATE -> start signal
AUX -> stop signal
i found a way to count the edges of the intern clock between start and stop (2 Edge Seperation), but no for a extern signal.
can somebody help me with this? especially with the first one.
B
Solved! Go to Solution.
06-14-2010 10:09 PM
Hi Borris,
To count the number of events during a the high period of a gate signal, you would need to configure a Pulse Width Measurement. There should be a Visual Studio C++ example to do this that is installed with the DAQmx Driver--mine was installed here:
C:\Users\Public\Documents\National Instruments\NI-DAQ\Examples\MStudioVC2008\Counter\Measure Period or Pulse Width
By default this will measure the period of your gate signal in terms of seconds (computed by counting the number of ticks of the known internal timebase). To get the behavior you need, the following two changes should be implemented:
1. Line 206 of MeasPulseWidthDlg.cpp: Change DAQmxCIPulseWidthUnitsSeconds to DAQmxCIPulseWidthUnitsTicks
2. Specify the source of the timebase to be an external timebase, set the CIChannel.CounterTimebaseSource Property to the desired PFI line
This will now return the data in terms of ticks of the external signal rather than in terms of the internal timebase. If you want the code to run continuously and return data for multiple pulses of your gate signal, you should configure Implicit Timing. This will latch all of the data into a buffer and will not need to re-arm the counter (which would give the risk of missing periods). The MeasBuffered_SemiPeriodFinite example shows how to configure Implicit Timing.
As for your second question, the same procedure above applies but for the 2 Edge Separation task instead of a Pulse Width task.
Best Regards,
06-16-2010 03:40 AM
Hi John,
thank you for your help. this works fine.
i had some problems in finding out how the timebaseSource must be implemented.
finally i found the solution.
for everybody who don't want to search long time for code, here is it:
// Create the task CNiDAQmxTask m_task("CITask"); //Create the counter input channel m_task.CIChannels.CreatePulseWidthChannel("PXI1Slot16/ctr0", "", atof(minimum), atof(maximum), startingEdge, DAQmxCIPulseWidthUnitsTicks); //Extract the Channel for edit
CNiDAQmxCIChannel chan = m_task.CIChannels.GetAll();
//Set the GATE-Signal chan.SetPulseWidthTerminal("/PXI1Slot16/PFI38");
//Set the Signal to counton SOURCE chan.CounterTimebaseSource = "/PXI1Slot16/PFI39"; CNiDAQmxCounterReader myCounterReader(m_task.Stream); double measuredWidth = myCounterReader.ReadSingleSampleDouble();
thank you and bye
B
06-16-2010 04:05 AM
and here is the same in ANSI C:
/*********************************************/ // DAQmx Configure Code /*********************************************/ DAQmxErrChk (DAQmxCreateTask("GatedEdgeCount",&taskHandle)); DAQmxErrChk (DAQmxCreateCIPulseWidthChan(taskHandle,"PXI1Slot16/ctr0", "cheese",0.000000100,0.830000000, DAQmx_Val_Ticks,DAQmx_Val_Rising,"")); DAQmxErrChk (DAQmxSetCIPulseWidthTerm(taskHandle,"cheese", "/PXI1Slot16/PFI38")); DAQmxErrChk (DAQmxSetCICtrTimebaseSrc(taskHandle,"cheese", "/PXI1Slot16/PFI39")); /*********************************************/ // DAQmx Start Code /*********************************************/ DAQmxErrChk (DAQmxStartTask(taskHandle)); /*********************************************/ // DAQmx Read Code /*********************************************/ DAQmxErrChk (DAQmxReadCounterScalarF64(taskHandle,10.0,&data[0],0));
05-12-2014 05:51 AM
Hi all .
Following comments I have a Question.
For example, I use my Source with a External Counter, and I need Count The External Counter while the Gate is High .
What Happen if the Source don't will push any Pulse? I need that if the Counter don't do any pulse the Ni Count 0 ticks, now is waiting to the source.
Thanks a lot. 🙂