11-29-2010 04:39 AM
Hello,
I'll start by saying that I am new to labview and it is possible that my question will be simple for most. As the topic I need to perform frequency divider by 2 and 3.
To digital input card will be given a signal of frequency 50Hz. I can use a USB card 6009 and 6221.
I found a few examples of the frequency dividers on the NI forum and on the internet but do not quite know how I could use them in my case...
For example, the divisor using JK flip-flop in attachments.
If anyone would be able to explain to me how it should look like in my case, or give some examples on the basis of whose ideas I will be able to understand the operation of such a program would be great.
Regards,
Mat M.
11-29-2010 11:42 AM
Hi Mat,
Assuming the signal is TTL, you can use a counter on the 6221 to generate a pulse after every N pulses of your external signal. Try starting with this example.
Best Regards,
12-03-2010 03:34 PM
Unfortunately, 2 & 3 are the *hard* divisors. Any divisor N >= 4 is relatively easy.
In fact, you *cannot* divide by 3 with counter hardware, and you can only sort of divide by 2 by using the technique John P linked to. I say "sort of" because a 50 Hz square wave will not be turned into a 25 Hz square wave. It will instead be turned into a 25 Hz pulse train with an extremely low duty cycle. Such a division is fine if you only need to control the timing of one of the edges of the divided signal, but not if you need to control both.
Here's the only trick I've thought of for divide by 3: set up a continuous analog output task and fill the buffer with alternating sets of 3 samples at 0.0 volts followed by 3 at 5.0 volts. Use the external pulse train as an external sample clock. And hope that the analog output makes clean enough edges in its pulse train to drive whatever needs to respond to the divided clock. (Same idea could be used to make a divide-by-2 square wave).
-Kevin P
12-06-2010 12:40 PM - edited 12-06-2010 12:41 PM
Kevin is absolutely correct that the signal resulting from the method I linked earlier would have an extremely low duty cycle. You can use this method to "divide" by 2, 3, or any other positive integer (other than 1), but like Kevin mentioned the resulting signal is a pulse every N ticks, rather than a true division of the input clock.
You can use Kevin's method to divide by 2 and give a 50% duty cycle using either AO or DO with an external sample clock. However, the waveform to generate would be [1, 0, 1, 0 ...], giving 1 period of output signal for every 2 clock edges. You can't use this method to give a 50% duty cycle and divide by 3, but you can get either a 33% or 67% duty cycle by generating [1, 0, 0, 1, 0, 0 ... ] or [1, 1, 0, 1, 1, 0 ... ] respectively. Generating [1, 1, 1, 0, 0, 0 ... ] is actually a divide-by-6. Any odd number divisor would not give you a 50% duty cycle.
There is a way to divide by an odd number and maintain a 50% duty cycle, but only if your input signal is also a 50% duty cycle square wave. Unless you absolutely need to have a 50% duty cycle then it's probably more trouble than it's worth:
1. Configure a DI task with Change Detection Timing. This can be used to generate a pulse (Change Detection Event) on every rising and falling edge of your external signal, effectively multiplying it by 2.
2. Use the Change Detection Event as the sample clock for your DO (or AO) task. The task would output [1, 1, 1, 0, 0, 0 ... ] for a divide-by-3 of the original signal.
Like Kevin mentioned, any divisor >4 is easy using the counters in their default "toggle" mode, but the duty cycle would not be 50% for odd divisors (similar to the DO/AO method). If you only care about one edge of the clock and the duty cycle is not terribly important, the Pulse Mode example that I linked in my last post can be used for any divisor between 2 and 2^N-1 on an N-bit counter.
Best Regards,
12-21-2010 06:11 AM
Hi,
Thank you very much for the reply but because I am a new to LabView I must ask for further information:
1. For example, given by John P I would make sure to set the correct parameters of input terminal.
2. To example of signal division by 3 I would ask for your example made in LabView, because the given information are not enough for me.
Best Regards,
Mat M.
12-27-2010 05:27 PM
Hi Matt,
Sorry for the delay, I've been on vacation for the holidays.
In Pulse Mode, when the counter alternates between low and high registers, it will pulse instead of toggle. So, if you have 2 ticks high and 2 ticks low, you will get a pulse every 2 edges of your input signal. If you change this to 3 ticks high 3 ticks low, you will get a pulse every 3 input edges.
So, all you need to do is change the following number to be whatever you want--the counter will generate a pulse after this many edges of your input signal occur:
If the pulse is too short for your requirements, you should implement Kevin's suggestion of using a DO task.
Best Regards,