Failed attempt to explain JAG linearity

Once again I revisited the Victor non linearity phenomenon and tried to convince myself with some math and excel analyses that PWM and motor inductance/resistance and motor commutator characteristics are the cause. In the Sensorless BackEMF speed control thread I conjectured that the JAG linearity was due to its 15khz pwm. This was putting about 15 pulses per commutator segment (we think there are 10 segments) at max motor speed whereas the 120hz and 2khz victors were putting an 1/8 and 2 pulses respectively. I dedicated a day to a more detailed analysis to verify that this was the reason for the JAG linearity.

Well… all I did was show that the results are the same for all three controllers … but I finally was able to reproduce the nonlinear speed vs duty cycle curve that we all see with victors. This is a big discovery and represents a paradigm shift in getting me off of the pure resistive motor model when using a pwm drive.

The analysis computes a normalized motor current i_norm which results from an assumed L/R for a CIM01 and a given controller PWM Hz. Instead of assuming steady state without commutator segments, I let the pulses accumulate from a zero coil current for the number of PWM pulses that the commutator segment would see. This normalized current is then multiplied by the max current and set equal to the i_free current.

So i_free = (12 - Vemf)/R * i_norm

This leads to an equation for w/w_free=(1-i_free/i_stall/i_norm)/(1-i_free/i_stall).

i_norm does fall off with speed when the L=230uh (from an old thread) is used because of commutator effects. I ran a case with L=23uh and the falloff was negligible.

But the surprising result is that the 15khz doesn’t seem to enter into the nonlinearity. So… I have replaced a nonlinear problem with a why linear problem:)

Enclosed is my Excel and if anyone wants to discuss it , I’d love to find a hole in my assumptions!!

POST NOTE:
If the L/R of the motor is small with respect to the the pwm period (like the 120hz Victor) or if the pwm period is small (like the JAG) and the commutator segment time is large with respect to L/R then

i_norm = duty is a good approximation.

So for the inductive motor model: i_free = ((12-Vemf)/R) *duty

Inductive model -> Vemf = 12 - i_free*R/duty (This holds for Vemf >0 else Vemf = 0 .)

So we have an inverse relationship with duty cycle.

The pure resistive model assumes that the motor input is a dc voltage = duty12
i_free = (duty
12 - Vemf)/R

Resistive model-> Vemf = duty12 - i_freeR

and we have a linear relationship to duty cycle.

Motor commutator effects.xls (97 KB)


Motor commutator effects.xls (97 KB)

Here is a comparison of the inductive motor model with real data taken by the Beach Bots in 2007 I think. I used the CIM motor parameters , not sure what Victor but just adjusted the i_free to account for added friction from their installation. . Fit is within about 5%

Inductive motor model data fit.xls (100 KB)


Inductive motor model data fit.xls (100 KB)

It was a Victor 884.

When I read through the jaguar docs, when you get into the CAN modes, there is both a voltage control mode and a current control mode. There was no mention of a pulse width control mode. If the Jaguar was in voltage control mode, that might explain the speed linearity.

I believe the voltage control mode simply converts a voltage input to a pwm command. There are provisions for a reference voltage input from a pot as well. I don’t believe there is any voltage feedback that is used in a PID loop…only encoder or current.

If you look at hbridge.c there is some code that does this conversion:
Here is an excerpt when the input voltage g_lHBridgeV is >0…

// Compute the PWM compare value from the desired output voltage.
// Limit the compare value such that the output pulse doesn’t
// become too short or too long.
//
ulCompare = (((32767 - ((g_lHBridgeV * g_lHBridgeVMax) / 32767)) *
SYSCLK_PER_PWM_PERIOD) / 32767);

g_lHBridgeVMax=32767 so this essentially says that

      ulCompare = (1 - voltage/32767)*SYSCLK_PER_PWM_PERIOD

     ulCompare then sets the HW registers to generate a gate pulse for a given number of system clock counts.

I don’t fully understand how these compare registers work but I’m guessing ulCompare sets a counter threshold on a system clock pulse counter. So if the voltage is zero then the counter never trips and the gates remain off. If the voltage is max or 32767 cnts then the ulCompare is zero and the gates are always on. Anything in between sets the duty pulse width.

Chris,
One of the things that has not entered into the discussion yet is…The brush assy contacts more than one commutator segment at a time. Although it is easier to see using a Victor, the current through the motor steps up and down as the brush assy crosses a commutator boundary. At any one point in time, you can have one or two windings in parallel.
Don’t forget that at slow speeds, motor losses become the more predominant part of the model. Bearing friction, brush friction, load losses and magnetic field issues all need to be accounted for. It is very difficult to get the motor moving particularly with small duty cycles. As the motor approaches max speed, the back EMF becomes more dominant.

The most likely explanation is that the input pulse time was mapped to the duty cycle output to provide a linear response. Luminary Micros probably did for us what allot of teams where already doing with the old controller.

Timeout… I found a bad assumption in the excel that changes the speed curves but not the normalized current. Stay tuned.

Dooh!!!

Both models are correct: the linear applies to the brake mode and the nonlinear to the coast mode.

The commutator, friction, pwm rates , motor inductance etc are all secondary distraction factors. The key is the darn protection diode in the off pwm pulse phase. Under simplifying assumptions, we can think of Vemf as a battery that is allowed to charge or discharge the motor coil. In the on phase, it is there for both the brake and coast mode. In the off phase, Vemf is only there for the brake mode where a current loop is created by switching on the lower legs of the H bridge. In the coast mode , these lower legs are switched off but there is a diode in the path instead. The diode essentially blocks Vemf from modifying the current once the current has reached zero and Vemf battery can be assumed removed from the ckt for most of the off phase. So in the coast mode we can replace Vemf with Vemf*duty. This leads to the two simple math equations I spoke of earlier. What I called the inductive model corresponds to the coast mode and the resistive model corresponds to the brake mode.

Brake mode: only 12 v chopped, Vemf present all the time so:

i_freeR = 12 duty -Vemf —> Vemf = 12duty - i_freeR … linear with duty

Coast mode: both 12v and Vemf chopped

i_free*R = (12-Vemf)duty --> Vemf = 12 - i_freeR/duty …varies inversely with duty

It is clearly a little more complicated than this, but these models capture the crux of the matter:

So all we need now is for someone to run the Victors and JAG in both coast and brake modes to see if theory holds up.

Hmmmmm how do I change the title of this thread:)

Doesn’t someone owe me a beer?!

Next time you are in Manchester NH, I will get you TWO beers.

Chris,
Do not start checking the menu just yet. The back EMF is present all the time the motor is turning. It varies with angular velocity, the number of poles in the armature and the number of poles in the magnet structure. It is a critical component in the no load speed of the motor. At this speed, the back EMF and the supply voltage cancel and no additional current flows in the motor windings. Look at the curves for any of the kit motors, and you will see that free speed occurs at current minimum. Now, if you drive a motor to free speed and open the supply voltage, the back EMF is capable of generating current if and only if there is a circuit path in which it can flow. In any of our motors, if the controller is put in the coast mode and the drive is removed, the circuit exists through the motor, wiring, FET diodes and battery. Since the diodes have a finite voltage drop in the forward conducting state, 1.25 volts per diode, current will only flow when the EMF is higher than the battery voltage by 2.5 volts (two FET strings in series). This is only possible if the motor is driven from an external source. At full throttle, the motor is spinning at a rate that is determined by the 12 volt source. When that is removed, the EMF will be around 12 volts and not enough to turn on the diodes. So what happens? The motor slows down due to frictional losses and magnetic interaction.
In the brake mode, the FETs are turned on to produce a closed circuit with the motor series resistance, the wiring resistance and series resistance of the two FET strings. Since Rds ON is 5.5 mohms and there are three FETs per string, the series resistance is 5.5/3=1.8mohm times two strings in series is 3.6 mohm. Total circuit resistance is likely in the neighborhood of 20-30 mohms.
However, as you may have pointed out, at less than full throttle, the controller is essentially in coast mode when a FET string is not turned on during the PWM off time. Again, it is unlikely that the diodes in the FETs are turned on (forward biased) during this time. Should this occur, once the EMF in the motor falls below 12 volts+2.5 volts=14.5 volts, the diodes would turn off. This becomes even more complex because of the dual winding caused by the brush contacting more that one commutator and the fact that the two windings are not rotating through the magnetic field at the same angular phase. i.e. the two will not reach maximum EMF at the same time.
So think about this, Stall current on the CIM is specified at 133 amps. Let us assume that is for two windings since it is labeled maximum current. If the supply is 12 volts at the motor terminals, then using Ohm’s Law, the motor series resistance works out to .09 ohms or .18 ohms per winding. The free load specification is 2.7 amps, again at max, so making a calculation, 0.243 volts would drop across the series resistance. Therefore at free speed, the back EMF would be 12+.243. An open circuit at that point would still not produce the required 2.5 volts to turn on the diodes. Now we are dealing with averages here so the inductance is not yet present in the calculations. Most certainly, the inductive spike is present for short periods of time. A scope would prove that during those times, the diodes do conduct and clamp the spike at 12 volts plus the diode forward voltage as you would expect.
So where does this all leave us? A quick check of the Jaguar manual says that the controller is designed for a very specific motor, i.e. the Mabuchi RS555 or the CIM. My suspicion is the motors were modeled and switching parameters set to optimize those motors. The manual goes on to say that other motor types may not behave the same and recommend the reader check the Brushed DC Motor Control Reference Design Kit (RDK) User’s Manual for more information on motor selection and use. If you have not downloaded that yet, it might prove to be very interesting.

Al,
I’m aware of everything you mentioned and I’m not sure that any of it contradicts what I’m saying.

I wish it was easy to draw pictures…

All I’m saying Al is that I believe the JAG linear transfer function that has been posted must have been taken in the BRAKE ON mode. Other xfer functions posted with Victors etc that are nonlinear were taken with the COAST ON mode.

Assume for discussion that the motor current is being driven positive during the PWM “on” phase.
In the brake mode, the “off” PWM phase places the low side FET’s ON and essentially shorts the coil which provides a path for the current to drive toward -Vemf/R as a steady state and can reverse the current in the coil. In the coast mode, as you say, the low side FET’s are OFF and the diodes are active. The diode will only conduct until the current drops to zero and then shuts off so Vemf cannot drive the current negative. So for most of the time , even though Vemf is there, it is not active in the calculation of current while in the “off” PWM phase for the coast mode. It is this that makes the difference. So my simple math model just assumes that Vemf is only present during the “on” PWM when operating in the coast mode but it does a great job of matching actual test data.

I am conjecturing that this is true for all the controllers we see in Vex and FRC. My experience with Vex motors tells me that they are coast mode since they have the same characteristic as the Victor nonlinear curve I posted earlier from Beach Bots. When I built the Vex Bbot inverse pendulum robot (http://youtube.com/watch?v=4loT_Xfhvbk
), I spent a lot of time modeling the problem with MATLAB and was always disappointed when my optimal control theoretical gains did not match the gains actually needed. Most of the problem came from the nonlinear Vex motor gain and frictional dead zones anomalies. Ohhh how I wish I had a Vex motor with an H bridge in the brake mode. I am currently working on a Vex unibot that is stable in two axes and balances on one wheel and already have had numerous failures from sticky nonlinear motors.

My suspicion is the motors were modeled and switching parameters set to optimize those motors. The manual goes on to say that other motor types may not behave the same and recommend the reader check the Brushed DC Motor Control Reference Design Kit (RDK) User’s Manual for more information on motor selection and use.

I have spent some time with the RDK and it may be optimized for the CIM re matching the bridge dynamics , but I’m guessing that a transfer function run in the coast mode will be nonlinear. There might be some SW optimization but I suspect this is only for the current and encoder PID’s. As I posted earlier to Joe Ross, the voltage control mode looks like a straight forward PWM motor controller that just puts out a PWM signal proportional to a voltage reference.

Chris,
During the time that valid drive signals are being converted to output, the brake and coast mode is not enabled. The selected mode only takes place when the input PWM goes to 127 or neutral value. Think about that time when the the throttle is just off the center position. The motor gets a very short pulse of output voltage. If the controller was in the brake mode during the off period, the motor would not turn very much. That is obviously not the case.
As an off season project for a team, I would like to see the test results of CIM motor linearity plotted for different loads. It would need to compare the linearity of the CIM at the max efficiency point, and several points on both sides as the motor approaches free speed and stall.
When teams report trouble tuning PID loops, I always wonder what else might be at play. As you know, things like non-linear frictional loss, gear backlash, motor bias, production variances in motors, misalignment of drive train shafts, minimum resolution on sensors and chain wear are all things that contribute to problems with achieving desired response.

This is why we need you in these forums Al… Very good point. My memory of the hbridge.c was a little fuzzy… they only go to the BRAKECOAST when voltage in is zero or when the limit switches are tripped.

Darn… I was hoping to be done with this. I might drink Erik’s beers anyway just to help me forget this problem.

So where does this leave us? Let me think outloud with the new ground rules:

It all hinges on the “off” PWM current. We have a low FET “on” and the rest “off”. Any current flow must now pass through a protection diode. As long as the diode can conduct, the current is heading toward a steady state value of -Vemf/R (assuming positive current during the “on” PWM drive). If the L/R is short with respect to the PWM period, the current decays quickly and is zero for most of the off phase. So the average current for the whole pulse is determined by the area under the “on” pulse which = (12-Vemf)/R*duty. This would be the case for the slow Victors and we would expect a nonlinear response equal to my old coast formula.

For the JAG, the L/R is large relative to the PWM period. If the current cannot decay to zero during the “off” phase, it will continue to accumulate until the average current stabilizes. Since the current never gets below zero we can consider the problem as the superposition of a steady state Vemf and a pulsed 12v. And this leads us to the linear equation = (12*duty -Vemf)/R .

SOOOO…I think the two formulas are ok but now it would be due to the 15khz JAG vs the slow Victors. I didn’t see this in my previous excel because I assumed the steady state current was heading towards zero in the “off” state instead of -Vemf/R.

TODO: rerun excel with revised off current and see if I can verify the above
Stay tuned again. I’m determined to collect my beers:)

Chris,
The diodes only conduct when the EMF is higher than 2.5 volts above the battery voltage. This will only occur (theoretically) during the inductive spike. The EMF is lower than the applied voltage except if the motor is supplied mechanical speed at greater than the applied voltage would produce. You also want to consider that the current only flows when a circuit is closed. Once the diodes stop conducting, there is no where for the current to flow. Open circuit voltage rules apply, even though the difference is small. I think that actually works in your favor if you are considering high impedance voltage monitoring. I have no specifications on the inductance of the motors. However the L/R equations go out the window with no current flow don’t they?

Well, my assumption is that during the “off” phase the inductive spike keeps the voltage high enough to turn on the diodes. This condition remains until the current goes to zero at which time we have an open ckt condition with no current. If the current does not make it to zero before the next “on” pulse then a closed ckt was there for the whole off phase.

I am not fooling with the diode drops yet because I think they are secondary effects. I also think there is only one diode in the picture, since it looks like they keep the lowside FET in ON state and feed the pwm pulse to the High side FET on the other side of the motor.

I will probably wind up just doing a simple hbridge simulation and run it.

Chris the diodes only conduct when the forward bias is high enough to turn them on. As soon as the bias falls below the 1.25 volts per diode, they stop conducting. Remember that the diodes are also back biased by the battery so the motor EMF must be higher than the battery voltage.

OK, finished my TODO and have verified that linearity is indeed due to the higher frequency of the JAG. Based upon my quoted rationale we can show that

120Hz Victor v_emf = 12 - i_free*R/duty…varies with 1/duty

15kHz Jag v_emf = 12duty - i_freeR …varies with duty

The 2kHz Victor is very close to the Jag.

I wrote a LABVIEW simulation (see attch hbridge.vi) of a one sided Hbridge and the curves (see attch thumbnail) verify what we are seeing. As Al says, this is independent of coast or brake mode however, with the JAG, the “off” ckt is essentially the brake mode since the diode is always conducting…the only difference is for the voltage drop across the diode. This is why I did not see any non spike Vemf in the JAG waveform …only duty cycle variations.

Feel free to run the program and vary the inductance to see its effects. I used a nominal 120uh which is close to what people have measured in the past. I think the max posted was 230uh.

I wonder what all this is worth? Since I have not seen this mentioned in any of the Hbridge tutorials maybe I’ll publish a paper. Lets see…what should I call it. How about

“Special Theory of Nonlinearity: An Inconvient Truth of Low Hz Hbridges”.

Maybe the good folks in Stockholm are reading ChiefDelphi threads:)
Well, it might be worth a minor entry to Wikipedia under Hbridge theory
or under alternative ways to spend time when Friday night TV is on.

Erick…put those beers on ice…assuming Al doesn’t send me back to the showers again.

RIP thread ;

Hbridge.vi (35.1 KB)
Motor Speed Graph.JPG


Hbridge.vi (35.1 KB)
Motor Speed Graph.JPG

RIP thread ;

Maybe not so fast :o.

We programmers now are dying to know how we can save ticks and optimize everything now.

Would it be prudent to suggest we can take these results, and figure out a minimum PWM frequency that will give us a “linear” response for all of our FRC motors?

And another question, a Jaguar will accept a 120Hz PWM signal, and if it does, will it behave in the same non-linear fashion as the Victors?

The pwm frequency that is being discussed here is the output of the speed controller and is completely independent from the input.

OK,
I thought it was time to make a chart, so here is a spreadsheet and chart. I took the values that have been mentioned here although they are not taken from published data. In calculating motor current, I simply took the motor winding resistance and stated inductance and plotted the result against duty cycle. Please note that I also multiplied the 15kHz values by 10 so that the current would at least approximate the current accumulated over the same time interval. The table certainly has a telling tale to tell in comparing duty cycle ON time with inductance rise time.
Note that this table and chart do not take into account the switching frequency of the commutator or the dead band in between segments. Nor does it make an attempt to average current. It merely is comparing the max current that could be achieved during the 150 Hz ON time period due to motor winding resistance and inductance. Please note that the 100% duty cycle 150 Hz switching frequency does approximate the published 133 amp stall current of the CIM.
Although the 15kHz current does look linear, please note that the plot is merely in a linear region of the same type of curve do to the stretched time base of the horizontal axis. The values are real though. At 15kHz, the motor current cannot rise to near max values even at 100% duty cycle due to the L/R time constant vs input frequency.
Remember that series wiring resistance, controller Rdson resistance, battery voltage and many other variables will serve to change these values.

motorcurrent.xls (41.5 KB)


motorcurrent.xls (41.5 KB)