Jump to content

As of July 17, 2015, the LabJack forums here at forums.labjack.com are shut down. New registrations, topics, and replies are disabled. All forums are in a read-only state for archive purposes.

Please visit our current forums at labjack.com/forums to view and make new posts. To post on the current forums, use your labjack.com login account. Your old LabJack forums login credentials have been retired. There are no longer separate logins for labjack.com and LabJack forums.


Photo

U3 quadrature mode


  • Please log in to reply
10 replies to this topic

#1 TonyF

TonyF
  • Members
  • 16 posts

Posted 20 May 2013 - 02:36 AM

I have been using U3-LV 1.30 Lab Jacks for some years with my own Delphi software to measure the output of pressure sensors in query/response mode. Now I want to measure RPM and direction of an impeller. The movement signals will come from two opto pickups and a slotted disc. Shaft frequency of interest will be around 2 to 100 Hz but the disc will have multiple segments so the signal frequency will be 20 to 1000 Hz or higher depending on number of segments, yet to be determined. Resolution and accuracy requirements are not very severe, 0.1 to 0.5% being OK. In addition to RPM I need shaft direction. I am not interested in following the acceleration of the shaft as it changes speed, measurements will be done when the shaft is up to speed and will be averaged over a period of between 1 to 3 secs. to remove the influence of flow turbulence induced RPM noise on the signal. Impeller inertia will also help remove this noise but the existing pressure measurements are averaged over this period and it makes sense to read and average the RPM data at the same time. My initial plan was to use a counter for the RPM, which implicitly averages over the sampling period. For direction I planned to use the 2 timers as follows. The disc would be slotted with a mark/space ratio of say 5/95 or less, to give narrow pulses. The two opto pickups would be spaced such that the signal from one would be delayed from the other by say 10% of the period (T) between pulses on one sensor. Thus if the disc rotated in one direction the second pulse would be delayed by 0.1*T and in the reverse direction by 0.9*T. So to determine direction the software would only have to check if the delay was more or less than 0.5*T. Then I remembered that the U3 has a quadrature mode using the two timers and it seemed more elegant to use that for both RPM and direction. I can make the disc with an even mark/space ratio and space the pickups to give an approximate 90 deg. shift. So far so good, but after reading the manual and scouring this forum I have been unable to figure out how to get what I need. I can see how to configure and reset the timers for quadrature mode but then I hit a brick wall. So in summary my questions are: 1. How do I use this mode to get freq. and direction? 2. For the frequencies mentioned can I continue with query/response mode or should I change to scanning mode? 3. How close to a 90 deg. phase shift do the the two inputs need to be for the quadrature mode to work properly? In other words what is the tolerance on the phase shift?

#2 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 20 May 2013 - 10:51 AM

Yes, quadrature is made to do just what you need. For background on quadrature encoding, go to the following Wiki entry and read the section titled "Incremental Rotary Encoder":

http://en.wikipedia....drature_encoder

1. How do I use this mode to get freq. and direction?

Each edge will add or subtract a tick from the quadrature count register. To get the current count at any time, you read Timer0Value:

//Read Value from Timer0.
eGet (lngHandle, LJ_ioGET_TIMER, 0, &dblValue, 0);

Typical use is to take an initial read of the count, then 1 second later take another read. By looking at the change in count over the change in time you get frequency, and the sign gives you direction.

2. For the frequencies mentioned can I continue with query/response mode or should I change to scanning mode?

The signal frequencies you mention are no problem for the quadrature input timer. The question of whether to use command-response or stream mode depends on how often you need to read the quadrature count from the U3.

3. How close to a 90 deg. phase shift do the the two inputs need to be for the quadrature mode to work properly? In other words what is the tolerance on the phase shift?

It is not very picky. You are just trying to space them so multiple edges are not right on top of each other:

http://labjack.com/s...ers-guide/2.9.2

#3 TonyF

TonyF
  • Members
  • 16 posts

Posted 20 May 2013 - 11:39 AM

Typical use is to take an initial read of the count, then 1 second later take another read. By looking at the change in count over the change in time you get frequency,


Many thanks for the quick response.
Surely this is how to do it when using a counter not a timer. I understand that reading the timer gives you the number of clock ticks between the last two rising (or falling) signals and did not rely on the time between reads. Or does the timer act like a counter in quadrature mode?

#4 TonyF

TonyF
  • Members
  • 16 posts

Posted 20 May 2013 - 11:44 AM

The signal frequencies you mention are no problem for the quadrature input timer. The question of whether to use command-response or stream mode depends on how often you need to read the quadrature count from the U3.


Currently with the pressure sensor readings I take readings every 0.05 secs for a duration of 3 secs and average the readings (60 reads in total). It seems to make sense to stick with that timing and method when I add the RPM feature.

#5 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 20 May 2013 - 12:07 PM

I understand that reading the timer gives you the number of clock ticks between the last two rising (or falling) signals and did not rely on the time between reads. Or does the timer act like a counter in quadrature mode?

What you are describing is timer modes 2 & 3.

Timer modes 5, 6, 8, and 9 are all doing some sort of counting rather than timing. With quadrature most people are trying to track absolute position, so the U3 tracks the current count and that is what you get.

Currently with the pressure sensor readings I take readings every 0.05 secs for a duration of 3 secs and average the readings (60 reads in total). It seems to make sense to stick with that timing and method when I add the RPM feature.

Counting over time inherently averages, so you just need to get the initial count and 3 second count, find the difference, and then divide by 3 to get Hz.

#6 TonyF

TonyF
  • Members
  • 16 posts

Posted 20 May 2013 - 12:22 PM

Counting over time inherently averages, so you just need to get the initial count and 3 second count, find the difference, and then divide by 3 to get Hz.


Yes that was my original plan but with a counter, thus leaving the problem of direction.
I had incorrectly assumed that the quadrature function still worked as a timer, which is what gave me the problems in the first place. Now that I understand the function it should be pretty easy to get it up and running.
Thanks for the great LabJack support policy.

#7 TonyF

TonyF
  • Members
  • 16 posts

Posted 27 June 2013 - 04:01 AM

I had other stuff to do which kept me away from this, but now that I am at it again I can't seem to get it to work. I put a code snippet below, with the error handling stuff removed for clarity. I am inputting 2 quadrature inputs on FIO6 and FIO7. The signals come from two optical pickups and a slotted disc, so although basically square wave in nature the rise and fall times are not very fast and vary with RPM. No two edges are coincident within the time period specified in the manual. I know that the signals are getting through OK because I have attached an oscilloscope directly to FIO6/7 and when I configured the LabJack to work as 2 counters, as a test, everything worked fine. (See below for addition question on counters) Originally I used the easy eGet function to read LJ_ioGET_TIMER and MyCount was a dbl. In that configuration, regardless of input frequency (around 50Hz), MyCount only gave 3 values -1, 0 and 1. I tried it with MyCount as a signed 32 bit integer, that didn't compile with eGet but it did with AddRequest/Go as below. That again only returns 3 values 6306152, 0 and 13384040 regardless of input freq., but it only does that on the first pass through the loop. later loops only return MyCount = 0. When using MyCount as a dbl it would still return -1, 0 or 1 on later loops. I also found that I had to specifically set the timer mode for each timer, is that correct? I thought that setting one would do both when in mode 8. HELP PLEASE. This is driving me mad. OpenLabJack(LJ_dtU3, LJ_ctUSB, pch, 1, lngHandle); ePut(lngHandle, LJ_ioPIN_CONFIGURATION_RESET, 0, 0, 0); //Configure FIO0, 1 and FIO2 as analog, all else as digital. ePut(lngHandle, LJ_ioPUT_ANALOG_ENABLE_PORT, 0, 7, 16); //********* timer counter test AddRequest(lngHandle, LJ_ioPUT_CONFIG, LJ_chTIMER_COUNTER_PIN_OFFSET, 6, 0, 0) ; AddRequest(lngHandle, LJ_ioPUT_CONFIG, LJ_chNUMBER_TIMERS_ENABLED, 2, 0, 0) ; AddRequest(lngHandle, LJ_ioPUT_TIMER_MODE, 0, 8, 0, 0) ; AddRequest(lngHandle, LJ_ioPUT_TIMER_MODE, 1, 8, 0, 0) ; AddRequest(lngHandle, LJ_ioPUT_TIMER_VALUE, 0, 0, 0, 0) ; Go() ; start loop Wait 1 second AddRequest(lngHandle, LJ_ioGET_TIMER, 0, MyCount, 0 ,0) ; Go() ; Display count Continue loop or not ? Y/N repeat loop ---------------------- Question on use of counters. I observe some non-intuitive behaviour with the use of counters. e.g. AddRequest(handle, LJ_ioGET_COUNTER, 0, dblMyCount, 0, 0) Go() does not function the same as eGet(handle, LJ_ioGET_COUNTER, 0, dblMyCount, 0) Also if I count in a loop and use ePut(handle, LJ_ioPUT_COUNTER_RESET, 0, 1, 0) to reset count to zero before the next count, the reset is ignored on the next GET_COUNTER but works on the second GET_COUNTER So get it to work I have to psuedo code like this loop start COUNTER_RESET GET_COUNTER Wait for 1 second GET_COUNTER Loop repeat Without the first GET_COUNTER I get an accumulative count instead of the count during each loop, even though I reset first????????

#8 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 27 June 2013 - 09:33 AM

Did you try it in the test panel in LJControlPanel first? See if quadrature works there before using your own code. You can also test by connecting 1 or 2 wires to GND and then tapping them inside the 2 quadrature inputs. It is hard to do any specific sequence but you should see values going up and down somewhat at random. Once you confirm the hardware, then you can try to get the same results in Delphi.

#9 TonyF

TonyF
  • Members
  • 16 posts

Posted 27 June 2013 - 10:59 AM

Did you try it in the test panel in LJControlPanel first? See if quadrature works there before using your own code.


OK, I have now tried it in the LJControlPanel.
It works fine when I configure FIO6/7 as either counters or timers, but when I configure the timers to be in quad mode I get the same random output of just 3 values -1,0 or 1 regardless of input frequency. If I remove the input signal then it will show a steady value, which maybe -1, 0 or 1

Do you have any comments on my previous question about the counter coding?

#10 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 27 June 2013 - 11:54 AM

Try the test with GND wires to see if you can get numbers besides -1, 0, and 1. If so it points to something not quite right about your signal.

AddRequest(handle, LJ_ioGET_COUNTER, 0, dblMyCount, 0, 0)
Go()

does not function the same as
eGet(handle, LJ_ioGET_COUNTER, 0, dblMyCount, 0)

If you use AddRequest and Go, you then need a GetResult to get the value back (and see if there was an error).

http://labjack.com/s...users-guide/4.1

Also if I count in a loop and use
ePut(handle, LJ_ioPUT_COUNTER_RESET, 0, 1, 0) to reset count to zero before the next count, the reset is ignored on the next GET_COUNTER but works on the second GET_COUNTER

On the U3 & U6, a request to LJ_ioPUT_COUNTER_RESET does not actually cause any communication with the device. Rather it sets a flag in the UD driver that says to do a reset on the next counter read. You would typically use an add/go/get block rather than an ePut.

I changed the pseudocode at the end of Section 4.3.6 to reflect this:

http://labjack.com/s...ers-guide/4.3.6

The underlying reason for this is that at the low-level the reset is part of the same packet as a read:

http://labjack.com/s...-guide/5.2.5.17

This allows you to have minimal time between when a read occurs and the reset happens, so you don't miss counts.

#11 TonyF

TonyF
  • Members
  • 16 posts

Posted 28 June 2013 - 01:37 PM

Many thanks for your help. Now I understand much better how the counter functions work. I was happy to use the code that I found worked OK but was puzzled as to why. Now I know. I have fixed the quadrature problem also. I wanted the maximum resolution on the counts combined with a small toothed rotor. It turns out that the width of my teeth were too narrow for the spacing of my two optical sensors. So it would open one beam before closing the next. The signals looked OK on an oscilloscope but the LabJack didn't like it. The answer was to make another rotor with 8 instead of 10 teeth with each tooth being double the width of the sensor beam spacing. When testing that I was pleasantly surprised to find that for each complete "cycle" the LabJack returned 4 counts. Obviously, one each for each edge then doubled up for the two timers. I was expecting only 1 or 2 counts per "cycle", so with 8 teeth I get 32 counts per revolution in place of the 10 or 20 that I was expecting. So my resolution is much better than I thought it would be. So now I have a RPM meter with direction info included. If I may make a suggestion it would be to explain some of this stuff in a bit more depth in the manual. Many thanks again for your help.


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users