From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

Keeping generated pulses in sync with an external clock

Solved!
Go to solution

I am using a PCI-6602 card with Windows 7 and the ANSI C library.

 

I need a continous 100 HZ output to remain in sync with an external 1 HZ clock.

I started with the example at http://www.ni.com/example/27415/en/

If I send 99 pulses out I can retrigger each second without a problem

If I send 100 pulses out the next retrigger is missed and pulses go out every other second.

I there a way to get around this?

 

 

    TaskHandle  taskHandle=0;
    char *      chan           = "Dev1/ctr0";
    float64     duty           = 0.5;
    float64     freq           = 100;
    uInt32      idle           = DAQmx_Val_Low;
    float64     initDelay      = 0.0;
    uInt32      edge           = DAQmx_Val_Rising;
    char        *triggerSource = "/Dev1/PFI19";
    uInt32      numSamples     = 100; 

    DAQmxCreateTask("",&taskHandle);
    DAQmxCreateCOPulseChanFreq(taskHandle,chan,"",DAQmx_Val_Hz,idle,initDelay,freq,duty);
    DAQmxCfgDigEdgeStartTrig(taskHandle,triggerSource,edge);
    DAQmxCfgImplicitTiming(taskHandle,DAQmx_Val_FiniteSamps ,numSamples);
    DAQmxSetStartTrigRetriggerable(taskHandle, 1);
    DAQmxStartTask(taskHandle);

 

0 Kudos
Message 1 of 5
(4,629 Views)
Solution
Accepted by topic author TomMessick

Some devil's advocate questions, because your timing is ever so slightly over-constrained:

 

- how crucial is it to generate at exactly 100 Hz?  What if you generated at, say, 100.01 Hz?  That tiny little timing cheat might give the board time enough to rearm and retrigger every 1 second.

- how certain are you that the external signal is a rock solid 1.000000 Hz?   If it can vary a little bit relative to your board, you won't be able to know in advance what time window you need to fit your 100 pulses into

- supposing the external signal is a perfect 1.000000 Hz and that you need to generate at (what your board thinks is) a perfect 100.0000 Hz, can you live with generating 99 pulses instead of 100?

- how do you plan to deal with the slight discrepancy that's almost certain to exist between the external signal's idea of 1.00000 sec and your board oscillator's idea of 1.00000 sec?   As I recall, the 6602 is rated at something like 50 parts per million timing accuracy, give or take a little temperature based variability

 

Otherwise, no specific magic answers.  If really stuck, I have an inkling or two about getting something done with multiple counters working together but haven't thought through details enough to be confident in feasibility.

 

 

-Kevin P

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
0 Kudos
Message 2 of 5
(4,620 Views)

Yes, I know this problem.

As kevin said, you need to make sure your 100 pulses always take less than yoiur minimum period, otherwise you skip next pulse.

The only solution I found is to reduce each pulse duration 

With high precision it is easier to setup not frequency, but high and low time of the pulses.

With 6602 you can change duration of each pulse low time in 12.5 ns steps. So 100 pulses duration will change in 1.25 us steps. One more problem is all of your pulses low time will be 12.5 ns smaller - tiny deviation from required 10 ms and all pulses the same. For the last pulse change will be 100 times larger, sometimes it can be a problem.

0 Kudos
Message 3 of 5
(4,591 Views)

I did some testing and it works with a frequency of 100.00001 HZ.  Backing off to 100.01 HZ is safe and is good enough for the guys who are going to be using this.  The source of the 1 HZ has been verified as better than 1 microsecond accuracy.  Since we are retriggering every second the drift between the 6602 and the 1 HZ won't cause problems during our tests, which can run for several days.

 

--

tom

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

Keep in mind, that last pulse will be 99 Hz to compensate for 99 pulses at 100.01 Hz.

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