Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

Count pulses of a generated pulse train signal

Hi,
I have a CompactDAQ system composed by a NI cDAQ-9172 usb chasis and a NI 9401 DIO card.
I want to simulate an encoder output signal, for what I generate two pulse train (A,B). In paralell I need to know the number of pulses I'm generating. I'm using Measurement Studio for Visual C++:
 
// Create a task and two channels for generating two pulse trains (using the two available counters of NI9401)

m_task = std::auto_ptr<CNiDAQmxTask>(

new CNiDAQmxTask());

m_task->COChannels.CreatePulseChannelFrequency(cDAQ1Mod5/ctr0, _T("channel1"), DAQmxCOPulseFrequencyUnitsHertz, DAQmxCOPulseIdleStateLow, 0.0, 1.0, 0.5);

m_task->COChannels.CreatePulseChannelFrequency(cDAQ1Mod5/ctr1, _T("channel2"), DAQmxCOPulseFrequencyUnitsHertz, DAQmxCOPulseIdleStateLow, 0.25, 1.0, 0.5);

m_task->Timing.ConfigureImplicit(

DAQmxSampleQuantityModeContinuousSamples, 1000);

// Create a timer

SetTimer(1, 5, NULL);

///////////////////////

...::OnTimer(..)

{

.....

// I want to count de pulses of the generated trains but this does not work, I obtain strange numbers..

unsigned int a,b;

a = m_task->COChannels[_T(

"channel1")].Count;

b = m_task->COChannels[_T(

"channel2")].Count;

}

m_task->Start();

0 Kudos
Message 1 of 6
(4,941 Views)

Hi Lei,

 

You arereading the value that is on the register of the counter but does do not work properly coz u dont now what was on that registry before...

There are 2 things u can do:

1. Why u do not create a finite number of pulses instead of a continous PWM? That is... u can indicate how many pulses u want to take out, and that's all.

2. If u still wanna do a continous pulse train output just use another free counter to count the edges of the first one,

 

Hope that helps,

 

Regards,

Jaime Cabrera

NI Applications Engineering Spain
0 Kudos
Message 2 of 6
(4,919 Views)
Hi Jaime,
Thanks for your reply!!
These are the problems I have with your proposals:
 
1.-Even if I generate a finite pulse train, I need to count the generated pulses. How could I count them? There should be a way because I've read that using a finite pulse train, the device uses two counters, one to generate the pulses and another to know the number of generated pulses ( in order to know when to stop generating ).
 
 
2.-To count the edges of the generated  pulse train, ¿do I have to wire physically the output to the input? ¿or is it possible to do a routing? I've tried to connect terminals : 

NI::CNiDAQmxSystem::ConnectTerminals(_T("/cDAQ1/Ctr0InternalOutput"),_T("/cDAQ1/Ctr1Source"));

But this gives me an execution error!!!
 
 
Besides as far as I know the cDAQ-9172 has two counters, so how can I generate two pulses and count one of them?
 
Another question: ¿Is it possible to change online the frequency of the generated pulse? or do I have to stop the task, change the frequency an re starta the task?
 
Thanks in Advance
 
Leire
0 Kudos
Message 3 of 6
(4,908 Views)

Hi Leire,

I believe there is no other chance that using another counter to verify that.

If you make the connection you can do it directly and u do not need to export the terminal u just need to say which terminal is your source for counter 1. Is not the export function, can u try this one:

int32 __CFUNC DAQmxSetCICountEdgesTerm(TaskHandle taskHandle, const char channel[], const char *data);

But do not insert "Ctr1/Out" say the PFI line (i dont know exactly for your device but u can look for it at documentation) for example "Dev1/PFI4". That should work.

You cannot change the frequency on the fly. You should stop the task and start a new one if u want  to do that.

You can use an analog input for counting edges if your pulse generation has not a high speed (high frequency) if you program it properly.

Hope that helps,

 

 

Regards,

Jaime Cabrera

NI Applications Engineering Spain
0 Kudos
Message 4 of 6
(4,902 Views)
Hi Jaime,
Perfect! I can read the number of generated pulses using the mentioned function. Thank you! Ha sido de mucha ayuda!
My problem is now that I need two train pulse generations and one edge counter, and the NI9172 has only two counters. However there is a freqout available for frequency generation (that could also be used as pulse generato) so I am able to generate two synchronized pulses and count one of them; but the frequency generation forces very high frequency and I don't see the way to apply the divisor... Is there any way to do it?
Moreover! Is there any other way to generate train pulses without using the counters? i.e. using digital outputs for waveform generation (correlated output)? Is somewhere an example?
 
Muchisimas gracias !!!
0 Kudos
Message 5 of 6
(4,897 Views)

Hola,

Puedes usar las salidas digitales, ya que se pueden clockear ahora ... eso sería una solución viable.

Mi pregunta es... te has planteado una tarjeta de contadores?

Busca algún ejemplo dentro de labview de Digital I/O con timing o sino busca alguno que ponga correlated I/O.

 

Saludos,

 

Regards,

Jaime Cabrera

NI Applications Engineering Spain
0 Kudos
Message 6 of 6
(4,776 Views)