How to design Low cost high efficient BLDC motor
Embed Size (px)
Transcript of How to design Low cost high efficient BLDC motor
Low Cost Brushless DC Motor Controller
Department of Computer Science and Electrical Engineering
Supervised by Dr. Geoffrey Walker
Submitted for the degree of Bachelor of Engineering
In the division of Computer Systems Engineering
29th November 2003
October 29, 2003
Professor Simon Kaplan,
Head of School of Information Technology and Electrical Engineering
University of Queensland
St. Lucia, QLD, 4072
In accordance with the requirements of the degree of Bachelor of Engineering in the
division of Electrical Engineering, I present the following thesis, entitled
Low Cost Brushless DC Motor Controller.
This work was performed under the supervision of Dr. Geoffrey Walker.
I declare that the work submitted in this thesis is my own, except as acknowledged in
the text, and has not been previously submitted for a degree at the University of
Queensland, or any other institution.
With advances in 42-volt automotive systems, more mechanical loads are being
driven from the DC power bus. Such loads include power steering pumps and air
A brushless DC (BLDC) motor has been chosen to drive the compressor in the Ultra
Commuter because of its superior output characteristics over induction and brushed
The cooling requirements demand 1kW peak power output. The air conditioning
system also requires pressure switches to protect the compressor from low-pressure
operation. Since space is precious, the controller needs to be as small as possible. As
such, large heat sinks are not an option, hence heat dissipation must be minimal. The
drive circuit must also be rugged to provide a long trouble free life.
The purpose of this thesis is to design, construct and evaluate the hardware and
software for a motor controller to meet the above requirements. These goals have
been met by careful component selection, rugged hardware design, space saving
layout techniques and reliable firmware.
I would like to thank the following people:
Dr Geoffrey Walker, my thesis supervisor for guidance and technical help throughout
Mr. Peer Allen, my lab supervisor for maintaining the thesis laboratory and providing
an excellent working environment.
Mr. Keith Bell and the rest of the EWS team for producing all of my PCBs.
Mr. Thommas Williams (Mechanical Engineer) for providing me with a test rig on
which to test my hardware.
Mr. David Finn (PHD student) for providing me with information on brushless DC
Mr. Paul Jones for his assistance in firmware development.
The thesis students of Axon 504 (Nino Johannson, Luke Billingham, Andrew Parker,
Brent Singer, Christopher Lister) for brightening up an otherwise dull work
Contents Chapter 1 Introduction...............................................6
1.1 42-volt Brushless DC Motor Controller ..............................................................6 1.2 Achieved Solution................................................................................................6 1.3 Document Overview ............................................................................................7
Chapter 2 Background Information and Product Review .............................................................................9
2.1 Brushless DC Motor Characteristics....................................................................9 2.2 Brushless DC Motor Construction.....................................................................10 2.3 Brushless DC motor Control..............................................................................12 2.4 Transistors..........................................................................................................14 2.5 Drive Topologies ...............................................................................................15 2.6 Existing Product Review...................................................................................16
Chapter 3 Derivation of Specifications ...................19 3.1 Air Conditioner Requirements...........................................................................19 3.2 Motor Requirements ..........................................................................................20 3.3 Controller Specifications ...................................................................................20
Chapter 4 Hardware Implementation ....................22 4.1 Hardware design and component selection.......................................................22 4.2 MOSFET Bridge................................................................................................22
IRF3803 Specs  .............................................................................................24 4.3 Gate Drive.........................................................................................................26
IR2101s Specs  ..............................................................................................27 4.4 Power Supply .....................................................................................................28 4.5 Current Sense Amplifiers...................................................................................30 4.6 Hall Effect Sensor Interface...............................................................................32 4.7 Pressure Switch Interface...................................................................................34 4.9 Temperature Sensor ...........................................................................................38
Chapter 5 Firmware Implementation.....................39
Chapter 6 Product Evaluation and Results ............43 6.1 Motor Truth table...............................................................................................43 6.2 Hardware............................................................................................................44 6.3 Efficiency and Performance...............................................................................45 6.4 Budget ................................................................................................................46
Chapter 7 Future Developments..............................49
Chapter 8 Conclusion ...............................................50
Appendix ...............................................................53 Appendix 1...............................................................................................................54 Appendix 2...............................................................................................................55 Appendix 3...............................................................................................................56
Chapter 1 Introduction 1.1 42-volt Brushless DC Motor Controller
Brushless DC (BLDC) motors find use in many applications ranging from printer
head motors to large conveyor belt drivers. With the upcoming 42-volt automotive
electrical system, more mechanical loads will be electrically driven. The electric
motors driving these loads may be brushed DC motors or brushless DC motors.
Brushless DC motors will find use in applications that are constantly running.
Examples of such applications include water pumps, oil pumps, fuel pumps, gearbox
hydraulic pumps, air compressors, variable valve actuators, power steering pumps, air
conditioning compressor and many more.
As the name suggests, Brushless DC motors dont have any brushes, as do their
brushed counter parts. As such, they require additional electronics to perform motor
commutation. The additional electronics is referred to as the motor drive or motor
The aim of this thesis project is to design and evaluate a low cost BLDC motor
controller. The motor controller is intended to drive the air conditioning compressor
of the Ultracommuter. It is expected that this thesis provide a solution suitable for the
requirements of the Ultracommuter.
1.2 Achieved Solution
The solution achieved as a result of this thesis project is a low cost micro controller
implementation. Smart component selection has been used to meet many of the
requirements set out by the project description. Though a prototype was available for
testing, more work is required to meet size constraints. This motor controller though
fulfils the project requirements, is not a universal design. It is application specific.
With further research and some hardware changes, a universal solution may evolve
from the current design.
1.3 Document Overview
The following pages document relevant background information, design processes,
product evaluation and results relating to the BLDC motor controller.
Chapter 2 Background information
This chapter contains background information on brushless DC motors, why
they are used, current applications, future applications, drive requirements, driver
topologies, and control methods.
Chapter 3 Derivation of motor controller specifications
This chapter examines the project descriptions and sets down a set of
requirements that the motor controller must fulfil. Specifications will be derived by
breaking down the motor controller into its subsystems and listing the requirements of
each subsystem. The process by which the subsystems were derived will also be
Chapter 4 Hardware Implementation
This chapter details component selection for the different subsystems that
make up the motor controller.
Chapter 5 Firmware Implementation
The chapter outlines the requirements of the motor controller firmware as set
down in the controller specification. It also describes how the firmware was
Chapter 6 Product Evaluation and Results
This chapter details the performance of the motor controller. It also compares
the actual product to the specifications of Chapter 3. Also discussed are the
procedures used to perform tests and how closely the results match theoretical
calculations. A table summarises the results.
Chapter 7 Future Developments
This chapter describes the improvements that could be made. Discussed are
aspects that would be implemented the same way and aspects that would be
Chapter 8 Conclusion
This chapter provides a brief overview of the entire project. Is outlines the
intended goals and the achieved goals. A summary of performance is also included.
The aim of this report is to provide a detailed and accurate summary of BLDC motor
drivers along with the relevant theory. It is hoped that the reader gains a firm
understanding of the BLDC motor controller and its capabilities.
Chapter 2 Background Information and Product Review This chapter provides the relevant background information required to understand the
hardware requirements, control strategies and software requirement of a BLDC motor
2.1 Brushless DC Motor Characteristics
Brushless DC motors first came about soon after the development of transistors and
other semiconductor switching devices. The principle reason for their existence was
to provide electronic commutation between phase windings. This gave rise to speed
control of motors where previously motors would have been designed specifically for
the desired operating speed. They also offer better efficiency over induction and
synchronous motors due to the lack of machine air gap loses. [Luo, F. L., Yeo, H. G.
(2000)] Also, brushless DC motors dont produce the levels of electromagnetic
radiation common to universal motors. [Bentouati, S.; Zhu, Z.Q.; Howe, D. (1999)]
A brushless DC motors characteristic is what makes them such a versatile drive
solution. BLDC motors have identical speed and torque characteristics to brushed DC
The torque produce by BLDC motors is given by:
( )22 g rms rmsT D r LB K K Iπ ϕ= =
From the equation, it is clear that the motor torque is directly proportional to motor
The speed, ω, of a BLDC motor is given by:
speedV Kω = ×
where Kspeed is the motor speed constant in radians per volt.
It is clear that the motor speed is directly proportional to the applied voltage, V.
Figure 1 summarises the torque characteristics of a BLDC motor. The actual torque
drops slightly due to core saturation at higher currents. It should also be noted that
BLDC motors produce maximum torque from standstill. This is one of the main
reasons they are preferred over induction motors. Induction motors draw up to twice
their rated current on starting but product only typically 30 percent of their operating
torque from standstill. Synchronous motors product zero starting torque, as a result
they are usually started and brought to synchronous speed using a DC motor.
BLDC Motor Torque Current Curve
0 20 40 60 80 100
Figure 1 BLDC motor torque speed curve
2.2 Brushless DC Motor Construction
A brushless DC motors internal construction is what gives it its characteristics.
Brushless DC motors are a variant of permanent magnet DC motors (PMDCM). PM
DC motors are simply synchronous motors in which the rotor field is driven with a
constant current. By driving the rotor winding with a constant current, a fix magnetic
flux is established within the motor. This can also be achieved by replacing the rotor
winding with a permanent magnet. Such motors are called brushless DC motors.
Brushless DC motors dont require slip rings so motor maintenance is reduced and
reliability is increased. Slip rings create dust as they wear. The dust needs to be
periodically cleaned from the motor housing. When slip rings wear past a certain
length, they need to be replaced.
Figure 2 3 phase synchronous motor internal diagram
Figure 3 3 phase brushless DC motor internal diagram
The stator windings of BLDC motors contain a multi-phase winding. Small cooling
fans are usually 2-phase, while medium and large power motors are 3-phase. Some
washing machine motors have 4 or 5 phase windings to reduce torque ripple. The
windings may be either wye connected or delta connected. Most motors have
ungrounded wye connections.
Brushless DC motors require that the motor controller perform the commutation
function. Commutation is a function of rotor position. The appropriate stator
windings of the motor need to be energised when the rotor pole lines up with winding.
It is possible to drive a BLDC motor by simply forcing the commutation intervals to a
preset value. The problem with this type of control is that the applied phase voltage
may not be proportional to the speed forced by the controllers commutation
The generated stator flux interacts with the rotor flux, which is generated by a rotor
magnet, defines the torque and thus speed of the motor. The voltage strokes must be
properly applied to the two phases of the three-phase winding system so that the angle
between the stator flux and the rotor flux is kept close to 90° to get the maximum
generated torque. Due to this fact, the motor requires electronic control for proper
Most BLDC motors have internal sensors to provide position information. The most
common type of sensor is the Hall Effect sensors. When the rotor pole lines up with a
particular phase, the sensors output goes high and when the rotor has passed, the
output goes low. 3-phase motors typically have three hall sensors. The sensors are
placed in the centre of each phase winding. They may be spaced at 60 or 120
electrical degree intervals. 120-degree spacing common. Encoders may also be used.
They are used on servomotors. The encoders are usually mounted on the end of a
gearbox. It is also possible to drive a BLDC motor without sensors.
2.3 Brushless DC motor Control
The purpose of a BLDC motor controller is to provide speed and/or torque control to
the motor. Usually a controller will provide one of the two, either torque or speed
control. Speed control is achieved by monitoring motor speed and adjusting the
applied phase voltage to maintain the desired speed. Torque control is achieved by
monitoring motor current. The motor current can be controlled to hold a constant
value thus providing constant torque on the motor shaft.
It is possible to incorporate speed and torque control. Typically, speed may be
controlled but a hard current limit will also be enforced to stop the motor drawing
more than its rated current. Alternatively, current may be controlled with speed
limiting to prevent the motor from running faster than its rated speed. This is
particularly important when brushless DC motors are run from power supplies that
have a higher output voltage that what the motor is rated for.
An example where constant torque control is used is in grinding mills. Constant
speed operation is typically usually used for conveyor belt drives in process control
In addition to providing speed and torque control, motor controller must also generate
the required motor commutation sequences. Motor commutation is usually related to
Hall Effect sensor outputs.
Figure 4 Hall sensor outputs and stator phase voltage relationship 
Figure 4 shows the relationship between Hall Effect sensor outputs and phase back
EMF waveforms. This is usually referred to as a motors truth table as it determines
which phases need to be energised for each particular Hall Effect sensor transition.
The simplest BLDC motor controllers operate by providing a trapezoidal current
waveform to the motor. More complex controllers can generate sinusoidal currents.
Sinusoidal drive waveforms result is quieter motor operation and smoother torque
output. In order to product sinusoidal drive waveforms, current sensing is needed on
each phase. Trapezoidal current driver only required one current sensor, usually
placed on the power leads into or out of the motor controller.
The output stage of motor controllers is made up of transistors. The transistor of
choice are metal oxide field effect transistors (MOSFETs). The theory of MOSFET
operation wont be discussed here. However, the relevant formula for calculating
MOSFETs have a characteristic drain to source resistance, Rds. This is the resistance
when the transistor is turned to its on state, that is, there is current flowing through
the device. As with any resistor, if there is a current flowing through it, there will
power dissipated in the device. The heat dissipated by a MOSFET due to its
resistance is referred to as conduction loss. Conduction loss, Pon, is given by:
2onon on ds
tP I RT
where Ion is the current flowing through the transistor when it is fully switch on.
Since switching from off to on state does not occur instantaneously, there is also
power dissipation due to the finite switching time. This is referred to as switching
loss, Psw and is given by:
1 ( )2
on offsw d o s c cP V I f t T= +
MOSFETs with higher current capability typically have lower drain-source resistance,
resulting is low power dissipation. They do however have a large gate-source
capacitance that results in higher conduction losses and reduced switching frequency.
2.5 Drive Topologies
Two main drive topologies exist to drive BLDC motors, the full bridge and the half
bridge. The half bridge circuit shown in figure 5 consists of three transistors. The
drain of each transistor is connected to a motor phase winding. The advantage of the
half bridge is the lower part count. In the event that MOSFETs are used, the resulting
switching losses are also lower. For a given power output, P:
so the conduction loss is: 2
2on onon on ds ds
s s d
t t PP I R RT T V
and switching loss is given by:
1 1( ) ( )2 2
on off on offsw d o s c c d s c cd
PP V I f t T V f t TV = + = +
These power losses are on a per transistor basis.
Figure 5 Half bridge motor drive
The disadvantage of a half bridge driver is that current can only flow in one direction through a motor phase. Also, the motor must be a wye-connected motor with the star point brought out for external connection. Torque delivered by a half bridge drive and motor is given by:
( )2 123
g rms rms peakT D r LB K K I K Iπ ϕ ϕ= = =
A more flexible driver is the full bridge using six switches. Current in a full bridge can be driven through a motor phase winding in both directions. A full bridge and the associated motor connection is shown in figure 6.
Figure 6 Full bridge motor drive
Because of the way a motor is connected to a full bridge, current is driven in two
phase windings at any one time. This means that torque is produce by two phases at
any one time as opposed to the half bridge, where torque is only produced by one
phase at a time. The effective copper utilisation is doubled.
The torque of a full bridge driver and motor is given by:
( )2 223
g rms rms peakT D r LB K K I K Iπ ϕ ϕ= = =
Since two phases are excited together, the current density in the motor is higher. As a
result the torque produce by such a set up is also higher. The full bridge is able to
deliver 1.41 times the torque of a half bridge connected to the same motor.
2.6 Existing Product Review
There are several existing products that are available for 3-phase brushless DC motor
control. A list of controller chips is summarised in table 1.
Most of these control ICs have integrated output transistors. They are intended to be
single chip solution for low power applications. The L6235 from ST
Microelectronics show incredible potential for automotive use. Its capable of
delivering 130 Watts continuous to a 3-phase motor. This chip would be particularly
useful for driving cooling fan motors, water, oil and fuel pump motors. Such pumps
would have the drive circuit integrated into the pump package to form a sealed unit
with only two wires coming out for power.
Another particular useful controller is the A3932 from Allegro IC. Its specifically
designed for automotive use. It features both high and low side gate drivers for N-
channel MOSFETs, over current protection, PWM input and tachometer output. The
PWM input allows the connection of an external micro controller or DSP to perform
the speed control loop. Another feature of this controller is the cost, only $9.00.
The MC33033 from On Semiconductor is an older controller. Its designed to run P-
channel high side switches. Also, it required additional hardware to provide closed
loop motor control. This controller can be used to drive N-channel transistors,
however, the parts could is greatly increased as a result. The main reason is that
signal inverters are required on the high side transistor outputs.
A commercially available motor controller is the Tritium Gold Controller.
Chapter 3 Derivation of Specifications The expected outcome of this thesis project is to produce a motor controller capable
of driving a BLDC motor, which in turn will drive an air conditioning compressor. In
order to fulfil the project requirements, a list of the requirements for the air
conditioning system must be made. From this, a set of specifications can be drawn up
and then the project can be broken down into separate subsystems.
3.1 Air Conditioner Requirements
The Ultracommuter air conditioner system has the following requirements:
" Electrically driven
" 42 Volt operation
" 1kW input power
" Temperature control
" Low internal gas pressure protection
The air conditioning compressor must be electrically driven to increase the overall
efficiency of the Ultracommuter vehicle. Since the Ultracommuter features a 42-volt
electrical system, the air conditioning system must operate from the 42-volt supply.
The cooling requirements of the Ultracommuter define that the input power to the
compressor must be 1kW peak and 500 to 700 watts continuous.
Temperature control is required to avoid running the air conditioner at full power.
Full power operation would result in uncomfortably low cabin temperatures. Once
the cabin temperature reaches a preset level, the air conditioner needs only to maintain
The air conditioning system must be prevented from operating in the event that
refrigerant leaks out of the system. This is required to protect the compressor.
3.2 Motor Requirements
The motor that will drive the air conditioning compressor has the following
" 3 phase delta or ungrounded Wye connected brushless DC
" 3000 rpm at 110 Volts
" 3kW output at 110 volts
" 27 amp winding rating
" Built in open collector Hall Effect sensors
3.3 Controller Specifications
From the list of motor requirements and air conditioner requirements, the following
list of controller specifications has been made:
8 bit micro controller
3 Phase full bridge output capable of 1kW
Motor current limiter
Cabin temperature sensor
12-volt to 5-volt Hall Effect sensor interface
Pressure switch interface
Greater than 95% efficiency
An 8 bit micro controller has been chosen to reduce cost. A digital signal processor
increases the cost of the controller dramatically.
Since the motor will have either an ungrounded Wye or a delta internal phase
connection, a 3-phase full bridge output is required to drive the motor.
Motor current limiting is required to ensure that no more than 27 amps flows through
the motors stator windings.
A cabin temperature sensor is needed to provide information on when to reduce motor
A 12-volt to 5-volt Hall Effect sensor interface is needed to drop down the sensor
signal level to 5V, which is compatible with 5-volt logic of the micro controller. The
pressure switch interface needs to perform the same task as the Hall Effect interface.
A target efficiency of 95% has been set to keep heat-sinking requirements to a
minimum. As a direct result, the size of final design will be reduced.
Chapter 4 Hardware Implementation 4.1 Hardware design and component selection
The overall hardware design was broken down into the following subsystems:
• MOSFET bridge
• Gate drive circuit
• Power supply
• Current sense amplifier
• Hall Effect sensor interface
• Pressure switch interface
• Micro controller circuit
• Temperature sensor
A detailed description of the different subsystems is provided.
4.2 MOSFET Bridge
A 3-phase full bridge arrangement was chosen for the power interface between the
motor and controller. The full bridge was chosen for it higher torque output
capability over a half bridge arrangement. The purpose of the bridge circuit is to
enable each of the three motor phases to be switched on as required by the motor truth
Due to the large currents each MOSFET has flowing through it, the potential exists to
have a very large power dissipation through the device. Figure 7 shows the
connection of the three-phase transistor bridge along with the series gate current
limiting resistors and current sense resistor.
Figure 7 MOSFET Bridge Schematic 
To provide stator current feed back to the motor controller, a series 0.005-ohm sense
resistor, Rsense1 was included in the circuit. At full load (Imax=23.8A), the voltage
across the sense resistor reaches 0.125 volts. The expected power dissipated across
the resistor was Imax2xRsense1 = 2.83 watts. The particular resistor value was chosen
purely to minimise the power dissipated in the device.
To provide reliable operation, the transistors in the three-phase bridge had to meet
certain specifications. The new 42V automotive standard dictated that MOSFETs be
capable of 75-volt operation. They also had to have low drain-source resistance to
minimise conduction losses. Additionally, N-channel transistors were required to
reduce the number of different part numbers in the design.
To achieve these requirements, a new 42-volt automotive MOSFET from
International Rectifier, the IRF3808 was chosen.
IRF3803 Specs 
0.007-ohm drain source resistance
Expected conduction losses were calculated using the following formula:
2onon on ds
tP I RT
where Rds is the drain source resistance of the MOSFET, Ion the full load current, ton is
the time for which the switch is on and Ts is the switching period.
Worst case conduction losses occur when the converter is running at 100% duty cycle,
that is under full load. Under this condition, each transistor is switch on for 33% of
each electrical cycle. The power dissipated across the drain-source junction is 1.32
Watts per transistor.
Expected switching losses were calculated using the following formula:
1 ( )2
on offsw d o s c cP V I f t T= +
where Vd is the supply voltage, Io is the current flowing through the device prior to
turn off, fs is the switching frequency, tcon is the turn on time of the MOSFET and tcoff
is the turn off time of the MOSFET.
Using tcon and tcoff times obtained from the IRF3808 datasheet, the worst case
switching losses worked out to be 2.03 Watts per transistor. This occurred under full
Overall expected efficiency:
Pswtotal = 6 x 2.03 = 12.2 Watts
Pontotal = 6 x 1.32 = 7.9 Watts
Ploss total = 20.1 Watts this occurs when the motor controller is running at full power
Therefore expected efficiency, _
out loss total
= 10001000 20.1
4.3 Gate Drive
The gate drive circuit forms the interface between the micro controller and the power
MOSFETs. The gate drive circuit has two purposes. Firstly, it buffers the gate
signals generated by the micro controller. The micro controller can only source a
maximum of 20mA from each pin. The peak charging current required to turn
MOSFETs may be as high as 2 amps. This is due to the high switching frequency
used along with the inherent gate capacitance of the MOSFET.
The second purpose of the gate drive circuit is to generate the gate voltages required
to activate the topside transistor. To turn on an N-channel FET, the gate source
voltage must be greater than the inherent threshold voltage i.e. Vgs>Vth. This implies
that in order to turn on transistors Q1 of figure2, the gate voltage would need to be
VphaseA+Vth. If the voltage across phase A is 42 volts, and 12 volts were required to
turn the transistor on, a gate voltage of 54 volts would be needed.
Since the supply voltage is only 42 volts, high side gate drivers incorporate
bootstrapping techniques to generate the required voltages. The effective high side
gate voltage generated by the gate driver is given by:
g phaseA d4V =V + 12V - V
where Vd4 is the forward voltage of diode, d4.
Figure 8 Gate Drive Schematic 
The gate driver chosen for the design was an International Rectifier IR2101. It has in
a single 8-pin package both a high and low side gate driver. As such, one IR2101 is
capable of driving one MOSFET pair. Since the motor controller is intended for a
three-phase motor, there are three identical gate driver circuits.
From figure 8, U4 is the IR2101 gate driver; diode D4 and capacitor C8 form the
bootstrapping arrangement for the high side gate driver. MOSFET Q1 is the topside
transistor and Q2 is the low side transistor. Resistors RG1 and RG2 are 15 ohm series
current limiting resistors. There sole purpose is to limit the initial gate inrush current
to protect the gate drivers.
Pulse width modulation (PWM) is applied to the low side transistors while the high
side switches are simply on or off.
IR2101s Specs 
Logic level inputs
Reverse voltage immune
Bootstrap operational up to +600 volts
10 to 20 volt supply
Up to 400 kHz switching frequency (thermal limitation)
4.4 Power Supply
A power supply circuit was needed to provide power to logic level components as
well as other components that were unable to operate from the 42-volt supply rail.
The gate drive circuitry, signal amplifier, and Hall Effect sensors required 12 volts to
operate while all of the digital hardware needed 5V. It was decided to create a +12
volt rail from which the 5volt supply would be derived.
Linear regulators were out of the question for stepping 42 volts down to 12 volts. The
main reason was the large amount of power that would have been dissipated across
the linear regulator. Also, commonly and cheaply available regulators only supported
input voltages up to 36 volts. An estimated 300 mA was required from the +12-volt
rail. From a linear regulator the power dissipation Preg would be:
( ) ( )reg cc out outP = V -V I = 42-12 0.3 9watts× =
for a power output of 3.6 watts.
A switch mode regulator was the logical solution for the 12-volt supply. The
inexpensive LM2574HVN-adj buck regulator was chosen. The efficiency of this
regulator was 84%.
+60 volt input
52kHz switching frequency
500 mA output
Figure 9 Power Supply Schematic 
From figure 9, diode D7 (1N4148), inductor L1 (330uH) and capacitor C4 (220uF)
form the output filter for the buck converter. Variable resistor R6 (500kΩ) provides
feedback to the regulator and enables the output voltage to be precisely set. Capacitor
C5 (0.1uF) is a bypass capacitor for high frequency noise.
The 5-volt supply was derived using a linear regulator running off the 12-volt rail. An
LM7805 regulator was used.
4.5 Current Sense Amplifiers
The current sense amplifiers were required to provide motor current information to
the micro controller. Current was sensed in both directions. Under normal operation,
the current flows from the +42 volt rail, through the motor and to ground through the
current sense resistor. When the motor under goes braking, current flows from
ground, through the motor and onto the +42 volt rail. The current needs to be limited
to 23.8 amps in both directions to prevent damage to the motors stator winding.
Taking direct current measurements from the sense resistor does not utilise the full
dynamic range of the analogue to digital converter (ADC) inside the micro controller.
Therefore, the current signal needs to be amplified. At full operating current the
voltage across Rsense is 0.119 volts. A gain of 39 provides the micro controller with
4.64 volts when the current limit is reached. The resistor values required to achieve
this gain are standard values. It also insures that if the current limit is exceeded, the
micro controller has enough headroom left to be able to detect the over current
Figure 10 Current Sense Amplifier Schematic 
A single supply, rail-to-rail opamp, the LMV324 was chosen. The opamp is supplied
from the +5V rail, ensuring that the micro controllers ADC doesnt see more than 5V
on its inputs. The current signal is amplified differentially to avoid any DC offset due
to opamp bias currents. The gain of the opamp circuits is determined by the following
14 1615 17
R RGR R
4.6 Hall Effect Sensor Interface
Most brushless DC motors have incorporated in the stator several Hall Effect sensors.
These sensors provide rotor position information to the motor controller. Hall effect
sensors are open collector devices as shown in figure 6.
Figure 11 Open Collector Hall Effect Sensor 
These devices require a pull up resistor from the collector to a positive supply voltage.
In this case the sensor is pulled up to +12volts. The micro controller can only support
input voltages up to +5V. To clamp the output voltage, 5.1-volt zenner diodes are
connect in reverse bias between the output and ground. To minimise power
dissipation in the Hall Effect sensors by limiting current, 10kΩ pull up resistors are
Figure 12 Hall Effect Sensor Interface Schematic 
4.7 Pressure Switch Interface
The pressure switch interface allows the connection of pressure switches to the micro
controller. Pressure switches are normally closed devices. When the pressure applied
to the switch falls below a certain level, the switch becomes open.
Figure 13 Pressure Switch Interface Schematic 
When the pressure switches are connected and the systems pressure is above the
minimum level, they are required to produce 0 volts at nodes Hpressure and
Lpressure. When the system pressure drops below a safe level the switches need to
create +5 volts.
Using resistor values:
When one or both switches are closed (system pressure OK), the output voltage is:
outV volts = =
This will be read by the micro controller pin as logic low.
When one or both switches are open (system pressure low), the output voltage is:
since there is no current path.
Diodes D8 and D9 are 5.1 volt zenner diodes which clamp the voltage on the micro
controller pins to +5.1 volts.
4.8 Micro Controller
An Atmel Mega8L, 8 Mhz micro controller was chosen for the task of performing the
logic operations required to commutate and control the motor. A micro controller was
chosen over a digital signal processor (DSP) to reduce cost and lower the complexity
of the associated hardware. Also, development tools and support were readily
available for the AVR processors.
Figure 14 Micro Controller Schematic 
From figure 14, switches, S1, S2 and S3 are input switches. They allow user control
of certain motor controller functions such as direction, mode, start/stop. Headers J5
and J6 are connection points for high side and low side pressure switches. Light
emitting diodes (LEDs) LED1, LED2 and LED3 serve as indicators to signal certain
conditions inside the motor controller.
Component, Y1 is an 8 MHz crystal. Capacitors C6 and C7 are crystal stabilizing
capacitors. Resistor, R7 is a pull up resistor for the micro controller reset pin.
The micro controllers ADC has a +5-volt reference. Pulse width modulation (PWM)
is provided from PORTB1, PORTB2 and PORTB3.
Atmel AVR Mega8L Specs 
8 MIPS at 8 MHz clock
3.3 to 5V operation
3 8-bit PWM channels
5 10-bit ADC channels
3 internal timer units
4.9 Temperature Sensor
Temperature sensor information is used to control motor speed. When the desired
temperature has been reached, the motor can be run at lower speed. A national
instruments LM35 was chosen for the application since no further external
components are required. The temperature sensor is connected to PORTC3.
Figure 15 Temperature Sensor Schematic 
1mV per degree celcius
Chapter 5 Firmware Implementation Reliable firmware was critical to reliable motor operation. The micro controller is
required to manipulate three PWM channels and three IO channels appropriately to
commutate the motor and provide speed control.
The firmware was written in the C programming language using Codevision AVR
Ideally, the firmware was going to perform the task of a finite state machine.
However, the changes in Hall Effect transition was not seen by the controller quick
enough, resulting is skipped states and commutation error. The firmware had to be
purely combinatorial. The following body of code outlines commutation generation
and speed control: //Commutation code. Motor running with PWM if((S1==0) && (S2==1) /*&& (pressure==1) && (Imax==0)*/) if((H1==1)&&(H2==0)&&(H3==0)) if (!startedTiming && throughEnd) ++loops; /*if (loops >= CHECK_LOOPS) // Retrieve and reset the timer // (0xFF-TCNT0)*(1/7813) = Time For Revolution in seconds // 60/Rev Time = Revolutions/Second motorSpeed = (CHECK_LOOPS*7813*60/(timerTicks + (0xFF-TCNT0))); if (motorSpeed > MOTOR_RPM && PWM > 0) int diff; diff = motorSpeed-MOTOR_RPM; PWM -= (diff/CHANGE_DIVISOR) + 1; if (PWM < MIN_PWM) PWM = MIN_PWM; else if (motorSpeed < MOTOR_RPM && PWM < 0xFF) int diff; diff = MOTOR_RPM-motorSpeed; PWM += (diff/CHANGE_DIVISOR) + 1; if (PWM > MAX_PWM) PWM = MAX_PWM; TCNT0 = 0xFF; timerTicks = 0; loops = 0; */ startedTiming = 1; throughEnd = 0;
PORTB=t1; OCR1A=PWM; OCR1B=0x00; OCR2=0x00; if((H1==1)&&(H2==1)&&(H3==0)) PORTB=t2; OCR1A=PWM; OCR1B=0x00; OCR2=0x00; if((H1==0)&&(H2==1)&&(H3==0)) PORTB=t3; OCR2=PWM; OCR1A=0x00; OCR1B=0x00; if((H1==0)&&(H2==1)&&(H3==1)) PORTB=t4; OCR2=PWM; OCR1A=0x00; OCR1B=0x00; if((H1==0)&&(H2==0)&&(H3==1)) PORTB=t5; OCR1B=PWM; OCR2=0x00; OCR1A=0x00; if((H1==1)&&(H2==0)&&(H3==1)) throughEnd = 1; startedTiming = 0; PORTB=t6; OCR1B=PWM; OCR2=0x00; OCR1A=0x00; //remove this and try if((S1==1)&&(S2==1)) OCR1B=0x00; OCR1A=0x00; OCR2=0x00; PORTB=0x00; Speed control is achieved by clearing a timer in the first state and then reading it in the last state. The time taken for one electrical cycle is simply the timer value multiplied by the appropriate scaling factor. The timer values are averaged to reduce error. Averaging does however slow down the motor controllers response to load or supply voltage changes. If the motor speed is less than the desired speed, the pulse width modulator (PWM) duty cycle is increases. If speed is higher than desired, duty cycle is decreased. When a low-pressure condition occurs, the motor must be shut down. Monitoring the status of the pressure switches does this //Motor free wheel on pressure if (pressure ==0)
PORTB=0x00; OCR1B=0x00; OCR1A=0x00; OCR2=0x00; PORTB=0x00; //pressure switch code if((PIND.6==1)&&(PIND.7==1)) pressure=1; if((PIND.6==1)&&(PIND.7==0)) pressure=0; if((PIND.6==0)&&(PIND.7==1)) pressure=0; if((PIND.6==0)&&(PIND.7==0)) pressure=0;
When a low-pressure condition is detected, the motor is free wheeled to a stop by
turning off all gate signal outputs.
Temperature control is provided by the following code: //temperature sensor code
Once the cabin temperature reaches a preset temperature, the motor desired speed is
Current limiting is implemented as follows: //current limit code limit to 25 amps
PORTD.5 = 1;
PORTD.5 = 0;
If the motor current exceed 25 amps, a flag is set. This flags results in all outputs
being turned off. A variable was not used for the current limit as the limit is a hard
limit and should not be changed.
A copy of the micro controller code is available in appendix 3.
Chapter 6 Product Evaluation and Results 6.1 Motor Truth table
To drive the motor using Hall Effect sensor information, it was necessary to extract
the truth table from the motor. This was accomplished as follows:
1. Connect all three Hall sensor outputs to an oscilloscope. 2. Arbitrarily label the stator phase connections, phase A, phase B and phase C. 3. Connect the oscilloscope such as to measure phase voltage Vac. 4. Turn the rotor by hand, observe and record the state of each hall effect sensor
at the peak of the sinusoidal back EMF waveform. 5. Repeat steps 3 and 4 but change the phase voltage being measured. The
process is complete when all six states are known.
Clockwise Phase Hall 1 Hall 2 Hall 3 Switch Vac 1 0 0 1,6 Vbc 1 1 0 3,6 Vba 0 1 0 3,2 Vca 0 1 1 5,2 Vcb 0 0 1 5,4 Vab 1 0 1 1,4 Counter clockwise Vca 0 1 1 5,2 Vcb 0 0 1 5,4 Vab 1 0 1 1,4 Vac 1 0 0 1,6 Vbc 1 1 0 3,6 Vba 0 1 0 3,2 Table 2 Motor truth table
Table 2 summarises the motor truth table. Also included is the transistor pair that
must be switched to energise the required phases. Both the forward and reverse truth
table has been included in the event that the motor is geared or if the load is coupled
to the flywheel as opposed to the shaft.
A prototype circuit was built and results were obtained.
Figure 16 Motor controller circuit board
Figure 1 shows the motor controller circuit board. A ground plane was placed under
the lower power part of the circuit to reduce noise effects and increase the heat
spreading area. Reducing noise effect is particularly important to avoid false gate
triggering. False gate triggering would lead to cross conduction, which in turn would
lead to large amounts of dissipated power. MOSFET failure may or may not occur
depending of the temperature of the devices.
State machine coding was not possible due to limitation of the micro controller. The
changes in Hall Effect sensor states were not detected fast enough for the state
machine to be effective. As a result, at high motor speeds, some states were skipped.
This defeated the purpose of having a state machine. The state machine code was
written in such a manner that if an invalid state was detected, the motor controller
would cease to operate until reset. This resulted in proper operation at low speeds up
to 400 rpm but resulted in a fault condition for higher speeds.
An alternate approach would have been to use a micro controller with three input
capture units, or a digital signal processor (DSP). The interrupt associated with the
input capture units would have served as the trigger for a change of state. A field
programmable gate array (FPGA) may also have been used to produce an application
specific IC (ASIC), however, cost would also have been increased.
6.3 Efficiency and Performance
Efficiency measurements were taken with surprising results. The efficiency was
measured by measuring the power supply line current and voltage. The measured
power was compared with motor current and motor supply voltage. The motor
current was measured by measuring the voltage across the current sense resistor. The
exact resistance of the sense resistor was determined by driving a constant current (1
amp) through the resistor and measuring the resulting voltage across it. The exact
resistance was calculated to be 0.0053 ohms. The motor supply voltage was used as
the input voltage since during efficiency testing the motor was run with a pulse width
of 100%. This meant the motor would be energised with the full supply voltage of 42
The mechanical power was not measured at the motor shaft. It was not required as
the project specification defined outputting 1kW from the controller, not the motor.
Motor Phase Measurements MOSFET Measurements
Power Supply Measurements
Motor Power Vds(on)
Pcond per FET
Total Conduction loss
Switching loss Line Vin Pin Efficiency
20.9 100 501.6 0.165 1.15 6.90 5.103 21.4 24 513.6 97.14 20.9 100 627 0.161 1.12 6.73 17.2702 21.7 30 651 95.88 21.2 100 763.2 0.191 1.35 8.10 13.5016 21.8 36 784.8 96.89 19.4 100 814.8 0.14 0.91 5.43 7.168 19.7 42 827.4 98.16
Table 3 Summary of efficiency 
Switching loss was deduced by subtracting all of the measurable losses and output
power from the input power. A maximum theoretical efficiency of 98.2% was
calculated. An efficiency of 98.16% was recorded for an 827-watt output. The motor
controller couldnt be tested at 1kW output due to the lack of power supplies from
which to run the circuit. The 42-volt test was conducted by running the motor from
30 volts to cool down the test room. This reduced the load on the compressor slightly.
Then 42 volts was applied.
Conduction losses were determined by measuring the drain to source voltage and
multiplying it by the motor current. The losses were calculated on a per FET basis
then multiplied to get a total power dissipation.
Time didnt permit attaching heat sinks to the transistors. The circuit board was
placed in the cold air stream of the air conditioner for cooling. Due to the small
surface area of the TO-220 transistor packages, the MOSFETs did get hot. The heat
was transferred through the transistor legs to the printed circuit board (PCB) tracks.
After 30 minutes of operation, the copper tracks were discoloured. Some tracks had
begun to lift off the board. Appropriate heat sinking would have avoided this
In trying to keep the controller compact, tracks could not be made as wide as required.
Instead, copper braid was soldered onto high current tracks. The tracks where then
flooded with solder.
One of the purposes of this project was to produce a low cost solution. This part of
specification was comfortably met. Table 4 lists all parts used in the evaluation
board. The total bill of materials was $92.90. The printed circuit board measured
150mm x 100mm. At $2.20 per square inch, the total board cost was $52.80. The
board was a large part of the overall cost. This was unavoidable since a plated
through board was required due to the number of surface mount components. The
overall cost of the hardware was $145.70.
Part Type Designator Footprint Description Value Supplier Order Code Price C1 rb.3/.6 Capacitor 1000uF Farnell 345-1343 2.92 C10 Rad-0.2 Capacitor 0.47uF Farnell 218-522 0.82 C11 Rad-0.1 Capacitor 0.1uF Farnell 303-896 0.34 C12 Rad-0.1 Capacitor 0.1uF Farnell 303-896 0.34 C14 Rad-0.1 Capacitor 0.1uF Farnell 303-896 0.34 C2 rb.3/.6 Capacitor 1000uF Farnell 345-1343 2.92
C3 rb-.2/.4 Capacitor 220uF Farnell 580-480 0.69 C4 rb-.2/.4 Capacitor 220uF Farnell 580-480 0.69 C5 Rad-0.2 Capacitor 0.1uF Farnell 303-896 0.34 C6 805 Capacitor 22pF Farnell 301-9184 0.13 C7 805 Capacitor 22pF Farnell 301-9184 0.13 C8 Rad-0.2 Capacitor 0.47uF Farnell 218-522 0.82 C9 Rad-0.2 Capacitor 0.47uF Farnell 218-522 0.82 D1 axial-0.3 Zener Diode 5.1V Farnell 316-2412 0.08 D10 axial-0.3 Zener Diode 5.1V Farnell 316-2412 0.081N4148 D11 axial-0.3 Schottky Diode Farnell 368-106 0.03 D2 axial-0.3 Zener Diode 5.1V Farnell 316-2412 0.08 D3 axial-0.3 Zener Diode 5.1V Farnell 316-2412 0.081N4148 D4 axial-0.3 Schottky Diode Farnell 368-106 0.031N4148 D5 axial-0.3 Schottky Diode Farnell 368-106 0.031N4148 D6 axial-0.3 Schottky Diode Farnell 368-106 0.031N4148 D7 axial-0.4 Schottky Diode Farnell 368-106 0.03 D8 axial-0.4 Zener Diode 5.1V Farnell 316-2412 0.08 D9 axial-0.4 Zener Diode 5.1V Farnell 316-2412 0.08Fuse F1 pctb2n Fuse connector EWS 1Halls J1 sip-5 Hall Connector EWS 0Hi J5 pctb2n Switch Connector EWS 1Lo J6 pctb2n Switch Connector EWS 1 L1 inductor 0.5 A inductor 330uH Farnell 322-7340 1.61 LED1 LED EWS 0.3 LED2 led EWS 0.3 LED3 led EWS 0.3IRF3710 Q1 to220a N-Channel MOSFET Polykom 3.7IRF3710 Q2 to220a N-Channel MOSFET Polykom 3.7IRF3710 Q3 to220a N-Channel MOSFET Polykom 3.7IRF3710 Q4 to220a N-Channel MOSFET Polykom 3.7IRF3710 Q5 to220a N-Channel MOSFET Polykom 3.7IRF3710 Q6 to220a N-Channel MOSFET Polykom 3.7 R1 805 10k Farnell 911-975 0.08 R12 805 10k Farnell 911-975 0.08 R13 805 10k Farnell 911-975 0.08 R14 805 39k Farnell 912-049 0.08 R15 805 1k Farnell 911-859 0.08 R16 805 39k Farnell 912-049 0.08 R17 805 1k Farnell 911-859 0.08 R2 805 10k Farnell 911-975 0.08 R3 805 10k Farnell 911-975 0.08 R4 805 100 Farnell 911-732 0.08 R5 805 100 Farnell 911-732 0.08 R6 vr-5 Potentiometer 500k Farnell 349-318 3.15 R7 805 1k Farnell 911-859 0.08 R8 805 100 Farnell 911-732 0.08 RG1 1206 Gate resistor 15 Farnell 308-7566 0.05 RG2 1206 Gate resistor 15 Farnell 308-7566 0.05 RG3 1206 Gate resistor 15 Farnell 308-7566 0.05 RG4 1206 Gate resistor 15 Farnell 308-7566 0.05 RG5 1206 Gate resistor 15 Farnell 308-7566 0.05
RG6 1206 Gate resistor 15 Farnell 308-7566 0.05 Rnet1 sip-5 Connector 10k Farnell 911-975 0.080.005 Ohm Rsense1 Cshunt Sense resistor 0.005 Farnell 327-4780 2.45 S1 sip-2 EWS 0 S2 sip-2 EWS 0 S3 sip-2 EWS 0LM7805 U1 to220a Linear regulator 5V Farnell 701-853 1.09LM2574HVN U2 DIP8 Switching regulator adjustable Farnell 412-5708 7.39ATMEGA8 U3 dip28s Micro controller Farnell 391-7940 14.33IR2101 U4 dip-8 Gate driver Farnell 360-7010 6.3IR2101 U5 dip-8 Gate driver Farnell 360-7010 6.3IR2101 U6 dip-8 Gate driver Farnell 360-7010 6.3LM358 U7 dip-8 Op amp Farnell 301-2748 0.55LM35 U8 TO92/E Temp. sensor NSC samples 0 Y1 xtal-1 Crystal 8 Mhz Farnell 103-914 3.98 Total 92.9Table 4 Bill of materials
The IR2101 gate drivers were one of the most expensive components since three parts
were required. The IRF3808 transistors were extremely well priced. They were the
only 75-volt automotive rated transistors available at design time. They also meet all
of the required specifications for drain-source resistance.
Chapter 7 Future Developments
Future improvements to the motor controller design may be made to make the
controller more flexible. For its intended application, the current design is
satisfactory. However, to run motors at higher speeds, a faster controller would be an
option. The best way to make a universal controller would be using a field
programmable gate array (FPGA) to produce an application specific controller.
Though the MOSFET bridge, gate driver, power supplies and sensor interfaces
worked as required, a redesign of the digital controller would provide a significant
improvement to the overall motor controller. A digital signal processor would be the
logical choice. Alternatively, a dedicated, off the shelf controller IC could be used
along with a small micro controller to perform the control loop calculations. This
would alleviate the need for external gate drivers, reducing the cost of the solution
along with the problem of slow controllers. A possible solution would be using the
Allegro A3932 coupled to an 8 bit micro controller.
A further size reduction may be possible by using a MOSFET pack rather than
discrete transistors. However, finding a FET pack with the required characteristics
may prove difficult while the 42 volt automotive standard is still in its early days.
Currently available transistor packs would reduce the overall efficiency of motor
controller due to there higher drain to source resistance.
A suitable enclosure for the motor controller would add to its appeal and practicality.
Integrating the heat sinks into the package would reduce the size of the overall
solution. Aluminium would ideally be used.
Chapter 8 Conclusion Though this project resulted in a successful prototype, the potential exist for
improvement to certain parts of the design. Most parts of the design functioned
perfectly, while others could have been improved. The power interface, made up of
the MOSFET bridge, gate driver and current sensing amplifier performed well. The
digital part of the motor controller, though performed well for low speed, could have
been improved. A redesign of the digital hardware would have been required.
The results obtained outlined the success of the prototype circuit for its intended
application. The measured efficiencies were very close to the calculated efficiency.
At 42-volt operation, an efficiency of 98.16 was measured. The calculated maximum
efficiency was 98.2%.
Design factors, heat sinking in particular needed more attention. The effects of heat
sinking didnt become evident until the controller was tested under full load. Also
made evident was the need to modify the printed circuit board to carry the required
currents without resulting in board stress and damage.
 Advanced PM brushless DC motor control and system for electric vehicles
Fang Lin Luo; Hock Guan Yeo;
Industry Applications Conference, 2000. Conference Record of the 2000 IEEE ,
Volume: 2 , 2000
Page(s): 1336 -1343 vol.2
 Permanent magnet brushless DC motors for consumer products
Bentouati, S.; Zhu, Z.Q.; Howe, D.;
Electrical Machines and Drives, 1999. Ninth International Conference on (Conf. Publ.
No. 468) , 1999
Page(s): 118 122
 Electric drives for pump, fan, and compressor loads in automotive applications
Industrial Electronics, 1995. ISIE '95., Proceedings of the IEEE International
Symposium on , Volume: 1 , 10-14 Jul1995
Page(s): 80 -85 vol.1
 Automotive electrically driven air conditioner system
Oldenkamp, J.L.; Erdman, D.M.;
Automotive Power Electronics, 1989 , 28-29 Aug 1989
Page(s): 71 72
 Design of an integrated motor/controller drive for an automotive water pump
Harris, N.C.; Jahns, T.M.; Surong Huang;
Industry Applications Conference, 2002. 37th IAS Annual Meeting. Conference
Record of the , Volume: 3 , 2002
Page(s): 2028 -2035 vol.3
 A novel based-based sensorless brushless DC (BLDC) motor drive for automotive
Jianwen Shao; Nolan, D.; Teissier, M.; Swanson, D.;
Industry Applications Conference, 2002. 37th IAS Annual Meeting. Conference
Record of the , Volume: 4 , 2002
Page(s): 2386 -2392 vol.4
 Texas Instruments Appl Note SPRU469
 Electrical Machines for Drives
Slemon, G. R.;
Power Electronics and Variable Frequency Drives, 1996, p62 65. IEEE Press
 MC33035, NCV33035 Datasheet, On Semiconductor, 2003
 Atmel AVR Atmega8 Datasheet, Atmel Corporation, 2003
 HP InfoTech. Codevision AVR. 2003 (v1.23.8c) Available:
 IRF3808 Datasheet, International Rectifier, 2003
 IR2101 Datahseet, International Recifier, 2003
D C B A
ze B Dat
J5 Hi 12
1 2 3 4 5 6
#include <mega8.h> #include <math.h> #define H1 PINC.0 #define H2 PINC.1 #define H3 PINC.2 #define S1 PIND.0 #define S2 PIND.1 #define S3 PIND.2 #define t1 0x12 #define t2 0x22 #define t3 0x28 #define t4 0x09 #define t5 0x05 #define t6 0x14 int PWM=150; int temperature=0; int current=0; //char pressure=1; char Imax=0; volatile long timerTicks = 0; int startedTiming = 0; int throughEnd = 1; long motorSpeed; int loops = 0; int MOTOR_RPM=900; #define CHECK_LOOPS 5 //#define MOTOR_RPM 1500 #define CHANGE_DIVISOR 50 #define FIRST_ADC_INPUT 3 #define LAST_ADC_INPUT 5 unsigned char adc_data[LAST_ADC_INPUT-FIRST_ADC_INPUT+1]; #define ADC_VREF_TYPE 0x20 // ADC interrupt service routine // with auto input scanning
#pragma savereg- interrupt [ADC_INT] void adc_isr(void) #asm push r26 push r27 push r30 push r31 in r30,sreg push r30 #endasm register static unsigned char input_index=0; // Read the 8 most significant bits // of the AD conversion result adc_data[input_index]=ADCH; // Select next ADC input if (++input_index > (LAST_ADC_INPUT-FIRST_ADC_INPUT)) input_index=0; ADMUX=(FIRST_ADC_INPUT|ADC_VREF_TYPE)+input_index; // Start the AD conversion ADCSRA|=0x40; #asm pop r30 out sreg,r30 pop r31 pop r30 pop r27 pop r26 #endasm temperature=(char) ((int) adc_data*100)/256; current=adc_data; #pragma savereg+ // Timer 0 overflow interrupt service routine interrupt [TIM0_OVF] void timer0_ovf_isr(void) timerTicks += 0xFF; void main(void) PORTB=0x00; DDRB=0x3F; PORTC=0x00; DDRC=0x00; PORTD=0x00; DDRD=0x38;
// Timer/Counter 0 initialization // Clock source: System Clock // Clock value: 7.813 kHz TCCR0=0x05; TCNT0=0x00; // Timer/Counter 1 initialization // Clock source: System Clock // Clock value: 8000.000 kHz // Mode: Ph. correct PWM top=00FFh // OC1A output: Non-Inv. // OC1B output: Non-Inv. // Noise Canceler: Off // Input Capture on Falling Edge TCCR1A=0xA1; TCCR1B=0x01; TCNT1H=0x00; TCNT1L=0x00; OCR1AH=0x00; OCR1AL=0x00; OCR1BH=0x00; OCR1BL=0x00; TCCR2=0x61; ASSR=0x00; TCNT2=0x00; OCR2=0x00; TCNT0=0xff; // Timer/Counter 2 initialization // Clock source: System Clock // Clock value: 8000.000 kHz // Mode: Phase correct PWM top=FFh // OC2 output: Non-Inverted PWM ASSR=0x00; TCCR2=0x61; TCNT2=0x00; OCR2=0x00; // External Interrupt(s) initialization // INT0: Off // INT1: Off GICR|=0x00; MCUCR=0x00; // Timer(s)/Counter(s) Interrupt(s) initialization TIMSK=0x00 | 0x01;
// Analog Comparator initialization // Analog Comparator: Off // Analog Comparator Input Capture by Timer/Counter 1: Off // Analog Comparator Output: Off ACSR=0x80; SFIOR=0x00; // ADC initialization // ADC Clock frequency: 62.500 kHz // ADC Voltage Reference: AREF pin // ADC High Speed Mode: Off // ADC Auto Trigger Source: None // Only the 8 most significant bits of // the AD conversion result are used ADMUX=FIRST_ADC_INPUT|ADC_VREF_TYPE; ADCSRA=0xCF; SFIOR&=0xEF; #asm("sei") while (1) //Commutation code. Motor running with PWM if((S1==0) && (S2==1)) if((H1==1)&&(H2==0)&&(H3==0)) if (!startedTiming && throughEnd) ++loops; if (loops >= CHECK_LOOPS) // Retrieve and reset the timer // (0xFF-TCNT0)*(1/7813) = Time For Revolution in seconds // 60/Rev Time = Revolutions/Second motorSpeed = (CHECK_LOOPS*7813*60/(timerTicks + (0xFF-TCNT0))); if (motorSpeed > MOTOR_RPM && PWM > 0) int diff; diff = motorSpeed-MOTOR_RPM; PWM -= (diff/CHANGE_DIVISOR) + 1; if (PWM < MIN_PWM) PWM = MIN_PWM; else if (motorSpeed < MOTOR_RPM && PWM < 0xFF)
int diff; diff = MOTOR_RPM-motorSpeed; PWM += (diff/CHANGE_DIVISOR) + 1; if (PWM > MAX_PWM) PWM = MAX_PWM; TCNT0 = 0xFF; timerTicks = 0; loops = 0; startedTiming = 1; throughEnd = 0; PORTB=t1; OCR1A=PWM; OCR1B=0x00; OCR2=0x00; if((H1==1)&&(H2==1)&&(H3==0)) PORTB=t2; OCR1A=PWM; OCR1B=0x00; OCR2=0x00; if((H1==0)&&(H2==1)&&(H3==0)) PORTB=t3; OCR2=PWM; OCR1A=0x00; OCR1B=0x00; if((H1==0)&&(H2==1)&&(H3==1)) PORTB=t4; OCR2=PWM; OCR1A=0x00; OCR1B=0x00; if((H1==0)&&(H2==0)&&(H3==1)) PORTB=t5; OCR1B=PWM; OCR2=0x00; OCR1A=0x00;
if((H1==1)&&(H2==0)&&(H3==1)) throughEnd = 1; startedTiming = 0; PORTB=t6; OCR1B=PWM; OCR2=0x00; OCR1A=0x00; /* //remove this and try if((S1==1)&&(S2==1)) OCR1B=0x00; OCR1A=0x00; OCR2=0x00; PORTB=0x00; */ /* //free wheel the motor code //Motor free wheel on pressure and current else PORTB=0x00; OCR1B=0x00; OCR1A=0x00; OCR2=0x00; PORTB=0x00; */ //pressure switch code /*if((PIND.6==1)&&(PIND.7==1)) pressure=1; if((PIND.6==1)&&(PIND.7==0)) pressure=0; if((PIND.6==0)&&(PIND.7==1)) pressure=0; if((PIND.6==0)&&(PIND.7==0)) pressure=0;
*/ //temperature sensor code /*if(temperature>20) MOTOR_RPM=1300; PORTD.3=1; PORTD.4=0; if(temperature<=20) MOTOR_RPM=1000; PORTD.3=0; PORTD.4=1; */ //current limit code limit to 19.5 amps /*if(current>250) Imax=1; PORTD.5 = 1; else Imax=0; PORTD.5 = 0; */ ;