0% found this document useful (0 votes)
26 views24 pages

Sensored Hall Effect Sensor Based Field Oriented Control of Three Phase BLDC Motor Using dsPIC33CK DS00004064

The document describes the implementation of a Hall effect sensor-based field oriented control algorithm for three-phase brushless DC motors using a dsPIC33CK microcontroller. The FOC algorithm uses Hall sensors to determine rotor position and implements decoupling of torque and flux control similar to a DC motor. Block diagrams and explanations of the FOC process are provided.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views24 pages

Sensored Hall Effect Sensor Based Field Oriented Control of Three Phase BLDC Motor Using dsPIC33CK DS00004064

The document describes the implementation of a Hall effect sensor-based field oriented control algorithm for three-phase brushless DC motors using a dsPIC33CK microcontroller. The FOC algorithm uses Hall sensors to determine rotor position and implements decoupling of torque and flux control similar to a DC motor. Block diagrams and explanations of the FOC process are provided.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

AN4064

Sensored (Hall Effect Sensor-Based) Field Oriented Control


of Three-Phase BLDC Motor Using dsPIC33CK
Author: Maria Loida Canada

Introduction
The construction of modern BLDC motors allows them to be controlled like permanent magnet synchronous motors.
This means that a sophisticated technique called Field Oriented Control (FOC) is also applicable to BLDC motors. The
FOC algorithm is useful in the applications that require fast dynamic response with independent control of torque and
flux. Sensor-based FOC is advantageous for providing rotor position at slower speeds.
This application note describes the implementation of a Hall effect sensor-based FOC algorithm for three-phase BLDC
motors using Microchip Technology's 16-bit dsPIC33CK DSC’s. The mathematical computations and transformations
are performed by the DSP engine, while the on-chip peripherals, such as PWM, SCCP, op amps, Comparator with DAC,
simplify the implementation and reduce the overall system components. The following figure shows the block diagram
of the solution.

FIGURE 1: SYSTEM BLOCK DIAGRAM

PWM 1
3-Phase
PWM 2 Inverter Motor
Reference ADC17
FIRMWARE Bridge
Speed
PWM 3

Overcurrent Current Ia
Signal
ADC19 ADC0
CMP1
+ - +
OP-AMP1 Current
Temperature Sense Ia
Sensor
-

DAC
Current Ib
+
ADC1 OP-AMP2 Current
VBUS/16 ADC15 Sense Ib
-

Timer Hall A
Count Hall Sensors
State Hall B
SCCP3 GPIO
Hall C

 2021 Microchip Technology Inc. DS00004064A-Page 1


AN4064
1.0 FIELD ORIENTED CONTROL IN SENSORED BLDC
Field Oriented Control is a commutation method that keeps the rotor and stator magnetic fields at 90 degrees under all
conditions, enabling maximum torque generation from the motor and regulation of speed/torque under changing load
conditions. It deals with the fluxes (stator, rotor or air-gap). One of those is used as a reference frame for all other
quantities with the purpose of decoupling the torque- and flux- producing components of current. The decoupling
ensures the ease of control of the three-phase motor, similar to the DC motor with separate excitation. This means that
the armature current is responsible for the torque generation, and the excitation current is responsible for the flux
generation. In this application, the rotor flux is used as a reference frame.
The air-gap flux is equal to the sum of the rotor's flux linkage, which is generated by the permanent magnets plus the
armature reaction flux linkage generated by the stator current. The air-gap flux for this motor is smooth, and the Back
Electromagnetic Force (BEMF) is sinusoidal. This control scheme is created for the sensored BLDC motor that is used
as a hub motor in electric scooters. The motor's transversal section is shown in the following figure.

FIGURE 2: MOTOR’S TRANSVERSAL SECTION

For applications requiring precise control or high torque generation at low motor speeds, sensored control is preferred.
In the sensored FOC implementation, rotor position and speed are determined using an encoder, resolver or Hall effect
sensors. This application note describes the Hall sensor-based implementation with the target application in driving
electric scooter hub motors.

DS00004064A-Page 2  2021 Microchip Technology Inc.


AN4064
2.0 BLOCK DIAGRAM OF SENSORED FOC

FIGURE 3: FOC BLOCK DIAGRAM

ʘref Iqref Vq Vɲ Ia
+- +- d,q
Inverse 3-Phase
PI PI Clarke Ib Motor
Inverter
Transform
Idref Vd Vɴ and SVM Bridge
+- Ic
ɲ,ɴ
PI
੓e Inverse
Park
Transform
Iq d,q Iɲ ɲ,ɴ

Id Iɴ
ɲ,ɴ A,B
Electrical
Position Park Clarke
(੓e) Transform Transform
Hall A
Position and Hall B
Speed (ʘ) Speed
Hall C

Software Hardware

The control process in the previous figure can be summarized as follows:


• The three-phase stator currents are measured. For a motor with balanced three-phase windings, only two phase
currents are sufficient to be measured. The third current is calculated using the following equation: ia + ib + ic = 0.
• Clarke Transform: The three-phase currents are converted to a stationary two-axis system. The conversion pro-
vides the variables iα and iß from the measured ia and ib values. The values iα and iß are time varying quadrature
current values as viewed from the perspective of the stator.
• Park Transform: The stationary two-axis coordinate system is rotated to align with the rotor flux using a transfor-
mation based on the angle measured at the last iteration of the control loop. This conversion provides the id and iq
variables from iα and iß. The variables id and iq are the quadrature currents transformed to the rotating coordinate
system. For steady state conditions, id and iq are constant.
• Reference values of currents are defined as follows;
- id reference: controls rotor magnetizing flux
- iq reference: controls the torque output of the motor
• The error signals are fed to PI controllers. The output of the controllers provide vd and vq, which are the voltage
vectors that will be applied to the motor.
• A new transformation angle is measured and calculated based on the Hall sensor’s state. The new angle guides
the FOC algorithm as to where to place the next voltage vector.
• Inverse Park Transform: The vd and vq output values from the PI controllers are rotated back to the stationary ref-
erence frame using the new angle. This calculation provides the succeeding quadrature voltage values vα and vβ.
• Inverse Clarke Transform and SVM: The vα and vß values are used to calculate the new PWM duty cycle values,
which will generate the desired voltage vector.
• The speed (ω) is calculated with every Hall state change, which happens after every discrete PWM cycle.
The FOC firmware is implemented in the ADC Interrupt Service Routine (ISR), which runs at the same rate as the PWM
switching frequency.

 2021 Microchip Technology Inc. DS00004064A-Page 3


AN4064
3.0 FLOWCHART OF SENSORED FOC
The flowchart in the following figure shows the equivalent sequential routine of the FOC in software, and the change
notification routine used for measuring the speed and rotor position. The complete source code of the solution can be
found in Appendix A: “Source Code Listing”.

FIGURE 4: FLOWCHART

DS00004064A-Page 4  2021 Microchip Technology Inc.


AN4064
4.0 PI CONTROLLER

4.1 PI Controller Background


A complete discussion about the Proportional Integral (PI) controllers is beyond the scope of this document. However,
this section provides some basics of PI operation.
A PI controller responds to an error signal in a closed control loop, and attempts to adjust the controlled quantity to
achieve the desired system response. The controlled parameter can be any measurable system quantity, such as speed
or flux. The benefit of the PI controller is that it can be adjusted empirically by varying one or more gain values and
observing the change in the system response.
A digital PI controller is executed at a periodic sampling interval. It is assumed that the controller is executed frequently,
hence the system can be controlled. The error signal is formed by subtracting the desired setting of the parameter to be
controlled from the actual measured value of that parameter. The sign of the error indicates the direction of change
required by the control input.
The Proportional (P) term of the controller is formed by multiplying the error signal by a 'P' gain, causing the PI controller
to produce a control response, which is a function of the error magnitude. As the error signal becomes larger, the 'P'
term of the controller becomes larger to provide more correction.
The effect of the 'P' term tends to reduce the overall error as time elapses. However, the effect of the 'P' term diminishes
as the error approaches zero. With proportional control, in most systems, the error of the controlled parameter gets very
close to zero but does not converge. The result is a small remaining steady state error.
The Integral 'I' term of the controller is used to eliminate small steady state errors. The 'I' term calculates a continuous
running total of the error signal. Therefore, a small steady state error accumulates into a large error value over time.
This accumulated error signal is multiplied by an 'I' gain factor and becomes the 'I' output term of the PI controller.

4.2 Adjusting PI Gains


The 'P' gain of a PI controller sets the overall system response. To tune the controller, set the 'I' gain to zero. Then,
increase the 'P' gain until the system responds to set point changes without excessive overshoot or oscillations. Using
lower values of 'P' gain will slowly control the system, while higher values will give aggressive control. At this point, the
system will probably not converge to the set point.
After a reasonable 'P' gain is selected, slowly increase the 'I' gain to force the system error to zero. Only a small amount
of 'I' gain is required in most systems. The effect of the 'I' gain, if large enough, can overcome the action of the 'P' term,
slow the overall control response and cause the system to oscillate around the set point. If oscillation occurs, reducing
the 'I' gain and increasing the 'P' gain will usually solve the problem.
This application includes a term to limit the integral windup, which occurs if the integrated error saturates the output
parameter. Any further increase in the integrated error does not affect the output. The accumulated error, when it does
decrease, will have to fall (or unwind) to below the value that caused the output to saturate.
There are three PI control loops used to control the three interactive variables in this application. The outer loop controls
the rotor speed; the two inner loops control the rotor flux and the motor torque, respectively.

 2021 Microchip Technology Inc. DS00004064A-Page 5


AN4064
5.0 COORDINATE TRANSFORMS
Through a series of coordinate transforms, users can indirectly determine and control the time invariant values of torque
and flux with classic PI control loops. The process begins by measuring the 3-phase motor currents. In practice, the
instantaneous sum of the three current values is zero due to the balance phase windings. Therefore, by measuring only
two of the three phase currents, the third will be determined, which reduces hardware costs by eliminating the need for
the third current sensor.

5.1 Clarke Transform


The Clarke Transform transforms the quantities from the three-axis, two-dimensional coordinate system referenced to
the stator, to a two-axis stationary coordinate system.

FIGURE 5: CLARKE TRANSFORM

5.2 Park Transform


The Park Transform transforms the quantities from the two-axis stationary coordinate system to a two-axis rotating
coordinate system that rotates with the rotor flux. Theta is the angle of the rotor flux from the stationary reference frame.

FIGURE 6: PARK TRANSFORM

DS00004064A-Page 6  2021 Microchip Technology Inc.


AN4064
5.3 Inverse Park Transform
The Inverse Park Transform transforms the quantities from the to the two-axis rotating coordinate system that rotates
with the rotor flux, to a two-axis stationary coordinate system.

FIGURE 7: INVERSE PARK TRANSFORM

5.4 Inverse Clarke Transform


The Inverse Clarke Transform transforms the quantities from a two-axis stationary coordinate system to a three-axis,
two-dimensional coordinate system referenced to the stator. The alpha and beta axes are interchanged from that of a
conventional Inverse Clarke transform to simplify the SVPWM implementation, which will be further discussed in the
next section.

FIGURE 8: INVERSE CLARKE TRANSFORM

 2021 Microchip Technology Inc. DS00004064A-Page 7


AN4064
6.0 SPACE VECTOR PULSE WIDTH MODULATION (SVPWM)
The final step in the vector control process is to generate pulse-width modulation signals for the 3-phase motor voltages.
If the Space Vector Modulation (SVM) technique is used, the process of generating the pulse width for each of the three
phases is reduced to a few simple equations. In this implementation, the Inverse Clarke Transform is folded into the
SVM routine, which further simplifies the calculations.
Each of the three inverter outputs can be in one of two states. The inverter output can be connected to either the plus
(+) bus rail or the minus (-) bus rail, which allows for 23 = 8 possible states of the output.
The two states in which all three outputs are connected to either the plus (+) bus or the minus (-) bus are considered
null states because there is no line-to-line voltage across any of the phases. These are plotted at the origin of the SVM
star. The remaining six states are represented as vectors with a 60-degree phase difference between the adjacent
states.

FIGURE 9: SPACE VECTORS OF THREE-PHASE INVERTER

The process of SVM allows the representation of any resultant vector by the sum of the components of the two adjacent
vectors. In the figure below, UOUT is the desired resultant. It lies in the sector between U60 and U0. If during a given
PWM period T, U0 is output for T1 / T and U60 is output for T2 / T, the resulting voltage for the period T will be UOUT.

FIGURE 10: AVERAGE SVPWM

T0 represents a time where no effective voltage is applied into the windings; i.e., where a null vector is applied. The
values for T1 and T2 can be extracted with no extra calculations by using a modified Inverse Clarke transformation. If
Vα and Vβ are reversed, a reference axis is generated that is shifted by 30 degrees from the SVM star. As a result, for
each of the six segments, one axis is exactly opposite that segment and the other two axes symmetrically bound that
segment. The timings of the vector components along those two bounding axes are equal to T1 and T2. The null vectors
are applied in the remaining time T0 of the switching period T.

DS00004064A-Page 8  2021 Microchip Technology Inc.


AN4064
The dsPIC DSC is configured in the center-aligned PWM, which produces the symmetrical pulse pattern as shown in
the following figure. This configuration reduces the ripple current while minimizing the switching losses in the power
device.

FIGURE 11: PWM SIGNALS FOR PERIOD T

 2021 Microchip Technology Inc. DS00004064A-Page 9


AN4064
7.0 SENSORED IMPLEMENTATION OF POSITION AND SPEED MEASUREMENT
An important part of the algorithm is how to calculate the rotor angle needed for the FOC. This section of the application
note explains the process of estimating the rotor angle (ϴ) and motor speed (ω). The sensored control technique
estimates those parameters from the information obtained from the discrete states of the Hall sensor inputs.
The block diagram of the position and speed measurement is shown in the following figure. The sensored technique
uses the GPIO and SCCP (Capture/Compare/PWM/Timer) peripherals. The GPIO with Change Notification feature is
configured with mismatch style, which means that it detects changes from the last port read. The SCCP peripheral is
configured into Timer mode, using the FCY Clock of 100 MHz and prescaler of 64. The SCCP Timer period is based on
the minimum motor speed to avoid overflow and accommodate the maximum period.

FIGURE 12: POSITION AND SPEED MEASUREMENT DIAGRAM

Whenever the motor rotates, there is a Hall state change, which happens every 60 electrical degrees, the Change
Notification ISR (CN_ISR()) is serviced. Within the ISR, the Hall sensor’s state is read, and the rotor sector is calculated.
The interrupt event also measures the timer count of the SCCP Timer between subsequent interrupts.
The following figure illustrates the Hall states and its changes that trigger the interrupt events. The period calculation is
done by measuring the current timer count (ActualCapture) and subtracting it from the previous timer count
(PastCapture). The calculated period is filtered using the moving average filtering method. The moving average filtering
method is optimal for reducing random noise while maintaining a sharp response. It is done by getting multiple period
samples at a time, and taking the average of those to produce a single output point. The average period is used in
calculating the rotor position, while the raw calculated period is passed to the speed calculation routine.

DS00004064A-Page 10  2021 Microchip Technology Inc.


AN4064
FIGURE 13: TIMER COUNT CAPTURE FOR PERIOD CALCULATION

7.1 Position Measurement


It is important to know the accurate rotor position for the FOC to work correctly. The low-resolution discrete inputs from
the Hall effect sensor states would not be sufficient for the FOC because it requires a higher angle resolution to properly
execute the control.
The rotor sector is needed to properly get the rotor sector phase value. Rotor sector is the absolute position of the rotor,
in electrical degrees, in 60-degree steps. That information is obtained by reading the digital value from the three Hall
effect sensors. There are six valid sectors that are assigned with corresponding phase values in signed integer format.
The values are tabulated in the following table with the corresponding Hall state and sector number.

TABLE 1: RELATIONSHIP OF SECTOR TO ANGULAR POSITION


Hall C Hall B Hall A Sector Reference Phase Value
0 0 0 Invalid Invalid
1 1 0 6 32767
0 1 0 2 -21844
0 1 1 3 -10922
0 0 1 1 0
1 0 1 5 10922
1 0 0 4 21844
1 1 1 Invalid Invalid
The phase values serve as references to calculate the high-resolution transformation angle. The reference phase value
based on the sector is acquired with every change notification interrupt event, while the calculation of the transformation
angle is done in ADC_ISR(). The reference phase value is initially loaded to the transformation angle within the
CN_ISR(), given by the following equation.

EQUATION 1: INITIAL TRANSFORMATION ANGLE

The _90_Degrees_Phase_Offset keeps the stator and rotor flux at 90 degrees from each other. It is equivalent to 16384
and computed from the whole electrical angle rotation of 65536.
The time period measured between subsequent Hall sensor states is inversely proportional to the speed of the motor;
therefore, a proportionality constant is needed. The PHASE_INC_CALC is a constant that is used to compute the phase
increment from the average period.

 2021 Microchip Technology Inc. DS00004064A-Page 11


AN4064
EQUATION 2: PHASE INC CALC

EQUATION 3: PHASE INCREMENT

EQUATION 4: FINAL TRANSFORMATION ANGLE

From the equation above, the constant PHASE_INC_CALC is derived from dividing the SCCP Timer clock by the Timer
Prescaler and PWM switching frequency and multiplying the quotient by the equivalent phase value of 60-electrical
degrees. The phaseInc variable is computed from dividing the PHASE_INC_CALC by the average period. The phaseInc
value is used to increment the transformation angle in every ADC_ISR() cycle. The computed transformation angle
reflects the electrical angle at a distinct moment in time. The process continues until another change notification interrupt
event is serviced, and a new reference value is obtained. For a more elaborate illustration on the relationship among
the sector number, rotor sector phase value and transformation angle, see the diagram in the following figure.

FIGURE 14: ROTOR ANGULAR POSITION

7.2 Speed Measurement


Due to motor mechanical construction and that the Hall effect sensors might not be perfectly placed at 120 degrees from
each other, the time between the change of the Hall states is slightly different. For this reason, a single period capture
is not sufficient to accurately calculate the speed. To complete a single electrical rotation, it will take six change
notification interrupts. The period measured from those succeeding interrupts are integrated and used to calculate the
speed. The following equation is used for calculating the raw speed.

DS00004064A-Page 12  2021 Microchip Technology Inc.


AN4064
EQUATION 5: SPEED CALCULATION

The Period_Summation is a moving average summation that ensures that the calculatedSpeed will always be computed
after every six change notification interrupts. The calculatedSpeed is filtered using the moving average filter to ensure
that the measured speed is smooth and has no random noises.
The final output of the position and speed block are the measured speed and electrical angle that are fed to the PI control
blocks.

 2021 Microchip Technology Inc. DS00004064A-Page 13


AN4064
8.0 FAULT DETECTION AND PROTECTION
The application firmware is equipped with fault detection and protection against shoot-through, overcurrent,
overtemperature and undervoltage. These unwanted events may damage the motor and motor drivers, thus it is
recommended to prevent them.

8.1 Shoot-through
It is a failure event when two complementary switches in a voltage source inverter are turned on simultaneously,
consequently short-circuiting the supply.
The PWM peripheral has the dead-time generator that is applied in both the rising and falling edges of the PWM signals
to prevent shoot-through. The dead time lasts for 1 µs, ensuring that discharge or turn-off delay time does not falsely
switch ON the complementary switches simultaneously.

8.2 Overcurrent Protection


Overcurrent describes a sharp and fast rise in current over a short period of time. It can be caused by improper
commutation, excessive load, line-to-ground or line-to-line faults. In this condition, the value of the current is far greater
than the nominal line current and may result in the circuit overheating.
The current is monitored through the current-sensing circuits connected to the phase A of the motor. The resistor
RSHUNT is tapped at the low side of the inverter. The voltage across RSHUNT reflects the current that flows through the
inverter. The DSCs internal op amp is utilized for measuring and conditioning the voltage signal. The output of the
internal op amp is fed to the non-inverting input of comparator with DAC. The DAC is connected to the inverting input
of the Comparator and sets the reference value. The DAC has a 12-bit resolution that can provide 5% to 95% of AVDD.
The measured voltage signal is continuously compared to the reference voltage set by the DAC. If the voltage signal
goes higher than the voltage set by the DAC for 100 μs, the PWM drivers are disabled and the motor is stopped.

8.3 Overtemperature Protection


The operating ambient temperature range of dsPIC33CK64MP105 is from -40 to +85ºC. The overtemperature detection
for the microcontroller is done through the Temperature Sensor tied to AN19 pin of dsPIC. The diode in the temperature
sensor has a negative temperature coefficient. The ADC is used to monitor the die temperature through channel AN19.
The temperature limit is set depending on the measured voltage at normal operation and adjusted on the ambient
temperature range. At 25ºC, the measured ADC value is 240. The formula for getting the ADC Value is expressed in
the following equation.

EQUATION 6: EQUIVALENT DIGITAL VALUE OF SENSED TEMPERATURE

Rearranging the previous formula in the previous equation leads to the following equation.

EQUATION 7: VOLTAGE MEASURED AT ROOM TEMPERATURE

This Vtemp @ 25ºC is used as the reference voltage in which the change in voltage across the diode with the temperature
coefficient of -1.5 mV / ºC will be added or deducted depending on the rise or fall of the temperature. The new Vtemp is
computed using the following equation.

EQUATION 8: VOLTAGE MEASURED AT ANY TEMPERATURE

DS00004064A-Page 14  2021 Microchip Technology Inc.


AN4064
The fault protection is designed to shut down the system if the temperature rises to 57ºC or equivalent to the ADC value
of 225 because it is recommended that the battery of the electric scooter not operate in a temperature greater than 60ºC
or equivalent to the ADC value of 224.

8.4 Undervoltage Protection


Undervoltage is defined as a condition in which the voltage drops to less than 90% of the rated voltage for at least one
minute.
The undervoltage in VBUS is directly monitored by the controller using the VBUS/16 signal, which has a direct connection
to the dsPIC AN15 channel input. The routine used for monitoring the bus voltage is within the Interrupt Service Routine
used for driving the motor. It is checked for every 20 µs. To avoid false triggers for undervoltage, a counter is used for
counting the elapsed time for the undervoltage. If the counter exceeds 1 minute, the undervoltage fault will be activated,
which causes the system to be disabled.
It is recommended not to let the battery drop below 70%, so the controller undervoltage protection would be 0.7VBAT.
Using the following equation, the voltage limit is computed.

EQUATION 9: VOLTAGE LIMIT

 2021 Microchip Technology Inc. DS00004064A-Page 15


AN4064
9.0 APPLICATION OF SENSORED FOC IN ELECTRIC SCOOTER
In recent years, the use of electric two-wheelers, such as the electric scooter, as a means of personal transportation
became widespread. An electric scooter is composed of a battery, battery charger, motor, motor driver, DC-DC
converter, intelligent controller and other accessories.
The motor is fixed in the hub of the wheel. The sensored BLDC motor has a very similar construction with a permanent
magnet synchronous motor used as a hub motor. The reason for choosing BLDC is its compactness, low maintenance,
and noiseless operation. The Hall effect sensors are already included in the construction of the motor. The hub motor
typical voltage is 36V – 42V, with the speed ranging from 150 RPM to 650 RPM or 5 kph to 25 kph.
The sensored FOC technique is very suitable for driving the electric scooter because it provides an efficient way to
control the BLDC motor in adjustable speed drive applications. The FOC technique improves the torque response and
dynamic speed accuracy. The sensored nature of the solution makes it appropriate for the high precision drive of the
electric scooter hub motor.
With an increasing demand for electric scooters, a board was developed to cater to the need for intelligent control of
electric scooters. The electric scooter board was developed with a DC-DC converter, intelligent controller and motor
driver with a fully protected power stage. The board only requires the throttle signal, battery and battery charger to
completely control the electric scooter. The board was used in testing the solution discussed in this application note.
The reference design of the board was released in a separate document. The figure below shows the front and back of
the electric scooter board.

FIGURE 15: FRONT AND BACK BOARD PICTURES

The stopping of the motor is an important consideration in controlling the electric scooter. Regenerative braking is an
additional feature used for speeding up the deceleration and extending the battery life.

9.1 Regenerative Braking


Regenerative braking is the process of using a motor in motion as a generator, consequently, making the motor slow
down. The energy recovered in the process is stored back to the battery. The energy can only be stored when the Back
EMF generated by the BLDC motor is greater than the battery voltage. For practical application, regenerative braking
is preferred at high-speed motor operation.
The three-switch regenerative braking method is used in this application. An additional pin is used as an input for
processing the signal coming from the brake lever. The braking routine is included in the interrupt service routine used
for driving the motor. When a brake signal is sensed, the PWM signal is applied to the low side switches of the inverter
while the high side switches are turned off, as shown in the following figure.

DS00004064A-Page 16  2021 Microchip Technology Inc.


AN4064
FIGURE 16: LOW SIDE SWITCHES ARE MODULATED

1H 2H 3H
0 0 0

+ -
E

- E
+
+ - + E
-

Battery 1L 2L 3L

This switch configuration allows the converted electrical energy from the rotating motor to be boosted to a higher voltage
than the DC bus voltage. The second step in the process is turning off the low side switches, letting the current flow
back to the source through the MOSFET body diode, as shown in the following figure. The boosted voltage is, then,
stored back to the battery.

FIGURE 17: LOW SIDE SWITCHES ARE OFF

1H 2H 3H
0 0 0

+ -
E

- E
+
+ - + E
-

Battery 1L 2L 3L

 2021 Microchip Technology Inc. DS00004064A-Page 17


AN4064
10.0 TESTING ON THE ELECTRIC SCOOTER BOARD
This section presents the results of testing the sensored FOC drive in an electric scooter at no load condition. This
illustrates the rotor angular position, the SVM line-to-ground voltages and the SVM line-to-line voltages. The diagrams
and graphs are captured using X2CScope, a virtual oscilloscope tool that allows run-time debugging and data
visualization.

FIGURE 18: ROTOR ANGULAR POSITION AND SECTOR PHASE VALUE

FIGURE 19: SVM LINE-TO-GROUND VOLTAGES

DS00004064A-Page 18  2021 Microchip Technology Inc.


AN4064
FIGURE 20: SVM LINE-TO-LINE VOLTAGES

 2021 Microchip Technology Inc. DS00004064A-Page 19


AN4064
11.0 CONCLUSION
The sensored FOC based on Hall effect sensor achieved the high-precision speed and position control of the 3-Phase
BLDC motor through developing a high-resolution algorithm out of Hall effect sensor states. The 16-bit Microchip
dsPIC33CK DSC efficiently used its DSP for executing the FOC algorithm and its on-chip peripherals for a cost-effective
solution. The solution presented in this application note effectively drives the 3-Phase BLDC hub motor of the electric
scooter. Fault protection was added to the system to ensure that unwanted events that can cause system failure can be
readily detected and stop the system’s operation.

DS00004064A-Page 20  2021 Microchip Technology Inc.


AN4064
APPENDIX A: SOURCE CODE LISTING
The latest software version can be downloaded from the Microchip website (www.microchip.com). The user will find the
source code appended to the electronic version of this application note.

 2021 Microchip Technology Inc. DS00004064A-page 21


AN4064
APPENDIX B: REVISION HISTORY
Revision Date Section Description
A 07/2021 Document Initial release

DS00004064A-page 22  2021 Microchip Technology Inc.


Note the following details of the code protection feature on Microchip devices:
• Microchip products meet the specifications contained in their particular Microchip Data Sheet.

• Microchip believes that its family of products is secure when used in the intended manner and under normal conditions.

• There are dishonest and possibly illegal methods being used in attempts to breach the code protection features of the Microchip
devices. We believe that these methods require using the Microchip products in a manner outside the operating specifications
contained in Microchip's Data Sheets. Attempts to breach these code protection features, most likely, cannot be accomplished
without violating Microchip's intellectual property rights.

• Microchip is willing to work with any customer who is concerned about the integrity of its code.

• Neither Microchip nor any other semiconductor manufacturer can guarantee the security of its code. Code protection does not
mean that we are guaranteeing the product is "unbreakable." Code protection is constantly evolving. We at Microchip are
committed to continuously improving the code protection features of our products. Attempts to break Microchip's code protection
feature may be a violation of the Digital Millennium Copyright Act. If such acts allow unauthorized access to your software or
other copyrighted work, you may have a right to sue for relief under that Act.

Information contained in this publication is provided for the sole Trademarks


purpose of designing with and using Microchip products. Infor- The Microchip name and logo, the Microchip logo, Adaptec,
mation regarding device applications and the like is provided AnyRate, AVR, AVR logo, AVR Freaks, BesTime, BitCloud, chipKIT,
only for your convenience and may be superseded by updates. chipKIT logo, CryptoMemory, CryptoRF, dsPIC, FlashFlex,
flexPWR, HELDO, IGLOO, JukeBlox, KeeLoq, Kleer, LANCheck,
It is your responsibility to ensure that your application meets LinkMD, maXStylus, maXTouch, MediaLB, megaAVR, Microsemi,
with your specifications. Microsemi logo, MOST, MOST logo, MPLAB, OptoLyzer,
PackeTime, PIC, picoPower, PICSTART, PIC32 logo, PolarFire,
THIS INFORMATION IS PROVIDED BY MICROCHIP "AS IS". Prochip Designer, QTouch, SAM-BA, SenGenuity, SpyNIC, SST,
MICROCHIP MAKES NO REPRESENTATIONS OR WAR- SST Logo, SuperFlash, Symmetricom, SyncServer, Tachyon,
RANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, TimeSource, tinyAVR, UNI/O, Vectron, and XMEGA are registered
trademarks of Microchip Technology Incorporated in the U.S.A. and
WRITTEN OR ORAL, STATUTORY OR OTHERWISE, other countries.
RELATED TO THE INFORMATION INCLUDING BUT NOT
LIMITED TO ANY IMPLIED WARRANTIES OF NON- AgileSwitch, APT, ClockWorks, The Embedded Control Solutions
INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A Company, EtherSynch, FlashTec, Hyper Speed Control, HyperLight
PARTICULAR PURPOSE OR WARRANTIES RELATED TO Load, IntelliMOS, Libero, motorBench, mTouch, Powermite 3,
Precision Edge, ProASIC, ProASIC Plus, ProASIC Plus logo, Quiet-
ITS CONDITION, QUALITY, OR PERFORMANCE. Wire, SmartFusion, SyncWorld, Temux, TimeCesium, TimeHub,
TimePictra, TimeProvider, WinPath, and ZL are registered
IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDI- trademarks of Microchip Technology Incorporated in the U.S.A.
RECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUEN-
TIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND Adjacent Key Suppression, AKS, Analog-for-the-Digital Age, Any
WHATSOEVER RELATED TO THE INFORMATION OR ITS Capacitor, AnyIn, AnyOut, Augmented Switching, BlueSky,
BodyCom, CodeGuard, CryptoAuthentication, CryptoAutomotive,
USE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS
CryptoCompanion, CryptoController, dsPICDEM, dsPICDEM.net,
BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES Dynamic Average Matching, DAM, ECAN, Espresso T1S,
ARE FORESEEABLE. TO THE FULLEST EXTENT EtherGREEN, IdealBridge, In-Circuit Serial Programming, ICSP,
ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON INICnet, Intelligent Paralleling, Inter-Chip Connectivity,
ALL CLAIMS IN ANY WAY RELATED TO THE INFORMATION JitterBlocker, maxCrypto, maxView, memBrain, Mindi, MiWi,
MPASM, MPF, MPLAB Certified logo, MPLIB, MPLINK, MultiTRAK,
OR ITS USE WILL NOT EXCEED THE AMOUNT OF FEES, IF NetDetach, Omniscient Code Generation, PICDEM, PICDEM.net,
ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP PICkit, PICtail, PowerSmart, PureSilicon, QMatrix, REAL ICE,
FOR THE INFORMATION. Use of Microchip devices in life sup- Ripple Blocker, RTAX, RTG4, SAM-ICE, Serial Quad I/O,
port and/or safety applications is entirely at the buyer's risk, and simpleMAP, SimpliPHY, SmartBuffer, SMART-I.S., storClad, SQI,
the buyer agrees to defend, indemnify and hold harmless SuperSwitcher, SuperSwitcher II, Switchtec, SynchroPHY, Total
Endurance, TSHARC, USBCheck, VariSense, VectorBlox, VeriPHY,
Microchip from any and all damages, claims, suits, or expenses ViewSpan, WiperLock, XpressConnect, and ZENA are trademarks
resulting from such use. No licenses are conveyed, implicitly or of Microchip Technology Incorporated in the U.S.A. and other
otherwise, under any Microchip intellectual property rights countries.
unless otherwise stated.
SQTP is a service mark of Microchip Technology Incorporated in
the U.S.A.
The Adaptec logo, Frequency on Demand, Silicon Storage
Technology, and Symmcom are registered trademarks of Microchip
Technology Inc. in other countries.
GestIC is a registered trademark of Microchip Technology Germany
II GmbH & Co. KG, a subsidiary of Microchip Technology Inc., in
other countries.
All other trademarks mentioned herein are property of their
respective companies.

© 2021, Microchip Technology Incorporated, All Rights Reserved.

For information regarding Microchip’s Quality Management Systems, ISBN: 978-1-5224-8391-5


please visit www.microchip.com/quality.

 2021 Microchip Technology Inc. DS00004064A-page 23


Worldwide Sales and Service
AMERICAS ASIA/PACIFIC ASIA/PACIFIC EUROPE
Corporate Office Australia - Sydney India - Bangalore Austria - Wels
2355 West Chandler Blvd. Tel: 61-2-9868-6733 Tel: 91-80-3090-4444 Tel: 43-7242-2244-39
Chandler, AZ 85224-6199 China - Beijing India - New Delhi Fax: 43-7242-2244-393
Tel: 480-792-7200 Tel: 86-10-8569-7000 Tel: 91-11-4160-8631 Denmark - Copenhagen
Fax: 480-792-7277 Tel: 45-4485-5910
China - Chengdu India - Pune
Technical Support: Fax: 45-4485-2829
Tel: 86-28-8665-5511 Tel: 91-20-4121-0141
http://www.microchip.com/
China - Chongqing Japan - Osaka Finland - Espoo
support
Tel: 86-23-8980-9588 Tel: 81-6-6152-7160 Tel: 358-9-4520-820
Web Address:
www.microchip.com China - Dongguan Japan - Tokyo France - Paris
Tel: 86-769-8702-9880 Tel: 81-3-6880- 3770 Tel: 33-1-69-53-63-20
Atlanta Fax: 33-1-69-30-90-79
Duluth, GA China - Guangzhou Korea - Daegu
Tel: 678-957-9614 Tel: 86-20-8755-8029 Tel: 82-53-744-4301 Germany - Garching
Tel: 49-8931-9700
Fax: 678-957-1455 China - Hangzhou Korea - Seoul
Austin, TX Tel: 86-571-8792-8115 Tel: 82-2-554-7200 Germany - Haan
Tel: 512-257-3370 Tel: 49-2129-3766400
China - Hong Kong SAR Malaysia - Kuala Lumpur
Tel: 852-2943-5100 Tel: 60-3-7651-7906 Germany - Heilbronn
Boston
Tel: 49-7131-72400
Westborough, MA China - Nanjing Malaysia - Penang
Tel: 774-760-0087 Tel: 86-25-8473-2460 Tel: 60-4-227-8870 Germany - Karlsruhe
Fax: 774-760-0088 Tel: 49-721-625370
China - Qingdao Philippines - Manila
Chicago Tel: 86-532-8502-7355 Tel: 63-2-634-9065 Germany - Munich
Itasca, IL Tel: 49-89-627-144-0
China - Shanghai Singapore
Tel: 630-285-0071 Fax: 49-89-627-144-44
Tel: 86-21-3326-8000 Tel: 65-6334-8870
Fax: 630-285-0075 Germany - Rosenheim
China - Shenyang Taiwan - Hsin Chu
Dallas Tel: 49-8031-354-560
Tel: 86-24-2334-2829 Tel: 886-3-577-8366
Addison, TX Israel - Ra’anana
China - Shenzhen Taiwan - Kaohsiung
Tel: 972-818-7423 Tel: 86-755-8864-2200 Tel: 886-7-213-7830 Tel: 972-9-744-7705
Fax: 972-818-2924 Italy - Milan
China - Suzhou Taiwan - Taipei
Detroit Tel: 39-0331-742611
Tel: 86-186-6233-1526 Tel: 886-2-2508-8600
Novi, MI Fax: 39-0331-466781
Tel: 248-848-4000 China - Wuhan Thailand - Bangkok
Tel: 86-27-5980-5300 Tel: 66-2-694-1351 Italy - Padova
Houston, TX Tel: 39-049-7625286
Tel: 281-894-5983 China - Xian Vietnam - Ho Chi Minh
Tel: 86-29-8833-7252 Tel: 84-28-5448-2100 Netherlands - Drunen
Indianapolis Tel: 31-416-690399
Noblesville, IN China - Xiamen Fax: 31-416-690340
Tel: 86-592-2388138
Tel: 317-773-8323 Norway - Trondheim
Fax: 317-773-5453 China - Zhuhai Tel: 47-7288-4388
Tel: 317-536-2380 Tel: 86-756-3210040
Poland - Warsaw
Los Angeles Tel: 48-22-3325737
Mission Viejo, CA
Romania - Bucharest
Tel: 949-462-9523 Tel: 40-21-407-87-50
Fax: 949-462-9608
Tel: 951-273-7800 Spain - Madrid
Tel: 34-91-708-08-90
Raleigh, NC Fax: 34-91-708-08-91
Tel: 919-844-7510
Sweden - Gothenberg
New York, NY Tel: 46-31-704-60-40
Tel: 631-435-6000
Sweden - Stockholm
San Jose, CA Tel: 46-8-5090-4654
Tel: 408-735-9110
Tel: 408-436-4270 UK - Wokingham
Tel: 44-118-921-5800
Canada - Toronto Fax: 44-118-921-5820
Tel: 905-695-1980
Fax: 905-695-2078

DS00004064A-page 24  2021 Microchip Technology Inc.


02/28/20

You might also like