LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

better way to calculate speed of Motor using pulses

Hi,

 

I have been trying to calculate the frequency of a flywheel that is being controlled by an electric motor using counter on USB 6008, but I dont seem to get the feedback match the desired frequency. Although, it is partly the design's fault because the encoder PPR on the flywheel is 6.

 

Attached is the setup. and main vi and the pulse counter subvi. (Vis are not pretty to look at and are at test phases Smiley Wink)

 

What I am trying to do is supply an analog voltage to the electric motor between 0-5V which corresponds to 0-100Hz of the electric motor. This turns the hydraulic flywheel and I have a fiber optic transmitter and receiver that gives pulse output. I count this over 250 ms using edge detection on counter and calculate frequency. My error is quite unacceptable but as I increase the loop that counts to around 500ms, it becomes better. I would really appreciate it if someone could help me out here.

 

V Thanks 🙂

I may not be perfect, but I'm all I got!
Download All
0 Kudos
Message 1 of 10
(5,184 Views)

I more accurate way would be to set up your counter input as a Frequency task - that way you will be using the DAQ device's hardware timers instead of the Windows clock. The value you get back will probably be pulses/second (depending on how you set up your frequency task) which can then be simply converted to your desired unit using your scaling factor.

0 Kudos
Message 2 of 10
(5,166 Views)

Thank you for your reply shew82 🙂

 

Currently, I am using USB 6008 which doesnot have a hardware clock. So, I have to rely on the windows clock. Also, if you wouldn't mind showing me how to setup the frequency part of the counter to count pulse train, I would be grateful. Thanks

 

V

I may not be perfect, but I'm all I got!
0 Kudos
Message 3 of 10
(5,163 Views)

I didnt know the 6008 did not have a clock, and in that case this code probably won't work (I cant simulate a 6008 either). However, in general, a DAQmx counter input can be used to measure the frequency of a pulse train a little like this:

 

17985iD2AB9B351C26C377

0 Kudos
Message 4 of 10
(5,158 Views)

bump!

I may not be perfect, but I'm all I got!
0 Kudos
Message 5 of 10
(5,130 Views)

Hi Veejay,

 

Certainly USB-6008 only allows you to count edges, so you are on the right track to measure the time difference between each rising edge of the signal.  If you are interested in a slightly different approach, there is an KnowledgeBase which discusses how to measure the period between rising edges.  Linked at the bottom of this article is an example which implements this.  However the example uses shift registers to keep the last value from each iteration.  In your case, you are not holding the last value of the tick count, so your time difference values may be off.

 

Hope this helps!

Tejinder Gill
National Instruments
Applications Engineer
Visit ni.com/gettingstarted for step-by-step help in setting up your system.
0 Kudos
Message 6 of 10
(5,121 Views)

thank you Tejandar... I understand the example you directed me toward. But, could you show me what I am doing wrong in my program? There are two loops nested. Which loops should have the shift register? Thanks!

 

V

I may not be perfect, but I'm all I got!
0 Kudos
Message 7 of 10
(5,115 Views)

Hi Veejay,

 

I rarely suggest not using a SubVI, but in this case, it might be a good idea.  The counting that you are doing would make more sense in the top level while loop.  And if you were to move that code to the top level, the only thing left in your subVI is a DAQmx read. 

 

Also, because your data is pulled from the buffer each time your DAQmx VI is called, you could have an uneven rate because sometimes your SubVI could iterate multiple times and sometimes it will end right away depending on the value of the tick count and only get called once you've gone through a full iteration of your top level loop.

 

So in this particular case, I would personally get rid of the subVI and place the shift register in the top level.

Tejinder Gill
National Instruments
Applications Engineer
Visit ni.com/gettingstarted for step-by-step help in setting up your system.
0 Kudos
Message 8 of 10
(5,065 Views)

I get what you sayTejinder, except the part about placing shift registers. Do you mean shift registers for the time or something else? Thank!

 

V

I may not be perfect, but I'm all I got!
0 Kudos
Message 9 of 10
(5,036 Views)

Yes, if you see the example that I linked earlier you can see that it uses a shift register to keep the last value of the timestamp until the next rising edge occurs. When the next rising edge occurs we take another timestamp inside the loop and compare it with what comes out of the shift register.  This gives us the amount of time between each rising edge.

 

Upon second look of your code, I don't think you are doing that. In your SubVI, you call the Tick count, and simply subtracting 250 from it.  That is not giving you the period between rising edges.  You may want to look at the example above as a starting point.

Tejinder Gill
National Instruments
Applications Engineer
Visit ni.com/gettingstarted for step-by-step help in setting up your system.
0 Kudos
Message 10 of 10
(5,009 Views)