Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

How to Immediately Change Counter Output Rate?

I have a piece of code that largely works like this example: http://zone.ni.com/devzone/cda/epd/p/id/5493

 

In other words, I set up the Counter Output with some initial frequency and duty cycle, but then during the main loop of my program I continuously change the frequency to a new value based on other criteria.

 

I'm using an M-series PXI card and LabVIEW RT.

 

The problem I'm having is that the card waits for the next edge before changing the counter output rate. For instance, lets say it is going at a low frequency and I am upping to a high frequency. If the command arrives in the middle of the current pulse, it will wait to complete the low-rate pulse before starting the high frequency output. Is there a way to make it interrupt the current count and immediately start counting at the new rate?

 

Thanks,

Isaac

0 Kudos
Message 1 of 4
(4,819 Views)

Hi Isaac,

 

Using the Counter Output you will have to wait until the pulse is finished generating before updating the output.  I'm not sure what the desired behavior should be if you wanted to change frequency mid cycle, wouldn't this also affect the duty cycle for that first period?

 

If the frequencies are low (which I'm assuming is the issue), you can probably get faster update times by using the Correlated Digital I/O with Regeneration disabled.  The idea is that you can write arbitrary digital data on-the-fly to your DAQ device.  This is only going to give a faster update at low frequencies--the digital output buffer must be large enough so that it always has samples available (it would be written to in a loop).

 

Which M series are you using and what rates do you need to generate? 

 

You might want to take a look at this example code to see how you might implement adjustable frequency and duty cycle with digital I/O lines.  You can choose to assert the "Reset" line whenever a value has changed so the new pulse will immediately generate on the next loop iteration.

 

 

Best Regards,

John

John Passiak
0 Kudos
Message 2 of 4
(4,794 Views)

John,

 

Thanks for the response. I have LabVIEW 8.6, and I am having trouble opening the documents from your link. They say that I need LabVIEW 9.0. Is there a way around this?

 

I'm using a duty cycle of 0.1 in all cases, so most of one pulse cylce is spent 'off.' What I want is, if the command to change to a higher frequency arrives in the middle of the low portion of the cycle, that low portion is interrupted (a pulse immediately occurs) rather than waiting for the end of it.

 

The example you posted uses digital output rather than the counter. What are the limitations of this? For instance, what is the maximum frequency I could run the digital line at? If digital lines can be used in this way to mock up a counter output with better control, why would I ever want to use the counter itself?

 

Thanks,

Isaac

0 Kudos
Message 3 of 4
(4,785 Views)

Hi Isaac,

 

I posted the code in LV 8.2 so you should be able to open it now (it sometimes takes several minutes to upload).

 

There are a few limitations to using the digital lines instead of the counters:

1.  The digital lines are updated off of a sample clock which will be much slower than a timebase.  For example, on the 6221 the maximum update rate is 1 MHz, while the counter output has a max timebase of 80 MHz. As a result, the number of frequencies you can generate are going to be more restricted (divide down from 1 MHz vs. 80 MHz).

 

2.  On M series devices, the digital lines must be clocked from an external source.  This could be generated from a counter

 

3.  You have to build the digital waveform, which is a bit tricky (I think the example code should help out with that but I haven't had time to thoroughly test it).

 

4.  If you are generating digital lines at fast rates, you will need to write quite a few samples at a time to the output buffer to ensure the data does not underflow.  If the buffer includes multiple periods of the digital signal, you would have the case that using the counter output would still update more immediately.

 

Again, to determine the best course of action it would be useful to know what frequencies you want to generate and which exact hardware you are using. I just mentioned the digital lines as an alternative to the counters, but it might not be ideal for your situation.

 

 

-John

John Passiak
Message 4 of 4
(4,781 Views)