I wired up the encoder to the 9505 module so I can measure position and speed of the cart. It is a standard quadrature encoder with 1000 pulses per rev. Looking at the transition edges, we get 4000 edges per rev.
I started with a LabVIEW example to read the position of the encoder. This works fine and was very easy to set up. I also want to measure speed, though, and that gets a little more challenging. I decided to look at instantaneous speed by measuring the space between consecutive edges. I started with a routine that outputs the max of either the last space measured (space-1) or the current space being measured. Including the current measurement helps when the system is slowing down. I ran the motor at low speed and took a look at the space measurements. I found out that the pulse edges on the encoder I am using are not equally spaced. The graph below shows alternating long and short spaces. The long spaces were about twice the length of the short spaces. This would make the speed measurements very wild and inaccurate.
My second approach was to always average the last two space measurements. I averaged space-1 and max (space-2, current) to get a smoothed measurement of the spacing. This worked pretty well and reduced the variation significantly. The graph below shows there is still a small variation that repeated every four spaces, though. I realized that the widths of the on and off portions of the A and B pulses were not perfectly spaced either. I am guessing the on portion is slightly longer or shorter than the off portion of each signal.
My third approach was to average the last four space measurements. I averaged space-1, space-2, space-3, and max (space-4, current) to get a very nice, clean space measurement. This removed all the cyclical variation from the measurements and gave me a nice smooth curve, which you can see in the graph below. My only concern was that at low speeds with deceleration the delay for measuring true speed could be significant. The measured speed is always a couple of counts behind when averaging four values. I decided that when the current space measurement exceeds 40,000 (1/1000 of a second), I will only use the last two spaces. This trades a little variation for quicker response. I may adjust this cutoff level later.
Now that I had a very accurate measurement of the spacing between the pulses, I had to convert it to speed. I ended up using the new high throughput division available in LabVIEW 2009. I was able to divide 40,000,000 (total counts per second) by the spacing to get pulses per second. One nice thing is that the high throughput math works inside a single cycle timed loop. There is a delay of 29 cycles between inputting the numbers and getting the answer, but that is a very short amount of time when each cycle is 25 ns. Good enough for me!!!
Now I feel I have very accurate measurements of current, position, and speed. The next step will be adding PID control of the current.
On a side note, there is no noticeable noise in the encoder signals. Apparently the combination of shielding and differential encoder inputs is enough to eliminate any noise issues. This means I can run all the cables in the same track when I get some cable carrier, which will save me a little money. If there was too much noise, I was considering using two cable carriers in opposite directions – one for the encoders and one for the motor cable. I need to order the carrier soon, because the cables would get very tangled if the cart moves around much, and I am very close to moving the cart.


