01-29-2010 10:23 AM
Ethan,
I have been investigating Lorne's suggestions to see how valid they are. I started with his method and had a problem at small pulse widths, so I started looking at the current measurements at all the different offsets to see which points matched the true current. I am sure every motor is different, and the small robot motor I am using may not be a standard one used with the 9505, and the sampling rules may be different for my motor. For my application, I need very accurate current measurements regardless of PWM duty cycle since I am trying to control the current.
I would be curious to see a current waveform for one of your motors or solenoids. It would be interesting to see how the waveforms differ for other motors, etc. It would also be interesting to see if the current you are measuring is an accurate value, or just a steady value.
Bruce
01-29-2010 11:07 AM
Hi Bruce
I am in the process of adding a couple features to our 9505 example. My initial testing on motors here showed Lornes code as spot on for adjusting the timing. I do have a couple of concerns with the code we are using is investigating a time when the current is least stable on a motion platform. Right after we enable our drive is when we will see a peak current as the motor starts to move. If we were to study the motor after it has reached target velocity we should see a smaller more stable current.
I looked through the code and we are sending our rotating trigger from our while loop to our single cycle timed loop. When we include the lag in the reading of the current sense. I don't believe this will give us a accurate tick count for where the reading was made.
My understanding is that we have two issues to look into right now the first being the current spike you see at the start, I believe this is being caused by the initial resistance of the motor to get it moving. The second issue is why the current appears to fluctuate much more when we run at a higher duty cycle, this I need to further look into the code to explain, I think it's related to how we are timing our current sense readings.
Thank you for your feedback on this, I am going to reproduce this next week and will post my results.
01-29-2010 11:34 AM
Eric,
I don't agree with your explanation of the current spike. The spike occurs every duty cycle, not just when the motor is starting. All my measurements and graphs are after steady state has been reached, so they wouldn't include the motor starting. I also think my trigger timing is dead on. I tell it when to trigger, then once it triggers I get a reading. I have a full duty cycle to send the next trigger value, so I am sure it gets there before it is used.
One thing I would like to see is duplication of my results using a different 9505 module. The one I have was borrowed from NI and has seen a lot of use. I would like to be sure it is not damaged in some way. Since you don't have my motor, it would be nice to see a plot with nothing connected to the motor outputs and see if it matches mine.
If you want to talk to discuss the details, let me know.
Bruce
01-29-2010 11:46 AM
Bruce
I agree your code is sampling at a settled velocity, I was looking over your code and thought we were just running the first 2000 ticks. I have ran it on my machine with my test motor and do see this present here. You can see my results here, I will need to check out a current probe and additional setup that will need to be done, so I won't be able to provide a detailed response until next week.
This confirms that what you are seeing is not specific to your module.
01-29-2010 12:58 PM
Eric,
I feel like we are on the same page now. I also like seeing your graph - I see the same spike that I have been observing that makes the first 100 counts unusable. Your motor looks like it might fit the "standard" motor requirements a little better. I can almost see a rising and falling section for yours. I think if my motor behaved like yours I wouldn't be having any problems.
Bruce
01-30-2010 08:33 AM
I think I may have found an acceptable solution. After preventing rotation of the motor and recording several different duty cycles, I made some observations about my motor:
The current during the Off cycle is almost exactly twice as large as the On cycle. I would still like an explanation for this if anybody has one.
Based on this observation, I was able to develop a fairly simple algorithm to measure the current. I measure the current in the larger of the two cycles (on or off) at 140 points after the pulse starts. I estimate the other value by either multiplying or dividing by two. I then multiply each value by its pulsewidth and divide by the total PWM cycle time to get the average current over the entire cycle. This algorithm comes very close (+/- 5) to the average value of the curve for all the curves I recorded up to 75% PWM.
I wonder what will happen when everything starts moving. Hopefully this will be accurate enough for control purposes.
Bruce
02-08-2010 05:39 PM
Hi Bruce
I got a chance to setup a circuit to model a "Perfect Motor" basically it was a series of inductors and resistors. The first case I wanted to analyze was why we were seeing so much fluctuation in the current reading. On my circuit consisting of resistors and inductors I produced the following graph.The red lines match the readings I got from my o-scope current probe (I shifted them down just a little bit).
Our motors have a natural Vemf built into them which varies their voltage slightly based on the position of the brushes. In our case we were sampling over a number cycles and assembling the samples together, this makes our current vary a little bit on each reading and is normal for a motion system. Once we implement a PID it negates the effect of the Vemf. When we remove the Vemf we can see the signal is much smoother as shown in my image above.
Given this graph we can see that during the on portion of our duty cycle (keep in mind due to timing our duty cycle is shifted a little bit right) our current matches our scoped current. Now we encounter the question of why we can not read the PWM during the LOW portion of the duty cycle. I created some figures below to outline the problem.
The NI 9505 measures motor phase current by sensing the voltage drop across two resistors as shown in Figure 1 (attached). The difference between the two resistor voltages is amplified and sent to an Analog-to-Digital converter (ADC). The sign of the amplified voltage difference indicates direction of current flow. The ADC returns the 12-bit data to the FPGA.
When the PWM signal is HIGH, current flows as indicated in Figure 2 (attached). No current flows through R2. The differential voltage is correct and the NI 9505 returns accurate current measurements to the FPGA. When the PWM signal is LOW, current flows as indicated in Figure 3 (attached). Note that the voltage drop across R2 is negative, while the drop across R1 is positive. The differential voltage is not correct and the NI 9505 returns inaccurate current measurements to the FPGA.
The optimized location for reading the average current on a motor meeting the required inductance is in the middle of the HIGH time of the PWM signal. National Instruments recommends reading current at this point. Reading current during the LOW time of the PWM signal will return inaccurate data.
This explains why we see the currect current during the high period, during the low it appears to be roughly double with some voltage being introduced across the motor and we have a brief jump during transition. Lornes code posted earlier will hold true for when to sample during the hightime to get the correct current reading on locating the middle of the high time in the duty cycle.
02-08-2010 06:56 PM
Eric,
Very good explanation. That explains why the Off current is larger than the On current. If I understand your explanation correctly, I would expect the Off current to be measured exactly twice the On current, because the same current is going through both resistors. V = 2 I R, so if I divide the Off current by two that should be pretty close.
It does look like the On cycle is the best for measuring the current as long as your pulse width is greater than 200 counts. From my measurements, it looks like the spike makes the current measurements invalid for the first 100 counts.
Now I am going to go back and look at all my data with these explanations in mind.
How equal and accurate are the resistors R1 and R2? I noticed my measurements are significantly different when the motor runs in the opposite direction - the ratio between On and Off looks like about 1.8 instead of 2, so I am wondering if there could be 10% to 20% difference in the two resistance values.
Thanks,
Bruce
02-08-2010 08:59 PM
Eric,
Based on your circuit diagrams, I was able to measure the resistance in each arm of the circuit by disconnecting the motor and setting the PWM to 100%, then measuring the resistance in the arm connected to ground. By reversing the direction, I measured both resistances. On my 9505, I got about 0.75 ohms for CW and 0.9 ohms for CCW. My meter only measures to 0.1 ohms, so I had to estimate a little. For the Off circuit, the current should pass through both resistors for a total resistance of 1.65 ohms. This give an Off/On ratio of about 2.2 for CW and 1.8 for CCW. Experimentally, if I measure at the middle of each section, my 9505 gives a ratio of about 2.05 for CW for duty cycles between 20% and 80%. Based on previous observations, I expect the CCW ratio to be around 1.8, but I haven't measured it yet. This should give me a very good method for measuring current. I will read the middle of the On cycle for PWM > 20%, and the Off cycle for PWM < 20%. Depending on the direction of rotation, I will use a correction factor to get equal measurements in each direction.
Bruce
02-08-2010 11:12 PM
Eric,
Apparently the resistors are not quite as unbalanced as my meter indicated. For CW, my ratio Off/On is 2.05. For CCW it is 1.95. I will adjust the On values using these factors, since the Off values in both directions should match exactly.
Thanks again for explaining the measurement circuit. This looks like it will work in both directions and it makes sense to me.
Bruce