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.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

11 bit counter

Hi everyone, i am trying to generate a vi to count the number of pulses in a certain square wave (which i get after some processing) for a project. After i get the square wave i hooked it up to a 11 bit binary counter which i made and it counts the pulses correctly until like 7 hz but if i increase the frequency to say 10 hz the counter fails to count. I have spent all day but couldnt figure it out. I have attached the main circuit and sub vi's. So any thoughts anyone???

 

 

P.S I found the synchronous counter file online and used the jk flip flop inside it in the main circuit (8th.vi)

Download All
0 Kudos
Message 1 of 8
(3,120 Views)

Sorry forgot one sub vi. 

0 Kudos
Message 2 of 8
(3,119 Views)

You're missing another subVI: FF_JK.vi, and a subVI of the synchronous counter as well.  But this looks way too complicated for what you want to do, and the subVIs are a mess.  What are you actually trying to do here?  Why use all the complicated sloppy boolean logic when you just need a 16-bit integer for your counter?  (To make it an 11-bit counter, just mask off the high 5 bits.)  Why are you starting with a simulated sine wave if you're just going to convert it to a square wave?  There's no need for most of the code there if you just want to count pulses.

0 Kudos
Message 3 of 8
(3,108 Views)

Actually I have no idea what this whole circuit is for. It was revealed to me in steps like simulate a sine signal and den make a trigger which triggers at these points den differentiate it and use a halfway rectifier to get the top part so on and so forth lastly he told me to take the output of the flip flop and put it in a function generator so that the output is a series of square pulses when the flip flop output is 1 and it becomes 0 when the floppily out put is zero. Then I was supposed to hook it to a binary counter n count the pulses which are generated when the flip flop is 1 and den get a D to A converter which takes in 11 bits and gives out a step signal. (I am an underpaid slave basically ). So I did n the counter works but only till 7 Hz's if the frequency of the generator is increased it doesn't work. So I was hoping someone could help me figure it out and may be give me an hint about the D to A converter as well perhaps and I know its lame but I gotta do what the boss says. 

 

I have attached all the vi s again. The synchronus counter is a lib so i think it doesnt require a sub vi but i think i removed the ff_jk vi. so please take a look and help me out if possible

Download All
0 Kudos
Message 4 of 8
(3,090 Views)

Please, clean up your block diagram before posting.  You have wires running all over the place.  If you can't be bothered to clean it up yourself, use the block diagram cleanup feature (the broom icon in the toolbar).

 

I think I understand why your code doesn't work as you expect above 10hz, and it suggests that you don't really understand what you're doing here.  You generate 100 points of a sine wave at a time, but then you feed that to the Derivative PtbyPt VI.  (Side note: yet another reason to dislike and avoid the dynamic data type.)  Questions for you to think about: How many data points does the Derivative PtbyPt VI analyze?  How many points does it output?  What's happening to most of the sine wave data?

0 Kudos
Message 5 of 8
(3,077 Views)

I am really sorry about the wires all over the place as u might have noticed ia m really new to labview just started using it since last week. Anyways i checked out your advice, it turns out that was an unknown problem, thank you so much for pointing that out, but the actually problem you see comes at the square wave generator connected to the function generator graph. In that square wave generator if i increase the frequnecy above 10 the counter in the last part of the circuit ( the led's in the front panel ) stops counting. My worry is that it might be due to the fact that the drop and rise time between the square pulses may decrease to a level such that the flip flops inside the counter dont function but again i am not sure that if this is the problem or not?

 

Again really sorry about the messy wires and codes. Reattached a cleaner vi. Thanks so much for your help. 

0 Kudos
Message 6 of 8
(3,050 Views)

The other thing I noticed is that you are trying to analyze multiple data points, but your flip-flop only handles 1 point.  I think what you really want to do here is put the flip-flops into a for loop.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 7 of 8
(3,039 Views)

You still have exactly the same problem, you've just pushed it further down the line by using index array.  However, the more I think about it and look at your code, the more I realize how broken the entire approach is.  You might want to start over.

 

Think about what you're doing here.

1) Generate a sine wave

2) Clip the sine wave, giving you a square wave in which all values are either 1 or 0.

3) Take the derivative at each point.  Since every point in the signal is either 1 or 0, the derivative will always be either 0, 0.5, or -0.5 (with the default derivate options).

4) Again clip the signal, returning an array in which all elements are either 0 or 0.5.

5) Take just the first element of the array and check if it's close to 0 (which is odd since it will either be exactly 0, or 0.5).

6) Do some sort of complicated boolean logic with that "approximately 0" result.

7) Convert the boolean output to a 1 or a 0.  Use that as the amplitude for a square wave.

😎 Generate 2 points in a square wave with an amplitude of either 1 or 0, discard the second point and feed the first point into a series of flip-flops.

 

Does this make any sense to you?  What's all the boolean logic in step 6 for?  Why are you using that as the square wave amplitude?  Are you sure this is what your "boss" wants?  What is the actual goal?

0 Kudos
Message 8 of 8
(3,035 Views)