Archive for January, 2010

More current analysis

Saturday, January 30th, 2010

It looks like I jumped the gun on the inductor curves.  I started looking at the curves as the current increases by preventing the motor from rotating.  I found out that the curve did NOT stay the same shape as it shifted up.  For some reason, the Off current is roughly twice as much as the On current.  The shape of the curve also gradually changes, which makes the inductor oscillations unusable.

Current waveform, 25% duty cycle, no rotation, 470 uH inductor
Current waveform, 25% duty cycle, no rotation, 470 uH inductor

I decided the inductor wasn’t going to be useful, so I went back to just the motor and took a look at the currents at the higher loads.  I get the graph below, which shows a very smooth curve and the Off cycle is almost exactly twice the On cycle.  I recorded the curve at many different duty cycles and this looks pretty repeatable.

Current waveform, 25% duty cycle, no rotation, no inductor

Current waveform, 25% duty cycle, no rotation, no inductor

From my observations, I came up with an algorithm for measuring current.  I measure the current at 140 counts in whichever part of the cycle is longer, then estimate the other part of the cycle by multiplying or dividing by two.  I multiply each value by its percentage of the total cycle time, add together, and divide by total cycle time to get average current.  For all my recorded graphs the value was very close to the mean value of the entire graph.  I think this will be accurate enough to control the motor.  I will code it into the FPGA and see how well it works.  The next step will be writing a PID control loop for the current.

Current spikes with inductors

Thursday, January 28th, 2010

I ended up ordering a 220 uH inductor and a 470 uH inductor.  They arrived today so I tried them out.  I tried each inductor separately, then combined them to get 690 uH.  I saved graphs at 5, 25, 50, and 75%.  I plotted the original curve (white), a smoothed curve (red) and the mean value (green).  The graph for the 470 uH inductor at 25% duty cycle is shown below.  For those that are interested in seeing all the graphs, here are the Current Waveform Inductor Results (zipped).

Current waveform, 25% duty cycle, 470 uH inductor

Current waveform, 25% duty cycle, 470 uH inductor

The graphs still look nothing like the behavior that was predicted on the NI discussion forums.  The folks at NI predicted a rising current when it was on and a dropping current when it was off, creating a sawtooth waveform.  They figured sampling in the middle of the on portion of the cycle would give you a good estimate of the average current.  Obviously, that wouldn’t work in this case.  From the different graphs, I was able to make a number of useful observations.

  • There is still a spike at the beginning of the on cycle.  It isn’t as large, but it still makes the first 100 counts of data unusable.  This region should always be avoided when measuring current.
  • The high frequency oscillation is due to the rotation of the motor.  I assume the resistance varies as the motor rotates.  As the inductance increases, the amplitude of these oscillations decreases.  At 5% duty cycle, the motor did not rotate and the graphs are very smooth.
  • The inductors introduced a large amplitude oscillation in the current.  As the inductance increases, the amplitude decreases and the frequency decreases.  With a very large inductance, the oscillations would go away.
  • Ignoring the motor oscillations, these graphs are very repeatable.  They shift up and down as the load is changed but do not change shape at all, indicating that selecting a point where the smoothed curve crosses the mean should always give the correct current value.

With the 220 uH inductor, the graphs seem more uneven and erratic.  With the two larger inductances, I get very similar results.  For now, I plan on going with the 470 uH inductor.  I haven’t examined the motor performance yet, but I suspect it will work just fine.  It seems just as zippy as ever, so any effects should be minor.

Since I can’t easily predict when the best time to read the current is, I plan on building a lookup table that tells me when to sample based on the pulse width.  To create the table, I can locate the intersection between the smooth curve and the mean curve for each pulse width.  It shouldn’t be too difficult to automate the process.  For small pulse widths, I plan on preventing rotation to eliminate the small pulses until the current gets too high.  For larger pulse widths, the smoothing works very well.

Current spikes with resistors

Monday, January 25th, 2010

I decided to try another experiment.  I removed the motor from the 9505 controller and replaced it with a 1000 ohm resistor.  I still get a spike whenever the voltage switches, and it has the classical RC circuit decay.  The initial value is about 60 counts (6.2 mA per count) and it decays to a steady state value of 4 counts (24 mA), which is the expected current with the resistor.  I can’t explain why the second peak is positive instead of negative.

Current waveform, 25% duty cycle, 1000 ohm resistor

Current waveform, 25% duty cycle, 1000 ohm resistor

Next I removed the resistor and tried it with nothing connected as a load.  The curve looked almost identical to the previous curve, but it goes to a steady state value of zero, which is no surprise.

Current waveform, 25% duty cycle, open circuit

Current waveform, 25% duty cycle, open circuit

My final test for the day was to use a 150 ohm resistor to get a larger steady state current.  In this case, I noticed the peak still starts at 60 counts but decays to the expected steady state value.  It does weird things when it switches back to zero volts that I can’t explain.

Current waveform, 25% duty cycle, 150 ohm resistor

Current waveform, 25% duty cycle, 150 ohm resistor

It appears for resistive loads the current always starts at 60 counts and decays to the expected steady state value.  I do wonder what would happen if the steady state value was greater than 60 counts.  From the decay curves, I figured out that the time constant for the decay is about 1000 ns or 1 us.  I also noticed a third small spike just before 2000 counts.  It looks to me like the circuit disconnects from one source about 30 counts before connecting to the other source.

I noticed in the 9505 manual that the minimum inductance is 500 uH.  I assume my motor’s inductance is much lower than this.  My current plan is to buy a 500 uH inductor and put it in series with the motor.  It will smooth out the current to a triangular waveform that can be measured predictably.  The only negative effect I foresee is that it will also filter changes in voltage and delay the response of the motor.  The delay may not be large enough to worry about, though.  I might also get a smaller inductor, about 250 uH, to try out as an intermediate step – less smoothing but less delay.

Current spikes smaller

Friday, January 22nd, 2010

I removed the capacitors from the motor and repeated the test.  The current waveform looks better, but it still has spikes.  They are much smaller, but they still make it impossible to measure the current at low duty cycles.

Current waveform, 25 percent duty cycle, no capacitors

Current waveform, 25% duty cycle, no capacitors

The oscillations are much more visible, even though they are the same magnitude as before.  I noticed that the frequency of the oscillations is proportional to the speed of the motor.  They don’t worry me too much at this point.

My big unknown at the moment is how to measure the average current accurately.  My whole control strategy is based on adjusting the duty cycle to control the motor current.  If I can’t measure the current, I’m not sure how I will control the motor.  My only thought at the moment is to perhaps add an inductor to the motor circuit to increase the inductance and smooth out the current waveform.  I have no idea if that would actually work, though.

Current spikes

Thursday, January 21st, 2010

I modified the software to sample the current at different offsets from the start of the duty cycle.  After 2000 duty cycles, I get a complete picture of the current waveform over a single duty cycle.  As long as the system is in a steady state, the waveform is quite repeatable.  I used this program to examine the current waveform at different duty cycles and found out why the current measurements are way off during short duty cycles.  Take a look at this graph of the current waveform at 25% duty cycle and no load.

Current waveform, 25% duty cycle, no load

Current waveform, 25% duty cycle, no load

From the graph, I realized there is a large positive current spike when the voltage turns on, and a large negative spike when the voltage turns off.  When the duty cycle is short, the two spikes run together and make it impossible to measure the current during the on cycle.  After studying it for a while, I decided the filtering capacitors I put on the motor terminals are most likely causing the spikes.  There is a large current flow each time a capacitor is charged or discharged.  I am going to try removing the capacitors to see if that improves the current waveform.  It will be a challenge to remove them, though, because when I put them on I wound the wires around the terminals and put a huge blob of solder on them.  I could cut them off easily, but then I wouldn’t be able to put them on again.

Software begins

Tuesday, January 19th, 2010

This begins phase two of the project – the software.  Actually, I’ve been working on the software on and off for a few weeks, but I haven’t had anything to test it on until now.

I wrote the motor control and current measurement routines using samples from NI and modified them based on several discussions on the NI forums.  It is fairly simple – output a pulse width modulated signal, avoid a few specific duty cycles, and measure the current at the best point in the cycle.  The trick is figuring out the best time in the cycle to read the current so that it represents the average current for the cycle.

My first test was running the motor at different duty cycles, making sure it works, and seeing if the current measurements look reasonable.  I propped up the cart so the gear doesn’t engage with the rack.  I tried several speeds, and the motor runs great.  At low speeds, the gears don’t make any noise at all.  At high speeds, they make a little noise as they mesh.  The current measurement is kind of weird, though.  At any duty cycle over 5 percent, the current reads about 10-20 units, which is about what you expect when there is no load other than motor friction.  However, under 5 percent the current reads around 600 units, which is ridiculously large.  I suspect I am reading a peak value and should read some other time in the cycle.  My plan is to write a routine that will sample the current at a different time in the duty cycle each time through the loop.  I should be able to build a complete current waveform after many loops at constant speed.  It may not be perfect, but it will give me an idea of what is going on with the current and when the best time to measure it is.

I did run the cart back and forth on the rack a few times at different speeds.  It works great at low and medium speeds, but I don’t dare run it at high speeds until I have the limit switches ready to stop it before it hits the ends.  The travel is nice and smooth, so I don’t expect any problems in that area.

Hardware complete

Tuesday, January 19th, 2010

Today I picked up the finished hardware, and it looks really good.  Other than the cable carrier and the limit switches, everything is assembled and ready to go.

Bill cut off the end of the bearing shaft for me.  It turns out it isn’t a rubber saw at all, although it does kind of look like it.  It is a composite blade (hardware stores call them abrasive blades) that wears away as you cut.  Apparently they work really well for cutting hard metals like the shaft.

Dana mounted the bearing shaft on the shelf for me.  He ended up using a solid block underneath the brackets and just removed the right amount of material to get them to the thickness needed.  Dana also drilled a hole in the pendulum and added a set screw at the end so the pendulum is easy to mount on the encoder.  Bill cut off the end of the pendulum so it is about 30 inches long.  That is about as long as I could make it without hitting the floor when it is sitting on a standard table.

Many thanks again to the guys at Shaltz Automation for helping me build this contraption.  I couldn’t have done it without their help.

I wired up the motor to the 9505 module for preliminary testing.  At this point, the programming begins, so I am going to start a new category called “software” where I will discuss writing and testing software.  I will probably add a few more items in the hardware category when I add cable carrier and limit switches.

Limit Switches Work

Friday, January 1st, 2010

Finally had a chance to test the limit switches tonight.  Wired the first one up to the DAQ and didn’t get a signal.  Wired the second one up with the same result.  Figured maybe the connections were bad in the connector, since I didn’t have the special tools to push the wires into the sockets.  Checked continuity with a meter and pushed them in some more just to be sure.  Reviewed the limit switch documentation and verified all the wires were in the right positions.  Everything looked good.  Wired one back up to the DAQ, still no signal.  Started wondering what to try next.  Reviewed the limit switch documentation again, and noticed the sample circuits have a pull up resistor between the voltage source and the signal.  Added a 1K resistor to the circuit, and everything started working great.  The sensor is actually much more sensitive than advertised.  On a flat black surface (my computer keyboard) it works as advertised 2-20mm.  On any white or reflective surface (envelope, etc.) the range is actually between 2 and 3 inches depending on the surface.  I will have to test them on the actual surface they will be used with, but I expect to be able to mount them directly to the shelf.  Originally I expected to need some spacer blocks to get them closer to the surface, but it will be much easier to mount them if that is not necessary.

Other good news – I found out the sbRIO board has been repaired (finally) and has been shipped to me.  I should have it early next week.  That means I will have my choice of RIO chassis to work with.