02-15-2011 05:01 AM
Dear All,
I've had a good search but can't find any examples or descriptions of the best way to set up a VI that reads and logs my AI channels at each change in quadrature encoder input. I've a 360 PPR encoder with a Z index (Which I've determined I need to connect to PFI 8 9 and 10 through the SCB-68) and a PCI6221 card doing the DAQ, but all of the examples I see are how to measure the angle, rather than how to use the angle as a trigger for the AI for a sample at each increment. I must be missing some examples, can anyone point me in the right direction?
02-15-2011 01:13 PM
You could use the A, B, or Z signal directly as the AI Sample Clock by specifying the appropriate PFI line to use as your clock source (see here). The same PFI line can be routed to both the counter and to the sample clock for your AI Task.
Best Regards,
03-07-2011 11:34 AM
I have attempted this (I think, see attached) but can't seem to get it logging consistently to whole degrees. It is often liked to a 0.25 or 0.75 degree increment and sometimes it may skip a couple of degrees. If I put anything more complex than a text box output on screen it starts skipping several degrees and double-sampling the same value at multiple angles? I will follow up with sample data.
03-07-2011 11:37 AM
And here's the sample data. It should have been at crank angle's of 1,2,3,4,5 etc, rather than 0.25,1.75....
03-07-2011 12:21 PM
I only have a few moments so I didn't dig into the DAQ Assistants. However, it isn't especially surprising to me that you're getting the kind of data you're getting. A couple brief points:
1. It appears that you're correctly taking AI samples once per quad cycle of the encoder by specifying PFI8 as the sample clock
2. However, you have no way to know or specify what the encoder angle will be when the first sample is taken. Each quad state will increment (or decrement) the angle measurement by 0.25 degrees, and it's probably more-or-less random which
quad state the encoder is in when you start its task with an assigned angle = 0.0 I'd guess that over lots of trials, you might get a first sample at 0.25, 0.50, 0.75, or 1.00 degrees with pretty much equal frequency.
3. Your encoder measurement appears software timed, and is thus not truly synced & correlated to the AI samples.
4. You are only reading 1 sample per channel per loop iteration. If your encoder moves fast causing samples to be taken more quickly than your loop code executes, then you'll keep getting farther behind and reading staler and staler data from the AI buffer. You then manually correlate this with an on-demand software timed reading of crank angle, making it look like you missed AI samples. In fact, the buffer isn't missing them, but your software-timed approach to reading the counter task leads you to incorrectly correlate the stale AI samples to the current crank angle.
That's all the time I've got now, but I hope these ideas help you move things along a little further...
-Kevin P
03-07-2011 12:53 PM
Cheers Kevin, I'll try to work forward from that. A couple of Q's/points in relation to your points...
1- Woo! First thing I've got right in a long time.
2- Yes, that's true, and while it ultimately doesn't matter to me providing I get the same ones each cycle, I'm not getting that for the other reasons, making post processing a tad hard.
3- I'm not sure how to alter that. I'll look into it.
4- I'm confused as to how, I'll fix this. I'll think on it this evening.
Cheers for your time.
03-08-2011 02:55 AM
Here is how I solve this kind of measurement :
The LS7084 is not essential (you could also use the A or B signal from the encoder as the AI trigger) but this method will provide a four time better angular resolution.
See this example and don't hesitate to post back if you need further help.
03-08-2011 07:37 AM
JB's idea is a good one -- I'll just add one more good effect you can get with it:
...6. Configure both the AI and counter tasks to sample on the trailing edge of the pulse. That way you can be sure that the count value will have incremented/decremented before the sample is taken.
Note: a similar effect is possible with your board's change detection capability if you use the trailing edge of the change detect event as the sample clock. Some more searching on change detection and quadrature should find you some good info.
-Kevin P
03-08-2011 12:26 PM
Cheers for that help, I think I'm on it now, the example is fairly similar to a previous version I drew out then gave up on! Just trying to modify that example to suit my needs, the complication of 5 additional AI channels complicates the setup a bit more. I Can't find the function that's labelled as 2b - any idea where it is in the toolbox/function list?
03-08-2011 12:45 PM
I don't think that function is in the regular palettes, but it should be installed in the examples folder. Starting from
your LabVIEW install folder, the path down is:
<LabVIEW>\examples\DAQmx\_Utility\_Utility.llb\Get Terminal Name with Device Prefix.vi
-Kevin P