Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

Setup continuous counter?

I am trying to create a task that continuously measures the period of a signal.

here is the error:
NationalInstruments.DAQmx.DaqException: Data was overwritten before it could be read by the system.

If Data Transfer Mechanism is Interrupts, try using DMA. Otherwise, divide the input signal before taking the measurement.

Task Name: Measure Period

Status Code: -200141
at cC.c()
at dQ.a()
at bz.EndReadMultiSampleDouble(IAsyncResult asyncResult)
at NationalInstruments.DAQmx.CounterReader.EndReadMultiSampleDouble(IAsyncResult asyncResult)

and here is the code I am using to set it up:

public PacketDecoderRM_PW()
{
startTime = DateTime.Now;

Console.WriteLine (startTime);
try
{
myTask = new Task("Measure Period");

myTask.CIChannels.CreatePeriodChannel("Dev1/ctr0",
"rx input",
10E-06,
400E-06,
CIPeriodStartingEdge.Rising,
CIPeriodMeasurementMethod.LowFrequencyOneCounter,
0.00099999999999988987,
4,
CIPeriodUnits.Seconds);

myTask.Timing.ConfigureImplicit(SampleQuantityMode.ContinuousSamples);

myTask.Control(TaskAction.Verify);

myCounterReader = new CounterReader(myTask.Stream);

MyAsyncCallback = new AsyncCallback(processSamplesCallback);

myCounterReader.BeginReadMultiSampleDouble(10000, MyAsyncCallback, null);
TaskRunning = true;

}
catch(Exception ex)
{
myTask.Dispose();
Console.WriteLine(ex.ToString());
TaskRunning = false;
}
}




and the callback:

public void processSamplesCallback(IAsyncResult ar)
{
try
{
double[] Data = myCounterReader.EndReadMultiSampleDouble(ar);

for(int i=0;i < Data.Length; i++)
{

switch (pulseDecoderState)
{
case 0: // detecting SOF
if (classifyPulse(Data[i]) == 5)
pulseDecoderState = 1; // found a start pulse so advace the state to look for sync
break;

case 1: // detect SYNC
detectSync(Data[i]);
break ;

case 2: // decoding DATA
decodeData(Data[i]);
break ;
default:
// Should not reach here so reset if we do!
resetDecoder() ;
break ;
}
}
// continue to acquire and increment the cycle number
myCounterReader.BeginReadMultiSampleDouble(10000, MyAsyncCallback, null);

}
catch(Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
0 Kudos
Message 1 of 7
(4,711 Views)
Hi Bryan:

We actually have an example that does continuous buffered period measurements off a counter on your board.

To access this example look in this path:
C:\Program Files\National Instruments\NI-DAQ\Examples\DAQmx ANSI C\Counter\Measure Period or Pulse Width

The example that you need is called: Dig Periods-Buff-Cont-High Freq 2 Ctr

Let me know if this doesnt work for you.
0 Kudos
Message 2 of 7
(4,686 Views)
The high freq counter gives an error message that my signal is too slow. Basically what I am trying to do is decode a signal from an FSK board that outputs very random noise when no signal is being transmitted, then when a signal comes through, it is preceded by 3 charge pulses to condition the data slicing filter capacitors, after this a 150uS high and 150uS low come through followed by a train of high 50uS and low 50uS then data which can be different sizes. So I measure the period of these pulses and decode accordingly. The period sizes of the signal are basically sizes: 300uSec, 200uSec, 150uSec, and 100uSec. The receiver that I am trying to simulate uses a 1MHz time base to successfully capture all the pulses.


1. I can generate the singal by itself and am able to decode using the low freq counter, but when I introduce the fsk board I get a buffer overrun.

2. I use the fsk board and a large range counter, and the values that I recieve from the counter are not correct.


thanks,
BT
0 Kudos
Message 3 of 7
(4,681 Views)
a 1Mhz clock rate would be sufficient for my application, but the internal clock runs at 80mhz, 20mhz and 200k...
0 Kudos
Message 4 of 7
(4,677 Views)
Hello Bryan,

1) In your Low Frequency One Counter code, it looks like you specify 10E-06 and 400E-06 as your min and max values that you expect to read. Does the noise being output by the FSK board fall into this range?
2) Increasing the number of samples to read can sometimes alleviate buffer overflow issues. Does increasing the number of samples to read affect how long it takes to receive the buffer overflow error?

Take care,
E.Lee
Eric
DE For Life!
0 Kudos
Message 5 of 7
(4,660 Views)
Its hard to characterize the noise that comes out of it. I do believe its in the range of of 1us - 400us though. I still get an overflow if I increase the number of samples to 1000, or 10,000.
0 Kudos
Message 6 of 7
(4,657 Views)
Hello Bryan,

1) Does the high frequency 2 ctr example give you an error even when you are using the FSK board?
2) Does the large range 2 ctr example give you incorrect readings for all frequncies or just the high (or low) frequencies?

If the low frequency ctr is too slow and the high frequency ctr is too fast and the large range ctr can't accomodate all your signals, the only solution might be to input the signal on one of your analog input lines and decode the period in post-processing.

Take care,
E.Lee
Eric
DE For Life!
0 Kudos
Message 7 of 7
(4,639 Views)