## code to change the motor amp limit

General topics and discussions about the VESC and its development.
devin
Posts: 255
Joined: 08 May 2017, 01:55
Location: San Francisco, California, US

### Re: code to change the motor amp limit

rew wrote:A full sine cycle is 2*pi. So a third of that is 2/3 PI

Phase A is energized with the voltage: Va = Vs * sin (f * t + 0*2/3PI);
Phase B is energized with the voltage: Vb = Vs * sin (f * t + 1*2/3PI);
Phase C is energized with the voltage: Vc = Vs * sin (f * t + 2*2/3PI);

here Vs is the "duty cycle" dependent voltage scale. and f is the RPM (in the proper units).

Now the question is: what does it mean that a phase is energized with a voltage: We can only drive either to V+ or to V-?

Well, when the target voltage is 0, we alternate the highside and the lowside switch in a 50/50 fashion. 50% PWM. So now by varying the PWM percentage we can apply (effective) voltages anywhere between -Vbat/2 to +Vbat/2.

@rew For arguments sake, let's imagine in the following diagram showing a wye-wound motor that at a particular time mosfets D, B & C are ON leading to voltage across all 3 wye phases simultaneously:

Now we swap out the wye-wound motor for a delta-wound motor:

^Now, with the delta motor, even though mosfets D, B & C are ON, now there is no voltage across one of the 3 phases (bottom phase).

So @rew, please correct me if I am wrong, but by extension of logic you are basically saying that in BLDC mode 2/3rds Wye phases and 3/3rds Delta phases become energized simultaneously, but when in FOC mode, 3/3rds Wye phases and 2/3rds Delta phases become energized simultaneously.

@Rew can you please confirm that in FOC mode, only 2/3rds of the phases in a delta-wound motor become simultaneously energized, as opposed to in BLDC mode when all 3/3rds of the phases in a delta-wound motor become simultaneously energized?

---------------------------

Where:

Red Area = Phase "A" -- Energized
Green Area = Phase "B" -- Energized
Blue Area = Phase "C" -- Energized
Black Line = 12 Pole Wye Stator Magnetic Field Vectors w/ 3 Energized Phases
White Line = 14 Pole Rotor Magnetic Field Vectors

---------------------------

Where:

Red Area = Phase "A" -- Energized
Green Area = Phase "B" -- Energized
Blue Area = Phase "C" -- Not Energized
Black Line = 12 Pole Wye Stator Magnetic Field Vectors w/ 2 Energized Phases
White Line = 14 Pole Rotor Magnetic Field Vectors

Last edited by devin on 12 Jul 2017, 19:53, edited 1 time in total.

rew
Posts: 943
Joined: 25 Mar 2016, 12:29
Location: Delft, Netherlands.

### Re: code to change the motor amp limit

devin wrote:@Rew can you please confirm that in FOC mode, only 2/3rds of the phases in a delta-wound motor become simultaneously energized, as opposed to in BLDC mode when all 3/3rds of the phases in a delta-wound motor become simultaneously energized?
NO I cannot confirm that. It is not true.

If we start out with:
Phase A is energized with the voltage: Va = Vs * sin (f * t + 0*2/3PI);
Phase B is energized with the voltage: Vb = Vs * sin (f * t + 1*2/3PI);
Phase C is energized with the voltage: Vc = Vs * sin (f * t + 2*2/3PI);
and take Vs to be the battery voltage, say if the battery voltage is 20V, then Vs is 10V and f = 1. Now we can pick a random time. Say 0.2. So we get: Va = 10 sin (0.1) = 2.0V. Vb = 7.5V, Vc = -9.5V. To achieve this, leg A is set to PWM at (10V+2V/20V = 60%. Leg B PWMs at 87.5% and leg C at 2.5%.

Now with classical PWM when the timer rolls over, all signals are turned on. All highside fets go on. Then at 2.5% into the period, leg C goes low. Then at 60% leg A goes low. and finally at 87% leg C goes low. So in this case there is a 2.5% of the time that all highside fets are on, and 12.5% of the time all lowside fets are on. But the effective voltage on the A-leg is simply 60%*20V-10V = +2V.

devin
Posts: 255
Joined: 08 May 2017, 01:55
Location: San Francisco, California, US

### Re: code to change the motor amp limit

after doing some motor simulations today, I have some new predictions (i'll try to provide some supporting evidence in the next day or so)

wye 100kv -> wye 173.205kv
1 ohm -> 0.33 ohm
100 turns -> 57.73 turns
1 cross section -> 1.73205 cross section
33.33% copper fill -> 33.33% copper fill
1 copper volume -> 1 copper volume
100 unit torque per amp -> 57.73 unit torque per amp

wye 100kv -> wye 173.205kv
1 ohm -> 0.33 ohm
100 turns -> 33.33 turns
1 cross section -> 1 cross section
33.33% copper fill -> 11.11% copper fill
1 copper volume -> 0.33 copper volume
100 unit torque per amp -> 33.33 unit torque per amp

wye 100kv -> wye 173.205kv
1 ohm -> 0.33 ohm
100 turns -> 100 turns
1 cross section -> 3 cross section
33.33% copper fill -> 99.99% copper fill
1 copper volume -> 3 copper volume
100 unit torque per amp -> 100 unit torque per amp

wye 100kv -> delta 173.205kv
1 ohm -> 0.33 ohm
100 turns -> 100 turns
1 cross section -> 1 cross section
33.33% copper fill -> 33.33% copper fill
1 copper volume -> 1 copper volume
100 unit torque per amp -> 57.73 unit torque per amp

rew
Posts: 943
Joined: 25 Mar 2016, 12:29
Location: Delft, Netherlands.

### Re: code to change the motor amp limit

Proper science means you formulate a hypothesis that predicts the outcome of measurements. Right?
I predict your motor 1 will end up with 173Kv, same as you.
I predict your motor 2 will end up with 300Kv.
I predict your motor 3 will end up with 100Kv.
I predict your motor 4 will end up with 173Kv. (same as you) (added later: missed the 4th motor first time).

devin
Posts: 255
Joined: 08 May 2017, 01:55
Location: San Francisco, California, US

### Re: code to change the motor amp limit

rew wrote:Proper science means you formulate a hypothesis that predicts the outcome of measurements. Right?
I predict your motor 1 will end up with 173Kv, same as you.
I predict your motor 2 will end up with 300Kv.
I predict your motor 3 will end up with 100Kv.

@rew are you saying it is possible to have the same kv & kt values when km changes? in example #2 and #3, my understanding is km (motor size constant) necessarily changes when the copper volume changes.

devin wrote:...after doing some motor simulations today...

devin wrote:turns_per_coil = 50.0 # Number of turns per coil
airgap_diameter = 0.092 m # Airgap diameter
axial_length = 0.1 m # Machine length
innercoil = Copper # Copper
conductor_length = 0.125279348886 m # Average conductor length
coils_per_phase = 2.0 # Number of coils per phase
slot_opening_depth = 0.002 m # Slot opening depth
parallel_paths = 1 # 1
inneriron = Hiperco 50 Alloy (0.15mm) # Hiperco 50 Alloy (0.15mm)
slot_pitch = 0.0238237442897 m # Slot pitch
slot_depth = 0.02 m # Slot depth
conductor_temp = 310 K # Temperature of conductors
frequency = 0.021 Hz # Electrical frequency
magnet_thickness = 0.00635 m # Magnet thickness
slot_width = 0.01 m # Slot width
speed = 0.003 1/s # Mechanical speed
magnet_width = 0.0127 m # Magnet width
tooth_tip_angle = 0 rad # Tooth tip angle
outer = SMPMrectangular_OR # Surface-mounted rectangular magnets
slot_width_inner = 0.00807491743977 m # Inner slot width
outer_yoke_height = 0.00176988634241 m # Rotor yoke height
coil_span = 1.0 # Coil span in slot pitches
outer_diameter = 0.11 m # Rotor outer diameter
inner = ParallelTeeth_IS # Parallel teeth
inner_diameter = 0.091 m # Stator outer diameter
inner_yoke_height = 0.0155 m # Stator yoke height
iDC = 60 A # DC current
fill_factor = 0.99 # Slot fill factor
shaft_diameter = 0.02 m # Shaft diameter
inner_stacking_factor = 1.0 # Stator iron stacking factor
tooth_width = 0.0054 m # Tooth width
coils_per_parallelpath = 2.0 # Number of coils per parallel path
outerpm = N45 # N45
outer_inside_diameter = 0.093 m # Inner rotor diameter
topology = outerSMPM # Surface-mounted permanent magnet machine with outer rotor
outeriron = Arnon 5 (Non Grain Oriented Silicon Steel) # Arnon 5 (Non Grain Oriented Silicon Steel)
number_of_layers = 1.0 # Number of winding layers
number_of_slots = 12.0 # Number of slots
q = 0.285714285714 # Number of slots/pole/phase
outer_stacking_factor = 1.0 # Rotor iron stacking factor
slot_width_outer = 0.0177210294773 m # Outer slot width
number_of_conductors = 1.0 # Number of conductors per slot
airgap_thickness = 0.001 m # Airgap thickness
number_of_poles = 14.0 # Number of poles
slot_opening = 0.0002 m # Slot opening width

devin
Posts: 255
Joined: 08 May 2017, 01:55
Location: San Francisco, California, US

### Re: code to change the motor amp limit

rew wrote:The C phase is, in BLDC mode only, not energized.

devin wrote:@rew If it's so that phase C is energized simultaneously with phase A & B in a wye-wound motor in FOC mode (but not in BLDC mode)... in the following diagram, exactly which mosfets would be ON to permit this all-3-phase-wye-winding energized state?

devin wrote:@rew For arguments sake, let's imagine in the following diagram showing a wye-wound motor that at a particular time mosfets D, B & C are ON leading to voltage across all 3 wye phases simultaneously:

devin wrote:Now we swap out the wye-wound motor for a delta-wound motor:

devin wrote:^Now, with the delta motor, even though mosfets D, B & C are ON, now there is no voltage across one of the 3 phases (bottom phase).

devin wrote:@Rew can you please confirm that in FOC mode, only 2/3rds of the phases in a delta-wound motor become simultaneously energized, as opposed to in BLDC mode when all 3/3rds of the phases in a delta-wound motor become simultaneously energized?

rew wrote:NO I cannot confirm that. It is not true.

If we start out with:
Phase A is energized with the voltage: Va = Vs * sin (f * t + 0*2/3PI);
Phase B is energized with the voltage: Vb = Vs * sin (f * t + 1*2/3PI);
Phase C is energized with the voltage: Vc = Vs * sin (f * t + 2*2/3PI);
and take Vs to be the battery voltage, say if the battery voltage is 20V, then Vs is 10V and f = 1. Now we can pick a random time. Say 0.2. So we get: Va = 10 sin (0.1) = 2.0V. Vb = 7.5V, Vc = -9.5V. To achieve this, leg A is set to PWM at (10V+2V/20V = 60%. Leg B PWMs at 87.5% and leg C at 2.5%.

Now with classical PWM when the timer rolls over, all signals are turned on. All highside fets go on. Then at 2.5% into the period, leg C goes low. Then at 60% leg A goes low. and finally at 87% leg C goes low. So in this case there is a 2.5% of the time that all highside fets are on, and 12.5% of the time all lowside fets are on. But the effective voltage on the A-leg is simply 60%*20V-10V = +2V.

@rew For argument's sake, here is a graph from someone in a different thread who is running a brushed motor in DC mode... note that only 2 leads run between the vesc and the motor... from the following graph we can see that all 3 "phases" are involved in sending power through just 2 dc motor wires.... so I am still having a lot of trouble believing all 3 wye phases are simultaneously energized in the motor itself.

^@rew Simply based on the evidence I have so far seen, including the above user-submitted graph, it would appear that when "3 phases" are energized simultaneously on a vesc, it results in power through only 2 out of 3 of the motor wires, i think -- which by extension of logic would result in 2/3rds of a wye-wound motor's phases being energized simultaneously, even in FOC mode.

rew
Posts: 943
Joined: 25 Mar 2016, 12:29
Location: Delft, Netherlands.

### Re: code to change the motor amp limit

Let me try to put it this way.
A coil is an electric component that carries current and only changes that current in response to a voltage.So in theory you could short a coil and the current will keep on running forever. In fact, that's what they do for the superconducting magnets in MRI machines.

A coil of a motor is not energized by voltage, but by current. You may need a voltage to start that current running, but when things are near-perfect, the voltage can be zero and a current is maintained.

So when we start 1A, 2A and -3A running into the three leads of the motor, to keep that current running we only need to keep the voltages close to zero. Now in reality we don't have superconducting coils or ideal mosfets. So SOME voltage is required to maintain that state. But in electronics it is difficult to generate say 1V on the motor from a 50V battery voltage. The good news is that 50V 2% of the time is equivalent to 1V 100% of the time. It has almost exactly the same effect.

devin
Posts: 255
Joined: 08 May 2017, 01:55
Location: San Francisco, California, US

### Re: code to change the motor amp limit

rew wrote:Let me try to put it this way.
A coil is an electric component that carries current and only changes that current in response to a voltage.So in theory you could short a coil and the current will keep on running forever. In fact, that's what they do for the superconducting magnets in MRI machines.

A coil of a motor is not energized by voltage, but by current. You may need a voltage to start that current running, but when things are near-perfect, the voltage can be zero and a current is maintained.

So when we start 1A, 2A and -3A running into the three leads of the motor, to keep that current running we only need to keep the voltages close to zero. Now in reality we don't have superconducting coils or ideal mosfets. So SOME voltage is required to maintain that state. But in electronics it is difficult to generate say 1V on the motor from a 50V battery voltage. The good news is that 50V 2% of the time is equivalent to 1V 100% of the time. It has almost exactly the same effect.

rew wrote:The C phase is, in BLDC mode only, not energized.

@Rew -- starting off at the point where we are both still in agreement -- in BLDC mode 2/3rds of the wye-wound motor phases are energized at any given time via 2/3rds of the motor wires...

For Illustration, MOSFETS A & F ON in the following diagram (& inductive recirculation via mosfets D & F):

Where:

Red Area = Phase "A" -- Energized
Green Area = Phase "B" -- Energized
Blue Area = Phase "C" -- Not Energized
Black Line = 12 Pole Wye Stator Magnetic Field Vectors w/ 2 Energized Phases
White Line = 14 Pole Rotor Magnetic Field Vectors

Question: If one is operating a wye-wound motor in BLDC mode on a VESC (which we agree should only have current in 2/3rds phases at any given time)...

If one opens the current plot for the above example, does it visually indicate:

A) Current in 2/3rds phases at any given time

or

B) Current in 3/3rds phases at any given time

??

My working theory to account for this discrepancy is maybe the VESC "thinks of" all motors as 3 phase full bridge AC powered motors for calculation purposes, and then applies a final conversion/adjustment factor to those calculations as a final invisible step before sending power to the motor to adjust for the physical reality that the motor attached is a BLDC motor not a 3-phase-AC-source powered full-bridge AC motor.

Delta Version:

Where:

Red Area = Phase "A" -- Energized
Green Area = Phase "B" -- Energized
Blue Area = Phase "C" -- Energized
Black Line = 12 Pole Wye Stator Magnetic Field Vectors w/ 3 Energized Phases
White Line = 14 Pole Rotor Magnetic Field Vectors

Last edited by devin on 12 Jul 2017, 19:54, edited 1 time in total.

devin
Posts: 255
Joined: 08 May 2017, 01:55
Location: San Francisco, California, US

### Re: code to change the motor amp limit

rew wrote:The C phase is, in BLDC mode only, not energized.

devin wrote:@Rew -- starting off at the point where we are both still in agreement -- in BLDC mode 2/3rds of the wye-wound motor phases are energized at any given time via 2/3rds of the motor wires...

devin wrote:Question: If one is operating a wye-wound motor in BLDC mode on a VESC (which we agree should only have current in 2/3rds phases at any given time)...

If one opens the current plot for the above example, does it visually indicate:

A) Current in 2/3rds phases at any given time

or

B) Current in 3/3rds phases at any given time

??

My working theory to account for this discrepancy is maybe the VESC "thinks of" all motors as 3 phase full bridge AC powered motors for calculation purposes, and then applies a final conversion/adjustment factor to those calculations as a final invisible step before sending power to the motor to adjust for the physical reality that the motor attached is a BLDC motor not a 3-phase-AC-source powered full-bridge AC motor.

Some supporting evidence for this theory from wiki: https://en.wikipedia.org/wiki/Vector_control_%28motor%29:

https://en.wikipedia.org/wiki/Vector_control_%28motor%29 wrote:Projections associated with the (d,q) coordinate system typically involve:[19][22][23]

Forward projection from instantaneous currents to (a,b,c) complex stator current space vector representation of the three-phase sinusoidal system.
Forward three-to-two phase, (a,b,c)-to-( α \alpha , β \beta ) projection using the Clarke transformation. Vector control implementations usually assume ungrounded motor with balanced three-phase currents such that only two motor current phases need to be sensed. Also, backward two-to-three phase, ( α \alpha , β \beta )-to-(a,b,c) projection uses space vector PWM modulator or inverse Clarke transformation and one of the other PWM modulators.
Forward and backward two-to-two phase,( α \alpha , β \beta )-to-(d,q) and (d,q)-to-( α \alpha , β \beta ) projections using the Park and inverse Park transformations, respectively.

However, it is not uncommon for sources to use three-to-two, (a,b,c)-to-(d,q) and inverse projections.

While (d,q) coordinate system rotation can arbitrarily be set to any speed, there are three preferred speeds or reference frames:[16]

Stationary reference frame where (d,q) coordinate system does not rotate;
Synchronously rotating reference frame where (d,q) coordinate system rotates at synchronous speed;
Rotor reference frame where (d,q) coordinate system rotates at rotor speed.

Decoupled torque and field currents can thus be derived from raw stator current inputs for control algorithm development.[24]

Whereas magnetic field and torque components in DC motors can be operated relatively simply by separately controlling the respective field and armature currents, economical control of AC motors in variable speed application has required development of microprocessor-based controls[24] with all AC drives now using powerful DSP (digital signal processing) technology.[25]

devin
Posts: 255
Joined: 08 May 2017, 01:55
Location: San Francisco, California, US