Upload
truongtuyen
View
220
Download
0
Embed Size (px)
Citation preview
11 June 2013
HYBRICYCLE
Project Report CMPE / EE 123C
Page 2
Contents
Team Members ................................................................................................................................... 3
Abstract ............................................................................................................................................... 4
Motivation .......................................................................................................................................... 4
Objective ............................................................................................................................................. 4
Requirements .................................................................................................................................. 5
Research.............................................................................................................................................. 5
E-bike ............................................................................................................................................... 5
Structure ......................................................................................................................................... 6
Battery ............................................................................................................................................. 8
Regeneration ................................................................................................................................. 12
Motor Control ............................................................................................................................... 14
Power Systems .............................................................................................................................. 16
Motor Characterization ................................................................................................................. 18
System Overview .............................................................................................................................. 21
Approach ........................................................................................................................................... 21
Controls ......................................................................................................................................... 21
Structure ....................................................................................................................................... 24
Power Systems .............................................................................................................................. 27
Microcontroller ............................................................................................................................. 37
Drive Circuitry................................................................................................................................ 49
Regeneration ................................................................................................................................. 59
Budget ............................................................................................................................................... 71
Conclusion ......................................................................................................................................... 72
References ........................................................................................................................................ 73
Appendix ........................................................................................................................................... 75
Power Rails .................................................................................................................................... 75
Microcontroller ............................................................................................................................. 76
PWM Level Shifter ......................................................................................................................... 77
Gate Driver .................................................................................................................................... 78
H-Bridge ........................................................................................................................................ 79
Initial Regeneration Model ........................................................................................................... 79
Regeneration Buck-Boost Circuit .................................................................................................. 80
Final Regeneration Circuit with Overvoltage Protection .............................................................. 81
Microcontroller Code .................................................................................................................... 82
Page 3
Team Members
Chris McNamara Undergraduate Electrical Engineer I am a 5th year electrical engineering student with a focus in power engineering. My engineering interests have to do with power distribution and also with motor controls. For the past two years I have interned in the engineering department for an electrical contractor and I recently passed the Fundamentals of Engineering exam and am now a certified Engineer in Training. I have taken both the power distribution class and the motor control class here at UCSC and I am currently enrolled in the power supply class. My chief responsibility on this project is the design of the regenerative braking system on the bicycle and I will be working closely with RJ to make sure we can properly recharge the system’s battery with the regenerated energy. I will also be assisting in any PCB designs. Travis McKane Undergraduate Electrical Engineer I am a 5th year Electrical Engineering student with a primary focus on power and analog electronics. I have some previous work experience with Maxim Incorporated where I worked with DACs and Voltage References. After graduating in the spring of 2013 I plan on finding a job in industry that deals with analog electronics/hardware design or power. My primary responsibility for this project is pedal assist for the user, which includes creating a working motor controller, along with any PCB design and layout that must be done for the project. Rafael Chavez Undergraduate Electrical Engineer I am a 5th year Electrical Engineering major with a focus in programming systems and hardware validation. My engineering interests focus on how hardware and software interact and writing the software to allow these interactions. For the past two years I have taken numerous courses here at UCSC dealing with the interactions of hardware and software including CE13 to CE121. I also have experience in hardware validation and software testing through numerous internships that I have had at IBM, the Department of Defense, and Agilent Technologies. My main responsibility in this project is to design the firmware that will run on the microcontroller and be able to control all of the functions of the HybriCycle design and therefore I will be required to work closely with all of the team members. RJ Duffner Undergraduate Electrical Engineer I am a 4th year Electrical Engineering student at the University of California Santa Cruz. My primary focuses at Santa Cruz have been Electronics and Power. I will be graduating this spring quarter with a Bachelors of Science in Electrical Engineering. After graduation, I plan to look for a job in my subfield of interest: electronics and power. My goal for this project is to learn how to use and design power electronics for useful tasks. I have some industry and project experience when I worked for a computer software company called Naehas Inc. in Palo Alto doing quality assurance testing. This background as well as my mechanical minded history will allow me to assist the team in the construction and instillation of the electric components onto the bicycle. My main responsibility on this project will be the power system.
Page 4
Abstract
Hybricycle will be an electric bicycle capable of providing pedal assistance on steep climbs or
whenever desired by the user. The bicycle will also have regenerative braking capabilities. When
specified by the user, the bike will use a brake-by-wire system to operate the motor as a generator,
simultaneously slowing the bike and recharging the battery. The system we design will be such that
most bicycles could be easily modified to include our system.
Motivation
The purpose of this project is to create a working electric bike at a fraction of the cost of normal
transportation. The environmental benefits are also readily apparent, seeing as an E-bike consumes no
fossil fuels. As a society we are leaning more towards a green alternative to everything we do, which can
mean riding your bike to work instead of driving a car. For the team this issue is a large part of why the
project is important.
Objective
The project is to design an electric bicycle capable of providing assistance to the user based on input
from the user. The user will use a twist throttle to specify how much electric assistance is desired. The
input will be handled by a microcontroller which will calculate the drive signal to be sent to the motor.
The motor will provide feedback to the microcontroller on its current rotor position. The microcontroller
will use this feedback to determine the appropriate drive signals and also the speed of the bicycle
In addition to pedal assistance the bicycle will have regenerative braking capabilities. This means that at
times specified by the user the motor will be operated as a generator to both decrease the speed of the
bicycle and to recharge the system’s power source. Special circuitry will be designed in order to ensure
efficient and safe recharging of the batteries. The microcontroller will communicate with the battery
charger to ensure that the battery is not overcharged. The battery level will be communicated to the
user via an LCD screen.
Page 5
Requirements
30 minutes of full throttle pedal assistance
Controllable pedal assistance
Back charge battery with regeneration
Display speed and battery charge level
Research
E-bike
We found that there were several features missing in current electric bicycles that could be useful to
the rider. Currently, most available electric bicycles include the most basic feature, pedal assist.
Although this is a great start at trying to remove the barrier between riders and steep hills, there are
several additional features that can be added at very little cost. These features include regenerative
braking, an LCD display, and some protection relays in order to protect the circuitry and rider.
Adding regenerative braking to the design was definitely one of our biggest motivations in doing this
project. As most electric bicycle kits do offer pedal assist in their controllers, they don’t however offer
regenerative braking. Designed and implemented with only a few components, regenerative braking can
be integrated into a current design to harvest the energy wasted as heat when the rider applies the
friction brakes.
Additionally, most riders would agree that a display showing their speed and remaining battery
power would be a useful feature in an electric bicycle conversion kit. Requiring the addition of only an
op-amp and two resistors, there is no reason why these features should not be standard in e-bike kits.
Using a simple LCD display, we were able to add the speed of the bicycle as well as the amount of charge
left in the battery for a worriless ride.
Although most of the features mentioned above are definitely features that most riders would
benefit from having on their electric bicycle kit, no one wants to pay a steep price for these sought after
Page 6
features on top of an already expensive conversion kit. Most electric bicycle kits are sold at around $500
without a battery1. Our goal is to compete with this price point while adding additional display and
regeneration features.
Structure
Choosing the bike and the placement of all the components was one of the most important parts of
this project. The main question at the beginning surrounded the type of bike to use. The first question
we asked ourselves was could we build the entire bike frame ourselves? Often, manufacturers like
Stealth Bikes USA will design custom frames so that all the electronics and components are out of the
way2. While this is much simpler for the end user when compared to a conversion kit, it is also much
more complicated to build. One example of this type of bike is shown in Figure 1.
Figure 1. Frame Integrated Electric Bike
3
The team concluded that a frame integrated design was out of the scope of the project. We chose to
focus our project on the electronics side rather than the structure. This meant that we would be building
a conversion kit. Conversion kits can be bought online and in stores and come with all the pieces and
components needed to covert a normal bicycle into an electric one. When the kit comes, the end user
will have to mount the parts and charge the battery. While this is more complicated than buying a
custom electric bike, it is also much cheaper. Conversion kits start for around $500 and can rise in price
Page 7
based on the included features4. A Stealth electric bike, like the one pictured above, can cost more than
$50005.
Since we were using off the shelf components and custom making the electronics, we had a choice
about the bike. We could use a full suspension mountain bike or a full-fledged road bike. We could also
go for a cruiser type bike for everyday use. The choice of bike would not only dictate part placement,
but it would also limit us to a certain part of the market. We choose to focus on the cruiser and
commuter section of the market. These types of bikes are usually cheap, simple and expandable.
Moreover, E-BikeKit built many of its kits with this market in mind6. While we would not be using their
electronics, we knew that by using a commuter type bike, we guaranteed that all the User Interfaces
and motor worked. Now that we had a type of market and type of bike selected, we had to pick a bike to
use. RJ had a commuter bike from Trek Bicycles that he was willing to loan to the project. This bike will
be described in detail in the approach section. With the bike set, we were then tasked with researching
all the accessories.
Electric bikes commonly have a throttle, brake, and LCD display. When we picked E-BikeKit for the
motor and controls, we locked our choices of throttle and brake. They would be mounted on the handle
bars (this is described in more detail below). However, the LCD Display was not dictated by the E-BikeKit
selection. For this project, it was desirable to have a display that was bright enough to see during the
day. This required a display with a large color contrast. We found a 16x2 display from Matrix Orbital that
contrasted white on blue7. Mounting this LCD display presented a significant design challenge. None of
the team members had any custom box design experience. This issue limited us to building a simple box
out of very simple materials.
Most bikes put the electronics in the frame triangle of the bike. This is where it is most protected
from damage. Another option was to mount the electronics on a rear bike rack. While they are not as
safe in this location, they will still be protected in a tip-over fall with the correct enclosure. While the
Page 8
rear rack would have led to a simpler design, we liked the idea of a custom box in the frame rails. We set
out to build a custom box that fit snuggly in-between the frame rails. We found that we could use the
water bottle mounts as mounts to hold the box in. These mounts are available on most cruiser bikes and
are indicated in Figure 2.
Figure 2. Typical cruiser bike frame with water bottle mounting holes indicated
8.
Designing the box to work with these four holes greatly reduced the complexity of mounting the
box. If the electronics had been heavier or the battery had been mounted in this box, we may have had
to add a third mount on the top frame rail. However, since the weight of the mounting box and inside
electronics is less than 10 pounds these four bolts will securely hold the box.
The other part of the structure that needed to be researched was the LCD box. This box is commonly
made of plastic and mounts on the handle bars with the use of zip-ties. We ended up building a small
wooden box that was painted and mounted onto the center of the handle bars using zip-ties.
Battery
Our initial battery research was broadly focused and many battery types were considered. The
group had a list of power requirements for the project and these requirements helped to guide the
battery research. The main requirement set by the group was that the bike should run at full throttle for
Page 9
30 [min]. The group decided that full throttle should supply enough power to assist the user up many if
not all hills. This full throttle power requirement lead us to choose a 1000 [W] hub motor. This large
motor is an absolute necessity as it is integral to usability of this product. For more information on the
motor selection, see the E-Bike section above.
After finishing the main power specifications, the team moved into choosing a battery. The first item
that we researched was battery sizing. In order to limit the current in the wiring and allow for more
power, a 48 [V] source was chosen over the more typical 36 [V]. At this voltage, the system will be using
20.83 [A] to deliver the maximum 1000 [W]. To ride this bike for 30 minutes at full throttle, 10.415 [AHr]
were necessary. Ultimately a 10 [AHr] battery size was selected.
After completing the sizing, the next design decision to make was selecting the battery type. While
the group researched many different battery types, Figure 3 summarizes the 3 types of batteries most
heavily considered due to their availability, cost or ease of use.
Type Price Weight Charge Density Self-Discharge Durability
Lead Acid $200 22 lbs. Poor poor 100-300 charges
Li-Ion $700 8 lbs. Best almost none up to 2000 charges
NiMH $400 14 lbs. Good will last about a month 500-600 charges
Figure 3. Battery Characteristics Chart
Figure 3 shows that while the Lithium-Ion battery is better in all performance categories, it is almost
twice as expensive as its next competitor. While the group was ready to spend the extra money if the
Lithium-Ion was necessary, the team came to the conclusion that the extra weight of the Nickel-Metal
Hydride (NiMH) batteries was acceptable to reduce costs. A 10 [AHr] NiMH battery was purchased. With
the battery chosen, the next challenge involved designing the power distribution side of the power
system.
Page 10
The last part of the battery research happened after we had selected the battery. Since we were
going to be implementing a regeneration system, we needed to research the charging considerations for
our chosen battery. This information would become a vital part of our protection schemes integrated
into the regeneration circuitry. The NiMH battery is not the easiest battery to charge. Nickel based
batteries do not have a specified charging voltage like lead-acid or Lithium batteries do9. This means that
they will charge as long as the input potential is higher than battery potential. This downside most often
comes into play in a parallel battery pack. Since all the cells are slightly different in impedance, they will
not charge equally in parallel since the currents will be different. Since our battery was a series string of
40, NiMH cells, we were able to charge the battery straight through the discharge leads versus having to
partially charge certain parts of the battery. This made the overall design of our regeneration circuitry
much simpler.
Since we know we can charge at any voltage, we then looked into the minimum and maximum
charge levels of our battery. Our NiMH battery had a nominal voltage of 1.2 [V] per cell. The 40 cells in
series then gave us the nominal 48 [V]. However, the nominal voltage can usually be thought of as the
half charge level. A typical discharge curve for an NiMH battery is shown in Figure 4.
Figure 4. NiMH Discharge Curve
10
Page 11
NiMH batteries should never be discharged below 1 [V] per cell11. At this voltage, some of the cells
will reverse potentials. This will lead to a lower capacity battery and high self-discharge. 1 [V] per cell is
our battery minimum. This would correspond to a pack voltage of 40 [V]. This number is very important
as it is necessary to turn off the motor if the battery voltage approaches this level to avoid over-
discharge. The upper limit of our battery was around 1.4 [V] per cell. This gave us a maximum voltage of
56 volts. Since regeneration would never be fully charging the battery we set the regeneration circuit to
output the maximum voltage of the battery. To fully charge a NiMH battery, it is necessary to use
complicated feedback control circuitry to guarantee that state of charge with current sensing. Since we
were simply interested in extending the range and providing electric braking, this feedback control logic
was unnecessary. Instead, we made sure that we didn’t overcharge the battery through control logic
that would not engage the electric brake if the battery was near 100% charge.
With the charge voltages set, we moved onto setting the charge rate. NiMH batteries can be
charged from 0 to 100% in 1.5 hours9. This would mean that we could charge our battery at 10 amps
provided we had temperature and voltage protection. The only concern when charging NiMH batteries
is the cell temperature. If the cell temperature becomes too hot, then the battery may start venting the
chemicals. This is hazardous and will lead to the destruction of the battery. Since we were expecting to
charge at a rate well below our boost converter current limit of 5 [A], the brake would only be engaged
for short periods of time, and our battery was vented to the air, we only needed simple on off control on
the charger for safe regenerative braking. If our battery had been in an enclosed box, we may have
needed to use thermistors to make sure that the pack temperature stayed below a safe to touch
temperature. Details of the charge circuitry will be covered in depth in future sections.
Page 12
Regeneration
Physics
It is necessary to understand the underlying physics that make regeneration possible before
attempting to design and implement a regenerative braking scheme to be included in the conversion kit
of the electric bicycle. Regeneration schemes for electric vehicles work by harnessing the rotational
energy present in the electric motor and converting this energy to electric energy to be stored in the
system’s battery. The basic physical principal which makes this conversion and storage of energy
possible is Faraday’s law12.
Faraday’s law states that a time-varying magnetic field through a coil of wire will induce an
electromotive force in the wire. This means that as the magnetic field through a coil changes, a voltage
will develop across it. In a permanent magnet AC (PMAC) motor (also called a Brushless DC motor), the
rotor is made of permanent magnets and the stator is constructed of 3 phase-windings along the inside
rim of the motor. As the rotor turns, the permanent magnets pass by the phase windings of the stator
and thereby induce a back-EMF in them12. This means that as the wheel of an electric bicycle rotates,
there is electric potential energy built up in the phase-windings that can hypothetically be harnessed.
This is the energy that the regeneration scheme will aim to capture.
When a regeneration system is implemented, another benefit is electric braking. When the wheel
rotates, a back-EMF is generated, but there is not necessarily any current flow in the stator windings.
When current does flow in the stator windings (as it would if current was flowing into and recharging a
battery) there is an electric force generated which acts to slow the rotation of the wheel. This electric
stopping force is a consequence of the magnetic field that will be developed in the stator windings.
In electric motors, whenever there is an angle between the rotor and stator magnetic fields, there is
a toque induced that acts to align these magnetic fields12. This is the physical principal that is utilized in
the driving of electric motors. However, it is the same principal used in the electric braking process. As
Page 13
soon as there is a completed circuit across the stator windings, the induced back-EMF in the windings
will cause a current to flow. A consequence of this current flow is the development of a stator magnetic
field by Ampere’s Law which states that electric currents produce magnetic fields. With the
development of the stator magnetic field there will now be two magnetic fields present in the motor
(the other from the permanent magnet rotor) and there will be a resulting torque acting to align these
two fields. Current flow in the stator during braking is in the opposite direction than during driving and
consequentially the induced torque will act to turn the wheel backwards therefore slowing the bicycle.
Motor Selection
In order for energy harvesting and electric braking to be possible, it is necessary that the correct
type of motor be selected. There are typically two types of PMAC hub motors: geared and direct drive. A
comparison of the two motor types is shown below in Figure 5.
Motor Type Weight Effort when motor disengaged Regeneration
Geared ~ 7 pounds None Not Possible
Direct Drive ~ 14 pounds Noticeable Possible Figure 5. Battery Characteristics Chart
13
In a geared electric motor there is a free-wheel inside. This means that the motor will only turn
when it is being electrically driven. This reduces the amount of effort required by the rider when the
motor is not engaged as they will not have to overcome the rotating friction of the motor. Geared
motors are also typically lighter than direct drive motors. However, because the geared motor does not
rotate unless being electrically driven, regeneration is not possible because there will be no back-EMF
induced in the stator windings.
The second type of hub motor, the direct drive motor, is typically heavier and requires more effort
by the rider when it is not engaged. However, the rotation of a direct drive motor is fixed with the
rotation of the wheel itself. For this reason, regeneration is possible and therefore this is the type of
motor that was selected for the project.
Page 14
Performance Expectations
The primary goal of regenerative braking systems for bicycles is to increase the amount of time that
the bike can be used. Our research revealed that regenerative braking systems can be expected to
increase the range of the electric bicycle anywhere from 5-20% (10% on average) 14. However, there are
differing opinions on whether regenerative braking actually increases the efficiency of an electric
bicycle. A paper by the electric bike vendor EcoSpeed claims that regenerative braking systems can
actually decrease the efficiency of the bicycle because of the necessary drag that is associated with
direct-drive motors15.
Regardless of the expected efficiency gains, there is another consequence of the regeneration
system which is the addition of an electric brake. This electric brake will help provide additional stopping
power when it is engaged, and it will also help to reduce brake wear on the friction brakes14. Because
the strength of the electric brake is dependent on the current in the motor – which is dependent on the
speed of the bike – the electric brake strength will decay as the speed of the bike decreases. The electric
brake can be expected to decrease the bike’s speed, but not expected to bring the bike to a complete
stop.
While our research revealed that the benefits of a regenerative brake our debatable, another
motivation for including this feature is to gain experience in the design and integration of a more
complex system.
Motor Control
In order to fully understand what was necessary to complete a proper motor controller a fair
amount of research was done into the basics of 3 phase BLDC motor control. Due to previous courses a
basis of understanding for BLDC motors had been reached. The question remained how to control it.
Thanks to the web many application notes were found that gave a good idea of how proper BLDC motor
control is done. Microchips AN85716 gives the basic idea for sensor controlled BLDC motors. Due to our
Page 15
motor having 3 hall sensors this application note fit perfectly. Commutation code for each state was
made from Figure 6.
Figure 6. Sensor versus drive timing.
With the help of this application note a basis for drive commutation was created and tested.
Another helpful application note that dealt with the same topics is AN191617. This appnote solidified
the theory behind commutation and proper switching along with supplying a very basic 3 phase H-
bridge.
After testing the basic H-bridge circuit there was trouble with turning on the MOSFETS. Again using
the web another helpful application note was found. AN786 from microchip gave a good idea as to why
the H-bridge was not properly commutating18. Due to the nature of the high side transistor on each half
H-bridge being referenced to the phase of the motor there would never be a proper Vgs (around 4V)
that would turn on the transistors. AN786 gave a good idea of how to work around this, specifically by
using integrated circuits made for this job.
Researching gate drivers was also a big part of the project. AN786 helped narrow down exactly
what was necessary for a gate driver application. The most helpful application note in determining how
exactly these devices work was found in AN97819. This application note came from the chip manufacture
Page 16
we chose and gave a detailed overview of what to expect from a gate driver and how to properly select
the chip for any application.
Power Systems
The electric bike combines many separate systems in order to make the motor spin. This system
needs user input, computational speed and output logic in order to function correctly. These different
systems require different voltages and currents. With these different requirements, the power system
becomes a non-trivial task. This power system must create voltage rails for each of the necessary
systems as well as provide enough current to those systems for them to run effectively. With this
requirement, there are two different ways to accomplish this goal.
Most motor controllers employ linear regulators to power their lower voltage systems. Linear
regulators not only drop voltage, but they provide clean and usable power in a simple integrated circuit.
These regulators are connected to the battery (or power source) and act as simple voltage divider to
create a voltage rail at any needed voltage. However, the major problem with linear regulators is that
they burn most of their power as heat. This heat dissipation causes large power losses in the system. For
example, stepping down from 48 [V] to 5 [V] as the motor controller from E-BikeKit does wastes almost
4 watts of power if the microcontroller is assumed to pull about 100 [mA] 20. That is an efficiency of 10
percent. With some extra complexity, a switching regulator becomes a high efficiency alternative to the
linear regulator. Well-tuned switching regulators can often be over 80 percent efficient in the worst case
scenario21. To maximize the efficiency in the controller and save as much power as possible for the
motor, switching regulators must be used to create the necessary drops in voltage.
Switching regulators are devices that use a MOSFET paired with a PWM signal to regulate voltage
either up or down from the input. These devices are then paired with capacitors, inductors and diodes in
order create these changes. Switching regulators come in three different varieties. The boost converter
boosts the output voltage above the input. The buck converter produces a voltage lower than the input.
Page 17
There is also the buck-boost converter that is a 50/50 mix of the buck and the boost. While the buck-
boost converter provides the most flexibility, this converter adds unnecessary complexity into the
circuit. Since our project required only voltages at or below the 48 [V] battery voltage, the simpler buck
converter is the best design choice to create all three rails. The buck converter raises the total efficiency
of the circuit while keeping the complexity and size of the system down.
In a buck converter, the PWM will switch the MOSFET on and off very quickly in order to produce a
square wave voltage at the output of the MOSFET. This square wave will have an average value that is
dependent on the duty cycle of the PWM signal. This average value at the MOSFET will become the
output voltage level. The square wave is then put through an inductor and capacitor in order to create a
constant DC voltage and current with as little ripple as possible.
With the device characterization out of the way, we then moved onto researching different devices.
Most semiconductor companies make integrated circuits which combine all of the external control and
timing. Some also integrate this into a package with a MOSFET. With an integrated MOSFET the only
necessary feedback control is designing a resistor divider to set the correct output voltage. Early in the
design process I was pointed to Texas Instruments. They provide a helpful tool that will design your
system for you and let you print out a bill of materials. This tool was called WebBench22. This tool served
as an excellent place to start. With this tool I was able to quickly pick some different integrated circuits
that would work and start design. We have added a list of helpful references that we have read or used
in this project. This list is located in the references23-36.
The initial design of the power system focused around TI’s WebBench for names and capabilities of
parts and then moved into other design tools to verify. This will be explored in more depth in the Power
Systems section.
Page 18
Motor Characterization
After receiving our direct-drive motor several tests were conducted in order to gain a better
understanding of its internal construction. The first of these tests was determining the relation between
the induced voltage in the motor’s phase windings and the speed of rotation.
The back-EMF magnitude is expected to increase linearly with the motor speed. This is a
consequence of Faraday’s Law which states that the magnitude of induced EMF in a coil is proportional
to the rate of change of the flux through the coil. The flux change in the motor windings is a result of the
relative motion of the stator windings to the permanent magnets in the rotor; the faster this relative
motion, the greater the rate of change in the flux12. In order to verify this relationship, the motor was
rotated at different speeds and the RMS back-EMF voltage and EMF frequency were measured. The
results of this experiment are shown below in Figure 7.
Figure 7. Decreasing the duty ratio of the bottom H-bridge MOSFETs results in less voltage boost at the output.
y = 0.2251x R² = 0.9944
0
5
10
15
20
25
30
35
40
45
50
0 50 100 150 200 250
Bac
k-EM
F [V
rms]
Frequency [Hz]
Page 19
The plot shows that the relationship between the back-EMF and the motor frequency is indeed
linear. It was observed that, for the motor in use, the back-EMF magnitude and frequency are related by
the equation:
In addition to the back-EMF test, an additional test was used to determine the internal inductance
of the motor. This was done by connecting one pair of the motor phase windings to an LCR meter and
using this to measure the complex impedance. It was quickly observed that the internal impedance of
the motor varied with the position of the rotor. After discovering this, a test was done to determine the
relationship between the rotor position and the internal impedance. Phase AB was connected to the LCR
meter and the impedance was measured using a frequency of 1.0 [kHz] over a range of 20 degrees of
rotation. The results of this plot are shown below in Figure 8.
Figure 8. The internal impedance of the motor phase windings varies sinusoidally with rotor position.
As is evidenced by the above plot, the internal impedance of the motor phase windings varies
sinusoidally with the position of the rotor. This indicates that our motor is a salient pole motor as
opposed to a non-salient pole motor12. In a non-salient pole motor, the impedance is constant with
rotor position. In salient pole motors, the impedance varies sinusoidally.
2
2.2
2.4
2.6
2.8
3
3.2
3.4
0 2 4 6 8 10 12 14 16 18 20Mag
nit
ud
e o
f In
tern
al Im
pe
dan
ce
[oh
ms]
Rotor Position [Degrees]
Page 20
An unintended positive consequence of this test was that it made it possible to determine the
number of poles inside the motor. Because the impedance varies with the position of the poles, the
number of poles can be determined by the period (in rotor position degrees) of the observed sinusoid.
The period of the sinusoid is slightly greater than 8 degrees. Because the wheel has 360 degrees of
rotation the number of poles can be estimated by:
However, the number of poles must be an even number (because poles come in north-south pairs)
and so, since the period of the sinusoid was actually slightly greater than 8 degrees, it can be
determined that the motor actually has 44 poles (22 pole-pairs).
With the number of poles determined it is now possible to estimate the mechanical speed of the wheel
from the electrical frequency of the back-EMF (determined from the hall-sensor feedback) which is
known for PMAC motors to be12:
While the inductance tests did reveal the number of poles in the motor and made it possible to
determine the mechanical speed of the motor, it was not possible to accurately determine the internal
inductance of the motor’s stator windings.
Page 21
System Overview
Figure 9 shows a system level block for the Hybricycle. It has been broken down into its major
components which are the user interface, the power systems, the motor controller, and the motor.
Figure 9. System Overview Block Diagram
Approach
Controls
While the group had done some preliminary research on electric bike throttles and brake levers, the
electric bike conversion kit from E-BikeKit included well designed and well thought out controls that
took the guess work out of this section. As stated above, we had researched many different
manufactures of electric bikes and electric bike components. While no company matched the simplicity
of the E-Bike kit throttle and controls, other companies and designs were researched throughout the
course of the project. The first design called for a cable actuated throttle much like the one found on a
dirt bike. We would then use a standard motorcycle throttle cable connected to a spring loaded variable
resistor. While the throttle and cable are very easy parts to find, the group had trouble finding a suitable
standalone spring loaded resistor.
The next design called for using an off the shelf electric bike throttle. These were readily available
and cost about $40. We were considering a Hall Effect type throttle and a resistor type throttle. Both
throttles required three wires and were about the same size. The resistor type throttle used a variable
resistor to change the output voltage between Vcc and ground. The Hall Effect type throttle uses
Page 22
magnetic fields to establish the same effect. The only benefit to the Hall Effect type is that they were
more common in electric bike applications and were readily available in a size that would fit on the
bicycle handle bars. We were about to buy a generic Hall Effect type throttle when we found E-BikeKit.
The kit from E-BikeKit came with a hub motor, wheel, motor controller two Hall sensor type
throttles, and two brakes with integrated electrical switches. Given the ease with which we could order
everything, we chose the kit from E-BikeKit. The included controls were easy to use and provided the
basis for our user input system. Figure 10 shows the twist throttle we used in our final design.
Figure 10. Throttle used to input desired pedal assistance
37.
These throttles have integrated hall sensors and a magnet placed on the moveable part of the
throttle. When 3.3 [V] and ground were attached to the throttle, the third cable acted as a variable
voltage output. As the throttle is twisted, the output voltage goes up. These throttles also had an
unforeseen benefit. They came fitted with female 3.5 mm headphone connection. We were then able to
buy a 3.5 mm male connector so that there was no reason to cut any wires. This simple connector made
the design and routing of wires on the bike much easier and cleaner. It also allowed for sections to be
removed and replaced quickly. This was very helpful as one of the throttles stopped working very late in
the project lifecycle.
Page 23
In the kit we also received brake levers with integrated switches. These brake levers close the switch
when pressed and open it when fully out. These levers will allow us to physically control when the
regeneration comes on. During preliminary research, we also researched using accelerometers or
leaving the regeneration on for all no throttle situations. However, both of these methods had severe
flaws. An always on approach allows for no coasting. If a fast moving rider were unaware of this feature,
the electric braking force induced by the motor could cause accidents. The accelerometer method would
use accelerometers to intelligently turn on the regeneration and throttle based on the grade and speed
of the rider. However, we eliminated this feature when many team members believed that the rider
should always have control of his vehicle to aid in surviving unexpected situations. After we eliminated
the choice of autonomous control, we then asked if we wanted regeneration on a handle bar mounted
switch or button. The E-BikeKit presented a novel solution to this problem by integrating the switch into
the brake lever. This wouldn’t add any unnecessary clutter to the handle bar and the switch couldn’t
accidently be pressed without the rider wanting to slow down.
Our final control set up is shown in Figure 11. Both controls for the electronics are located on the
right hand side of the handle bar. The throttle is enclosed by the green box and the electric brake is
integrated into the lever shown in the red box.
Figure 11. Control layout for the Hybricycle. The throttle for pedal assistance is indicated in green, the electric brake in red.
We chose this because the most common place for throttles on motorcycles is on the right hand so
we chose to keep the throttle there for ease of use. Also the electric brake is located on the right hand
Page 24
side as well because that lever actuates the rear brake of the bike. Since the electric brake would be
applying force to the rear wheel, we chose to use the right hand brake to make sure the rider had an
easy transition to the product. We also had the ability to put the electric brake on both brake levers.
However, we agreed that it was not a good idea for the rider to engage rear braking while using the
front brake of the bike. While the braking force of the electric brake is small in most situations, we
thought this may induce an unexpected response to rider input.
Structure
The bike used is a 2004 Trek 7300FX. This bike was designed as an around town cruiser bike and will
provide the perfect basis for this electric motor conversion. It has 21 speeds and runs on 700c wheels.
These wheels are thinner and taller than normal mountain bike tires and roll more efficiently on
concrete than mountain bike wheels. This bike also has no suspension. Having a solid frame also makes
the conversion easier and more reliable. Mounting a hub motor and battery to a frame that has front or
full suspension would increase the likelihood of failures in the suspension components due to the added
sprung and unsprung weight. With no suspension, all the weight added is transferred directly to the
ground through the rigid wheel and does not act upon other parts of the bike. While the wheels may
come out of true (become slightly bent) more easily with the extra weight of the hub motor we avoid
the extra costs of having to replace bushings and bearings more often.
This project used a hub motor because it is the simplest to implement to a preexisting bicycle. The
hub motor simply replaces the standard rear hub of the bicycle. While our kit included a new wheel, we
could have reused the stock wheel and just had new spokes made to mate the motor to the wheel. The
rear wheel of the stock bike and that of the hub motor are shown in the Figure 12.
Page 25
Figure 12. Stock wheel and Hub Motor
In addition to the motor mounting, we also had to find a place for the electronics and battery. While
we had planned to mount the battery and electronics inside the frame rails to center the weight, we
were unable to fit our circuit designs and the battery in the frame together. Therefore, we moved the
battery to a rack on the back of the bike. This rack with the battery attached is shown in Figure 13.
Figure 13. Rear wheel mount for the Hybricycle battery.
All the electronics were mounted inside the frame triangle with a custom made wood box. Figure 14
shows the SolidWorks model of the box and the box mounted in the frame. This frame is held together
with the water bottle mounting screws. This makes the box sturdy and easy to remove. The holes for
Page 26
this mounting are located on the back of the box (not pictured) and the bottom of the box as seen in
Figure 14.
Figure 14. Custom-made housing for the Hybricycle electronics.
The placement of the electronics here allowed for all connection wires to be kept at a minimum
distance. This reduced losses and increased the ascetic qualities of the system.
The last part of the structure was the LCD box. We wanted the LCD to be easily readable by the rider
and decided that it should be placed in the middle of the handle bars. The box is held onto the bike with
two zip-ties that attach inside the box for a flush appearance. The box and its SolidWorks model are
shown in Figure 15.
Figure 15. Custom-made housing for the Hybricycle user display.
Page 27
Power Systems
The most important part of the power system is the battery. Due to its importance, this is where the
power system design started. The explanation of our battery choice can be found in the battery section
above. After we had chosen the battery, the team built and tested a close to ideal buck converter using
a simulation program called OrCAD38. This preliminary design came from our power electronics class
where we learned about the electrical side of buck converters and how to design them well. In this
simulation, the buck converter was to run at 60 percent duty cycle (Figure 16). This meant that there
should be 7.2 [V] on the output. The output waveform in Figure 17 shows that while the output voltage
does drop, it doesn’t quite get to 7.2 [V]. This is due to the fact that there are power losses across the
MOSFET that are not taken into account. The IRF640 used in the simulation will lose power every time it
switches and when it is conducting39. This preliminary design showed that the buck converter would
work, and it also gave a starting point for the design.
Figure 16. Ideal Buck Converter Model
Page 28
Figure 17. Output Voltage of Ideal Buck Converter
During our research we decided that we wanted to use buck converters to convert between
voltages. Our next step required us making a power budget. However, to begin the power budget, we
had to establish the voltage rails. The first rail was the 48 [V] rail coming directly from the battery. This
rail would go into the controller and directly to the motor. The next rail was the 12 [V] rail that would be
used to drive the gates of the MOSFETS. The final two rails came to be known as the low voltage rails.
The microcontroller and the user interface runs at 3.3 [V] while the LCD screen runs at 5 [V]. The 12 [V]
rail would need to be able to draw 200 [mA] of current and the power necessary to drive the low voltage
rails. The 5 [V] rail would need to be able to provide 250 [mA] and the current needed in the 3.3 [V] rail.
The 3.3 [V] rail would need to provide around 100 [mA] of current. With the four rails chosen and their
requirements calculated, the next step was to design the switching regulators.
The first design consideration would be in the duty cycle. The low voltage buck converters used to drop
the voltage to 5 [V] do not work with input voltages above 40 [V]. This led the team to design a multi-
level power system. This system can be seen in Figure 18.
Page 29
Figure 18. Power System Diagram
The first level consists of the 48 [V] to 12 [V] conversion. The second level then converts the 12 [V]
rail to 5 [V]. The last level uses a linear regulator to give a 3.3 [V] rail. While we had originally planned to
use 3 buck converters, we found that the efficiency gained of dropping from 5 [V] to 3.3 [V] with a buck
converter was not worth the extra components necessary. We calculated that the power wasted by the
linear regulator would be
( ) RJRPS1
This gave us an efficiency of 74 percent. Using the chosen buck converter, we only expected an
efficiency of 85 percent40. Knowing this, we chose to go for simplicity and took the small efficiency loss.
The next step in designing the switching regulators is to size the output capacitor and inductor. The
sizes of these components determine the current ripple, voltage ripple, turn-on time, rise time, and
noise propagation. The team turned to multiple online tools provided by TI in order to size and design
the first prototypes. All the design tools mentioned in this section are linked in the appendix. The first
tool used was the Power Stage Designer from Texas Instruments. This free and downloadable program
provided an ideal buck converter and allowed for the test sizing of the output capacitor and the output
inductor. With this tool, we could hone in on the correct value of the component without working
Page 30
through long equations. These equations can be seen in application note entitled “Basic Calculation of a
Buck Converter’s Power Stage.” It also quickly related switching frequency in the MOSFET with inductor
sizing in a visual way that would not have been obvious otherwise. Texas Instruments also provided
some good application notes along with their online software. Application notes AN1253, SLTA055 and
SNVA575 were all used in the early design process to find the right value for the inductor and output
capacitor. Later in the design process, we also used a Microsoft Excel spread sheet entitled “Component
Calculator for BUCK Converters.” This excel sheet had all of the necessary equations to make sure the
voltage and current ripples were below tolerance in the design.
In a buck converter, the inductor should be large enough that it will sustain the current during the
off portion of the duty cycle. As the inductor gets larger, the current ripple (the change in current
between the off and on times) decreases. However, with a larger inductor, the startup time of the
system also goes up. The inductor value should be large enough that it sustains current but small
enough that it reaches steady state quickly. In our designs, we set our current ripple deviation to be 20
percent of the output. While the allowable ripple is high, it was necessary to use physically smaller
inductors. The capacitor sizing is very similar. The capacitor can be compared to the voltage analog of
the inductor. The capacitor should be large enough so that it can hold enough charge to supply power
throughout the off period. However, the size of the capacitor also determines the output voltage swing
in steady state. The allowable voltage swing is completely dependent on the device being powered. For
the other components in the system to work reliably, the maximum deviation had to be less than 10
percent. When our design was implemented, voltage deviations were expected to be under 5 percent.
This constraint along with the feedback loop inside the integrated switching circuit will determine the
minimum size for the capacitor. For this system the deviations had to be small at steady state so the
team decided to pay the time penalty and size all the components up well above the minimum.
Page 31
After agreeing on the preliminary design constraints (voltage ripple, current ripple, and load current)
the team moved into a full design. Texas Instruments also provides an online tool called WEBENCH,
where the user inputs simple characteristics like input voltage, output voltage, and output current, and
the system designs the buck converter based on IC’s in stock. Most semiconductor companies are now
integrating the timing, MOSFET and feedback into one small IC. The single IC worked out great for our
application because it will minimize space used on the final PCB. TI’s WEBENCH also simulated how well
the system was supposed to run and printed out a schematic and bill of materials. After reading through
the outputs of this online designer, the team sampled 6 different switching regulators. Three sets of
regulators were selected for the low voltage rail and the other three sets were selected for the high
voltage rail. All of the possible candidates are shown in the two figures below. At this point, the team
moved onto the design of the other discrete components.
Figure 19. Buck Converter Selection.
Part Number Manufacturer Discription Package Pin Count
LM2592HV-ADJ Texas Instruments High Voltage Input Buck TO-220 5
LM2593HV-ADJ Texas Instruments High Voltage Input Buck TO-220 7
LM2672-ADJ Texas Instruments Low Current Buck PDIP 8
LM2673T-3.3 Texas Instruments Buck Converter Fixed Output TO-220 7
LM2673T-5.0 Texas Instruments Buck Converter Fixed Output TO-220 7
LM2674-ADJ Texas Instruments Low Current Buck PDIP 8
TPS54360 Texas Instruments High Voltage Input And Current Controlled Buck SOIC 8
LM2576HV-5.0 Texas Instruments High Voltage High Current Buck Fixed Output TO-220 5
LM2576HV-12 Texas Instruments High Voltage High Current Buck Fixed Output TO-220 5
LM2576HV-ADJ Texas Instruments High Voltage High Current Buck TO-220 5
LT1074HVIT#PBF Linear Technology High Voltage High Current Buck TO-220 5
LT1074HVCT7#06PBF Linear Technology High Voltage High Current Buck TO-220 7
LT1074HVIT#06PBF Linear Technology High Voltage High Current Buck TO-220 5
LT1074HVCT7#PBF Linear Technology High Voltage High Current Buck TO-220 7
LT1074HVCT#PBF Linear Technology High Voltage High Current Buck TO-220 5
Legend
Current Design Previous Designs
Page 32
Figure 20. Buck Converter Selection.
We had originally ordered some integrated buck converter IC’s from Linear Technology for backup.
However, all the TI parts worked very well and they were never needed. While it became clear that most
of these parts would have worked, we chose the most robust parts in order to guarantee extended
reliability.
Even with the main inductor and capacitor planned out, there were still many other components to
design. All the integrated circuits have a feedback loop that allows them to shift the output voltages in
response to loads, temperature and other external considerations. However, for the switching
regulators used, all the feedback was internal so the only necessary item was to connect a wire form the
output to the feedback pin. Another part that needed sizing was the input capacitor. This capacitor had
to be large and discharge very quickly. Most of the reference documents will place the input capacitor
size between 100 [µF] and 1000 [µF] depending on the current requirements in the system. The ESR and
the current ripple also need to be set that the capacitor can supply the necessary amount of power in
the switching period. The reason for this extra capacitor is the battery or power supply is unable to
provide the change in current at the switching frequencies of the PWM. The capacitor will allow the
buck converter circuit to pull all the current that it needs by making the buck converter input look like an
Part Number Manufacturer Ouput Voltage (Min) (V) Output Voltage (Max) (V)Output Current (Max) (A)
LM2592HV-ADJ Texas Instruments 1.2 57 2
LM2593HV-ADJ Texas Instruments 4.75 60 2
LM2672-ADJ Texas Instruments 1.21 37 1
LM2673T-3.3 Texas Instruments 3.3 3.3 3
LM2673T-5.0 Texas Instruments 5 5 3
LM2674-ADJ Texas Instruments 1.21 37 0.5
TPS54360 Texas Instruments 4.5 60 3.5
LM2576HV-5.0 Texas Instruments 5 5 3
LM2576HV-12 Texas Instruments 12 12 3
LM2576HV-ADJ Texas Instruments 1.23 37 3
LT1074HVIT#PBF Linear Technology 2.5 50 5
LT1074HVCT7#06PBF Linear Technology 2.5 50 5
LT1074HVIT#06PBF Linear Technology 2.5 50 5
LT1074HVCT7#PBF Linear Technology 2.5 50 5
LT1074HVCT#PBF Linear Technology 2.5 50 5
Legend
Current Design Previous Designs
Page 33
ideal voltage source. All the other pins required set values for turn on time or bootstrapping that were
given in the data sheet.
One concession made by the group in the power system was overall efficiency. Some of the
switching regulator integrated circuits were above 90 percent efficient. However, the packaging style of
these highly efficient integrated circuits would have made it very hard to prototype and test due to the
lack of on hand printed circuit board creation tools. Conceding 5 percent on the efficiency of the
switching regulators allowed the team to choose bigger packages that were easy to solder to through-
hole prototype boards. Even with this design choice, 5 percent is a small loss compared to the 50
percent loss in a linear regulator. The first package type used is TO-220. This package is a vertical mount
square with all leads coming out directly below the device. The second package used by the regulators is
PDIP. This package is a small rectangular package that has the leads coming out the sides and then right
angles down. Both of these packages are easy to solder and test with. This compromise in efficiency
allowed quick prototyping and building. The ability to quickly design was very important given that the
project must be completed in 20 weeks. Moreover the package selection should relate to less than 1 [W]
of loss. Given that the whole system will be using over 1000 [W], this compromise will not affect the
system negatively.
The high voltage rail went through two different revisions. The first revision involved the Texas
Instruments LM2593HV. This is a simple switcher package in the TO-220 package capable of delivering 2
[A] of current to a load. After wiring up this regulator and testing it, the team found that it was incapable
of supplying the full 2 [A] of current with such a large drop in voltage. During testing, we found this limit
to be closer to 1 [A]. With this issue, the team moved to the LM2596HV that was capable of supplying 3
[A] of current at maximum. After construction and testing, the second buck converter was more than
capable of supplying all the current necessary.
Page 34
The low voltage rail worked on the first revision. The low voltage rail included using a LM2673 from
Texas Instruments. This integrated circuit provided 5 [V] output while providing a maximum of 3 [A].
While the max current is way above anything that these rails will need, it allowed the team to have
some flexibility with the UI design and microcontroller implementation. While both of these systems
would go through many revisions throughout the first half of the design, the LM2673 circuitry never
faltered under the increased demands.
The 3.3 [V] rail started as a buck converter from 12 [V] using the same integrated circuit as above.
However, when we decided to change the buck to a linear regulator, we used a LM3940. This regulator
was set up to drop voltages from 5 to 3.3 volts and only required 2 capacitors. This was one of the
simplest pieces in the entire system and its reliability is perfect.
After all these systems were put together, the team went into the testing and implementation
phase. An overall block diagram can be seen below in the System Overview Section. The test circuit
included three dummy loads that would test the system at full power. The dummy load schematic can
be seen in Figure 21 below. These loads were meant to simulate a full load. With some blocking
capacitors (not shown), the system passed this early test and the team was able to produce the output
voltages seen in Figures 22.
Figure 21. Test Load
Page 35
Figure 22. 12 Volt Output (Left), 3.3 Volt (Channel 2 Right), and 5 Volt (Channel 1 Left) Output
While the output voltages do reach their target voltages, there was some noise present on the line.
After zooming in, it was obvious that this noise was due to the inductor spike during switching. This
spike is caused when the MOSFET switches on or off and the inductor tries to change rapidly. This very
high frequency noise is most likely due to grounding issues on the prototyping board. While all the
grounds met at a single point on this board, the self-inductance of those lines will store some energy will
discharge on the switching edge. Since the inductor is governed by the equation,
, it follows that
there should be a spike in voltage during any switching. There was a 328 [mV] spike on the 5 [V] rail, 136
[mV] on the 3.3 [V] rail and 512 [mV] on the 12 [V] rail. These spikes are shown in Figure 23 below.
Figure 23. AC Coupled Noise: 12 [V] (Left) 3.3 [V] (Channel 2 Right) and 5 [V] (Channel 1 Right)
While these spikes seem large, all of them are less than 10 percent of the output voltage. When
designing buck converter circuits, the output capacitance and inductance are set up based on a tolerable
deviation in output voltage as explained above. These ripples (although they were short duration spikes)
Page 36
were well under the design constraints. After taking up with the power electronics professor and
showing the waveforms to him, he said that these spikes should not do harm to any one of the type of
systems on the bike. With this reassurance, the team then tested the three rails on the systems that
were currently implemented and all three systems met their specifications.
When the team changed the 3.3 [V] rail to a linear regulator, the 3.3 [V] rail inherited some of the noise
from the 5 [V] Rail. This is because the linear regulator is a simple voltage divider type circuit. Since
there are no active filtering elements the noise will propagate through the switch at a decreased
magnitude.
With the system designed we then moved onto testing before the final product went onto a printed
circuit board. While testing, multiple issues presented roadblocks. The first roadblock occurred with the
current limit on the LM2593HV (explained above). It was not immediately clear that the problem was
the current limiting. While, the input waveform during tests was flat under the dummy load, it was just
at a voltage lower than expected. After testing a less strenuous dummy load and making sure that the
connections were good, it became obvious that the current limit had been reached. The second problem
in the power system was due to “cheap” capacitors. Some of the electrolytic capacitors the team had
bought were not able to sustain enough ripple current to keep the output ripple constant. This problem
too, was not immediately clear when reading the application notes and data sheets on hand. UCSC’s
power electronics class had never used input capacitors because we called all sources ideal. However,
after reading application notes that were previously thought to be unnecessary, the team was able to
isolate the capacitor. With higher ripple current capacitors installed, the difference was that of night and
day. The system worked better and the outputs were cleaner. While there have been some problems in
the power system, all of them have been easily solvable.
After some successful tests with the motor control and regeneration, the team put the power
system on a printed circuit board. When we got the circuit board running, we did have some immediate
Page 37
issues with high frequency noise on the 5 [V] supply. This was caused due to the self-inductance of the
traces. The trace lengths were all a little too long. This length caused the circuit to resonate on the
ground loop. While we were unable to send out for another board due to finical constraints, we changed
the inductor size smaller to move the filter frequency and added some extra solder on the traces. These
two fixes brought our noise back to within the 10 percent margin. From here, the power system was
fully designed and ready to be run.
Microcontroller
A motor controller has many important components that need to be chosen carefully in order for it
to function properly. The microcontroller - the central processing unit that will handle all of the signals
and properly drive the outputs - is a component that was given much thought before being purchased
for this very reason.
In order to select a microcontroller for our project, a few criteria had to be met. The microcontroller
would need a minimum of 6 PWM outputs, 2 ADCs and a relatively fast CPU speed. Price was also a big
concern as the project is self-funded. Research was done on a few different types of microcontrollers:
the dsPIC33 series, PSoC5 and the TI Stellaris motor controller. The PSoC5 was looked at since it was a
familiar microcontroller used in our Microcontroller course, but ultimately did not meet the minimum
criteria for the project (only 4 PWM outputs). The main choice was between TIs and Microchips
microcontrollers. The decision hinged on the programmers experience with the PIC and the ease of
testing that the dsPIC33 provided. Since its package was a SPDIP it could easily be prototyped on
breadboards, instead of having to buy an expensive development board for the socket alone. Another
reason the dsPIC33 was chosen was its easy to use and relatively cheap programmer. The Microstick II
was cheaper compared to the development boards for either the PSoC 5 or the TI Stellaris. The
Microstick II also interfaced seamlessly through USB to any computer and came with free coding
software and compiler. The comparison between microcontroller can be seen in Figure 24.
Page 38
Figure 24. Microcontroller Comparison Chart
The specific chip selected was the dsPIC33FJ128MC802. This microcontroller comes with 3
independent PWM Generators that can operate either independently or in complementary mode.
Moreover, this microcontroller comes with 4 independent 10/12-bit ADC channels and independent
trigger sources for each ADC channel. These microcontrollers are built solely for motor controller
applications. This was important for the project seeing as it would have good documentation for motor
control applications. The dsPIC33 also comes with 3 different types of communication architecture, I2C,
SPI, and UART. These will enable the user to properly communicate with the user LCD to display battery
usage and speed of the bike. The ADC on the chip allows for user input via the throttle. Finally the 6
PWM outputs allow the drive circuitry to properly drive the BLDC motor, as there are 6 FETs that need
to be independently controlled through 6 independent PWMs. The dsPIC33 is the perfect choice for use
with the system, and stood up well for the entire project as only 9% of the memory was used. The main
source for reference during this entire project when needing specific details was the DSPIC33F/J
datasheet41.
With an appropriate microcontroller selected, the high level design was the first step towards
designing proper functioning code. Driving a three-phase motor requires the thorough understanding of
commutation. The typical three-phase BLDC motor drive commutation scheme is shown in Figure 25.
Microcontroller Price Package PWM Outputs ADC RAM (kB) Flash Memory (kB) CPU Type CPU Speed (MHz) Samples
dsPIC33 $4.00 SPDIP 28 3 2, 10-bit 32 128 16-bit Harvard 70 Yes
PSoC 5 $11.00 QFN 68 4 2, 20-bit, 12-bit 32 128 32-bit ARM 67 No
TI Stellaris $8.00 LQFP 144 8 2, 12-bit 32 256 32-bit ARM 80 No
Page 39
Figure 25. Commutation Drive Scheme
42
This scheme consists of a power stage with a three-phase full-bridge, which is controlled via three-
phase PWM signals based on three Hall-effect sensors for the position feedback. As shown in Figure R2,
the PWM signals decide which phase in the motor is being powered. There is a total of three PWM pairs,
PWM 1 – PWM 3, where each pair has a High and Low PWM output. PWM 1H, 2H, and 3H are applied to
the corresponding high-to-Phase X (where X is A,B,C) gates Q1, Q2, and Q3 respectively. The same is
done to the low-to-Phase X gates Q4, Q5, Q6. The PWM’s must be sent from the microcontroller in an
ABC sequence in order for the motor to spin in the proper direction. The speed of the motor depends on
the duty cycle of the PWM signals, and hence, how much current is allowed to flow through the three
half H-Bridge’s. In order to vary the PWM signals duty cycle, we need to be able to handle some variable
input voltage and translate it to binary data. This necessitates the need for an ADC channel on the
microcontroller.
This completes the high level overview of driving the circuit that drives the motor. As we are also
implementing regeneration into our design, it is essential to understand regeneration and how the
microcontroller will play a part in the design. Although most of the regenerative breaking control will be
done in circuitry, the microcontroller will play a role in the regeneration circuit. As is true for most
batteries, overcharging is something that must be prevented with NiMH batteries. Although not as
Page 40
dangerous as overcharging a Lithium Ion battery because of the violent explosions in Lithium Ion
batteries, NiMH batteries still need charge protection. When overcharged, NiMH batteries will suffer
several dangers. First, overcharging will deplete the overall capacity of the battery as the excess energy
feeding into the battery will reverse the voltage polarity of the electrodes inside and cause a decrease in
the battery’s voltage. Second, although this was more common with older NiMH batteries, there is a
slight possibility of hydrogen build up inside the individual cells until rupture occurs. Lastly, overcharging
will cause excessive heat, which could potentially damage not only the battery, but also damage the
electronics surrounding the charging unit, in our case the regenerative breaking circuit43. Once the
battery has been completely charged the microcontroller needs to send the correct signal to the switch
that will stop the flow of current from the motor to the battery.
Providing the user with details about the battery as well as the bicycle speed is a very convenient
feature that many cyclists using electric bicycles would desire. For this reason, an LCD display module
will be incorporated onto the handlebars of the bicycle. This LCD will display the user with a battery
percentage and their current speed as shown in Figure 26.
Figure 26. LCD Display
These features are provided using feedback from both the motor and the battery. The speed of the
cyclist is calculated using the Hall sensors, as they dictate where the wheel is at all times. Using simple
circle arithmetic, I calculated the speed of the cyclist with the following formula:
Speed (MPH) = ( )
( )
( )
( )
( )
Page 41
To read the battery level, a simple voltage divider and buffer is used to drop the voltage to a range
usable by the microcontroller. Both of these features will require an independent ADC channel, which
will be sampling continuously for new data.
Figure 27 shows the high-level block diagram of how the system is connected and controlled by the
microcontroller.
Figure 27. High level System Block Diagram
The figure above demonstrates the multiple peripherals that the microcontroller interacts with. The
flow of the diagram goes as follows:
The 3-phase motor outputs its current to the microcontroller via Hall sensors and
microcontroller drives H-Bridge accordingly.
Battery voltage is read by the microcontroller in order to determine charge left on
battery.
Microcontroller outputs current charge & the speed calculated to the LCD.
As discussed above, there will be several input and outputs pins that will be used on the
microcontroller for this project. A total of five inputs and seven outputs will be used in implementing the
Hybricycle design. These I/O pins are discussed more in depth below.
Page 42
The pic33F offers several types of analog inputs. Since the hall sensors will only ever output either a
logical 0 or logical 1 (0 -3.3 [V]), there is no need to use an ADC channel for Hall sensor feedback
readings since these channels are much more useful for variable voltages. Therefore, a level sensing
input seemed appropriate. Also, level sensing inputs are remappable peripherals. This means that any
input pin that has remappable capabilities can be programmed to be a level-sensing input by simply
setting a bit in the TRISx and LATx registers. This was very useful since the microcontroller only has 4
ADC channel inputs, none of which have remappable capabilities.
When the input voltage is less than 0.66 [V] the microcontroller reads in the value of the pin as a digital
0 and when the voltage on the pin is greater than 2.31 [V], the microcontroller reads in the value as a
digital 1. It is very important that the sampling of the pin voltage is done correctly since there could be
unintended behavior if the voltage on the pin is sampled on the transition from 0 to 1 (0.66 – 2.31 [V]).
Figure 28 shows how the level-sensing works graphically.
1. 0 [V]
2. 0.66 [V]
3. 2.31 [V]
4. 3.3 [V]
Figure 28. Level Sensing Example
44
Two of the inputs that we are currently using output variable voltages. This implies the need for an
ADC input since a level-sensing input would not give enough details about the peripheral. In order for
the ADC to work properly, both voltage inputs need to be within the acceptable ADC voltage range of 0-
Page 43
3.3 [V]. The variable throttle output voltage did not need any external circuitry to be in range since its
voltage range is from 0.85 – 3.25 [V]. However, the battery output voltage varies from 56 [V] at
maximum charge and 42 [V] at minimum charge. This requires an external voltage divider circuit that
will drop the voltage to the appropriate range.
The ADC module can be configured to function as a 10-bit, 4-channel ADC or as a 12-bit, single
channel ADC. Both the variable throttle input and the charge level voltage input are in the voltage range
required in order to use the 10-bit resolution of the ADC. Setting the module to automatic 10-bit
channel scan mode, the ADC module continuously scans the appropriate channel for new data and
stores the 10-bit value into a pre-allocated buffer for the user to use accordingly. In our specific design,
all conversion results are stored in the user-specified Direct Memory Access (DMA) buffer area in the
same order in which the conversions are performed by the ADC module. Although the usage of the DMA
controller is not required in order for the ADC to work, it is an elegant solution that allows the system to
continue with other important processes while the DMA controller takes care of the tedious data
transfer.
Seven output pins are currently being used on our microcontroller. There are a total of six PWM
signals that come from six different output pins. PWM module 1 is used to generate multiple
synchronized pulse-width modulated outputs all of which have multiple operating and output modes. All
of these different features need to be considered in the design of the motor driving application.
There are two distinct operating modes for the PWMs: Complementary Output mode and
Independent Output mode. Complementary output mode is used to drive inverter loads similar to our 3-
phase BLDC motor. In Complementary Output mode, a pair of PWM outputs cannot be active
simultaneously, thus, its “Complementary” feature. Independent PWM Output mode differs in that each
PWM signal in its signal pair is independent thus a pair of PWM outputs can be active simultaneously. As
Page 44
we will be manually overriding the output of three of the PWM signals either of these modes will work
in this design.
As well as multiple operating modes, our PWM module also provides multiple output modes: Single
event mode, Edge-aligned mode, Center-aligned mode and Center-aligned mode with double updates.
All of these different modes differ where the PWM begins in relation to the period register. For our
design we have chosen Edge-aligned mode but center-aligned would have worked as well. Below,
Figures 29, 30 and 31 shows the different output modes.
Figure 29. Single Event PWM
44
Page 45
Figure 30. Edge-aligned PWM
44
Figure 31. Center-aligned PWM
44
The seventh output pin was for communication to the LCD module. This microcontroller offers
several different communication interfaces: Parallel Master Port, UART, SPI and I2C. Choosing the
interface was really dependent on the LCD because the LCD Module that was available only supported
I2C and UART. When we received the LCD module it was configured by default to use a UART interface
via RS232. This made the interface choice very simple.
The UART communication module, like the level sensing inputs, is a remappable output that can be
mapped to any output pin that has remappable capabilities. This UART module is a full-duplex,
Page 46
asynchronous channel that communicates with a variety of peripheral devices. It also supports parity bit
error checking, one or two stop bits, and transmit interrupts. Although this module does support both
transmit and receive channels, we will only be sending data to the LCD module therefore not requiring
to use the receive channel. Below, shown in Figure 32, is a block level diagram of the UART transmitter.
Figure 32. UART Transmitter
44
As shown in the above diagram, the UART transmits 8 bits at a time asynchronously. Once the data
has been loaded into the U1TXREG register the data is then transferred to the transmit shift register
automatically on the next clock cycle. From there the data is either modified by the parity bit set (if any)
or sent directly to the U1TX output pin which the user has mapped in the application code.
Understanding commutation and how it is supposed to work is essential to being able to drive the H-
Bridge circuit that in turn drives the motor. Below in Figure R10 we have the 3-phase BLDC motor that
we are using for our project.
Page 47
Citation:
Figure 33. 3-Phase BLDC Motor45
One can see the logic needed in order to drive the motor just by looking at the above figure. While
using ideas from basic physics and electromagnetics, the designer will power on a different coil
depending on the current position of the rotor. For example, if the current position of the magnet is
101, in order to move the motor to the next coil we would need supply coil 100 with current to torque
the magnet in the clockwise direction.
With the basic functionality of the motor understood, the next step is to create a state machine that
is able to translate this into actual software code. Figure 34 shows the state machine that has been
designed for this project.
Page 48
Figure 34. Commutation State Machine
It is clear that Figure R11 supports the clockwise rotation shown in Figure R10. However one might
ask where the different states (000, 001,...111) come from. The motor must give some feedback to the
microcontroller as to how the magnet is currently positioned. This feedback comes from the motor in
the form of Hall sensor outputs. Figure 35 shows Hall sensor outputs that feed into the microcontroller.
Figure 35. Hall Sensor Outputs
46
Page 49
As can be seen the Hall sensors that come from the motor are square pulses, where high is 3.3 [V]
and low is 0 [V]. A high state for a Hall sensor is feedback from the motor itself. In this motor, the rotor
is made up of multiple permanent magnets which constitute magnetic pole pairs. If Hall A is high this
means that one of the magnetic poles of the rotor has passed by the Hall sensor. Each sensor is placed
120 degrees apart so that there will be an accurate depiction of the position of the rotor as it spins. The
Hall sensors also correspond to a respective phase, that is, Hall A corresponds to Phase A, Hall B
corresponds to Phase B, and so on.
Drive Circuitry
In order to drive a BLDC Motor there must be power delivered to each of the three phases at certain
increments of time all depending on the position of the rotor. A BLDC motor can also be considered a
permanent magnet AC (PMAC) motor, as the power delivered to the motor constitutes an AC signal
from increments of DC voltage and current. While the back-EMF of the three phases of the BLDC motor
is indeed sinusoidal, this section of the report does not deal with its interaction with the system as a
whole. Driving the three phases of a BLDC motor takes communication and exact timing from multiple
sources to work properly. These sources include sensor input from the motor, proper commutation of
PWM signals, level shifting of PWM signals, and throttle input. The block diagram for the drive circuitry
is shown in Figure 36.
Figure 36. Block diagram of motor drive circuitry.
Page 50
Before going more in depth about the commutation of the drive signals it is first important to
understand how the power is being delivered to the motor. Most motor drivers are created using an H-
Bridge circuit, 4 transistors situated in an H where the upper side is connected to the primary voltage
source and the lower side is connected to ground with the middle of the "H" being connected by the
motor. Figure 37 shows this configuration with switches.
Figure 37. Simplified full H-Bridge with ideal switches
47.
Figure 37 gives an extremely simplified version of a full H-Bridge using ideal switches. Ideal switches
are used here instead of transistors, which will be used for the Hybricycle. Depending on the orientation
of the switches, the user is able to drive the motor either forwards or backwards. For a BLDC motor, the
H-Bridge circuit follows the same relative design but uses three half H-Bridges in order to drive all three
phases of the motor. This design is shown in Figure 38.
Figure 38. 3-Phase H-bridge circuit
48.
Page 51
As seen in Figure 38 the three phases of the motor (x, y and z) are driven by six MOSFETs, where Vs
is the supply voltage of the motor (48 [V] nominal for Hybricycle). The action of turning on each
individual MOSFET at certain times is called commutation and will be discussed later. While Figure 38's
circuit looks relatively simple, the action of turning on these MOSFETs and commutating them correctly
can cause many design issues. In order to understand how the motor phases are properly driven a
discussion on the signals that turn the MOSFETs on is needed.
Hall sensor signals are better represented as states; by representing the sensor signal as a 1 for a
high signal and zero being a low signal. This allows for the possibility of eight states (000-111); however,
two of the eight states cannot occur since all three of the hall sensors cannot have a 1 at the same time
or have a 0 at the same time. This is due to the fact that the rotor cannot be positioned in 3 places at
once (111 or 000). This leaves six unique states for the rotor position. In each state, two of the half H-
Bridges will have signals sent to them and the third half H-Bridge will be left "floating". The floating
bridge has both transistors off so there is no power flowing from the supply or power flowing to ground.
The other two half bridges will have one of two things happening. One of the half bridges will have its
top MOSFET conducting and the bottom MOSFET off. This will cause power to flow into the phase
associated with this half bridge. In order for the power to properly flow there must be a return path
from the motor phases to ground. This is how the three half H-Bridges will constitute a full bridge at any
given time. The remaining half H-Bridge, the one that is not floating, will have a return path to ground
from a different phase. This means that the half H-Bridge has its bottom MOSFET conducting and its top
MOSFET off. Figure 39 gives an example of this, where the left most half H-Bridge has power flowing
from the supply into phase x, while the middle half bridge has power flowing from phase y to ground.
The right most half bridge is floating and has no power flowing. Thus a full bridge is created between the
two have H-bridges at phase x and y.
Page 52
Figure 39. Diagram of Power flow for one Hall state
48.
Which H-Bridge section is switched on or off is completely dependent on the rotor position of the
motor. Figure 39 shows the power flowing through the motor for a certain Hall state.
The signals that drive the transistors are known as PWM waveforms. These PWMs are outputted by
the microcontroller and translated along to the gates of the MOSFETs at the proper times specified by
the rotor position of the motor. The PWMs are pulsed (square) waveforms that have a certain duty cycle
dependent on user input- the input method being a throttle on the bicycle. A 0% duty cycle constitutes a
waveform of zero pulse width, which means that no power will be delivered to the motor. A duty cycle
of 100% corresponds to maximum power delivery to the motor (48 [V] for this system). Intermediary
duty cycles will result in less power flowing into the motor. The voltage and power seen at the motor is
directly proportional to the duty cycle of the PWM. Thus a 50% duty cycle delivers half of the supplies
power to the motor (24 [V]).The PWM signals must be properly timed in order to avoid turning both top
and bottom side MOSFETs at the same time in one half H-bridge. This must be avoided because it
provides an almost zero-impedance path from the battery to ground resulting in high current flow that
can damage the system. This is one of the biggest design issues which will be talked about later.
Page 53
Now that the basics of the drive circuitry have been presented, the design and implementation of
the actual circuitry can be discussed. As seen in Figure 36 there are multiple blocks that have not yet
been discussed. These blocks represent design implementations to properly drive the three half H-
Bridges. The main issue with designing the drive circuitry was proper biasing of the transistors of each H-
Bridge. The design for this circuitry went through multiple iterations as certain parts were found to be
incompatible with one another.
Part selection was done as necessary, beginning with preliminary research to determine maximum
voltages and currents that would be pulsed through the H-Bridge circuitry. The two main parts that were
selected for the drive circuitry were the power MOSFETs and the high voltage gate drivers, which will be
discussed further in a later section. There were initially multiple MOSFETs chosen until further design
limitations were discovered. The first type of MOSFET chosen was the IRF3806; this MOSFET has a
forward voltage rating of 60 [V] and a maximum current rating of 43 [A] with low drain to source
resistance when turned on. When tests were done with the wheel being spun manually, it was found
that a large sinusoidal back-EMF was created in each of the phases. At high wheel speeds, the peak-to-
peak voltage of this back-EMF was observed to increase in excess of 80 [V]. This caused the IRF3806s to
be destroyed. Thus, it was determined that a much higher tolerance transistor should be selected; the
STP40NF20 was selected as the replacement. These transistors have a forward rating of 200 [V] with a
possible 40 [A] of current from drain to source.
The second major part selection was the gate drivers for the H-Bridge transistors. Multiple drivers
were selected and tested because, even after research, there was still some question as to how these
parts actually operate. It was finally determined that the drivers must be high voltage capable in order
to properly turn on each transistor. These types of drivers are known as bootstrap gate drivers, the
specific one selected was the IR2110, which is capable of 600 [V] bootstrap supply and also is capable of
driving both a high and low side MOSFET simultaneously.
Page 54
The first iteration of drive circuitry design began with the H-Bridge depicted in Figure 39. Believing
that with properly commutated PWM signals the H-Bridge MOSFETs could be switched using the PWM
outputs straight from the microcontroller. After testing, it was apparent that the biasing of the power
MOSFETs was not as trivial as it initially assumed. The transistor’s datasheet specified that there must be
a minimum of 4 [V] from gate to source to turn on the transistor. This was an issue because the PWM
signal from the microcontroller is a maximum 3.3 [V]. In order to boost this signal to the appropriate
magnitude, a level shifter circuit was designed to take the 3.3 [V] PWM and boost it to a 12 [V] PWM
signal with minimal delay time. After doing some research, a level translator circuit was designed using
one BJT per PWM and a hex inverter chip: the HD74LS04. This component has six inverters on one DIP
chip. The BJT - properly biased with a 1.2 [kΩ] resistor - translated the inputted 3.3 [V] PWM signal into a
12 [V] signal with the same duty cycle while adding minimal delay due to the hex inverter’s nanosecond
delay time along with the transistor.
Research was also done on the proper biasing of power MOSFETs after first tests were completed. It
was found that, in order to properly turn on a power MOSFET, not only did the gate to source voltage
have to be sufficiently high but there must also be a relatively large charging current into the gate of the
MOSFET. Every power MOSFET has capacitances at each of its three legs; the capacitance at the gate is
the most important as it allows for the transistor to be turned on. If the gate capacitance is not
completely charged the MOSFET will not turn on under proper timing constraints and power will not
properly flow through the motor. The solution for this issue is using a gate driver as expressed
previously in the report. The selected gate driver, the IR2110, is capable of driving a load with 2 [A] of
current.
The implementation of the gate drivers caused further issues with the system until their actual
operating conditions were met. This was mainly due to poor documentation on the datasheet. Yet after
reading through an application note on the IR2110 the proper biasing of the driver was met. The main
Page 55
advantage of using this type of gate driver is its bootstrap supply voltage. The source of the top MOSFET
and the drain of the bottom MOSFET are connected to each other as seen in Figure 39 with the load in
between. The gate driver is also connected to the source of the top MOSFET. The operation of this
connection is to "pull" the potential of the gate of the top MOSFET to that of the source voltage plus an
additional 12 [V]. The added 12 [V] comes from the bootstrap capacitor that is charged to a potential of
12 [V] when the bottom side MOSFET turns on and discharges into the gate of the top side transistor
when it is turned on. This operation took a long time to properly work seeing as there were many issues
associated with the connection to the source of the top side MOSFET.
An issue with the IR2110 gate drivers was found when driving the motor. There has to be a return
path to ground for the power flow out of one of the phases, there can be a large current apparent at the
source of the top side MOSFETs if the bottom side MOSFETs are not turned on. For a small period of
time, the only path for this current to flow is into the Vs pin of the IR2110 chip. This causes the chip to
blow and consequently the circuit no longer works. By fixing the layout of the IR2110 circuit this
problem can be fixed. Giving each chip a proper ground layout will suffice.
Another important design consideration in the design of the drive circuitry is dead time of the
PWMs. This arises from the transistors in the H-bridge being burnt out during a period of time when
both the top MOSFET and bottom MOSFET of one half H-bridge are on at the same time. This causes a
massive amount of current to flow straight from Vs to ground and causes destruction of an entire half of
the H-bridge. Adding dead time is an easy fix in the coding of the commutation cycles, after each state,
there is a small delay between the time the signal is sent to turn the MOSFETs on. The only issue with
this is that it can cause the current in the motor to flow into the amp driver pin as stated above.
Bypass capacitors have also been a cause for concern at each stage of the drive circuitry. It was not
initially apparent that a bypass capacitor was needed across the entire H-bridge in order for it to
properly commutate. The size of this capacitor is very important as it has to be large due to the high
Page 56
battery voltage. After placing this capacitor in parallel with the drive circuitry, the motor began spinning
as expected. It was surprising that one capacitor changed how the motor behaved completely.
Another design issue that was run into was the Hall sensor output from the motor. The waveforms
of these devices when powered and connected to an oscilloscope were not what was expected. The
waveforms were extremely noisy and were not a proper high-low signal. In order to fix this issue, a
number of circuits were tested. First,using an operational amplifier to try and level the waveform out,
this ultimately did not work. The next design was both simpler and more convenient. By utilizing a pull-
up circuit consisting of two resistors and a capacitor connected to a 5 [V] source, the Hall sensor output
was then a perfect square waveform. This design works flawlessly with the system and has caused no
issues.
The final issue that the drive circuitry has is that the bottom transistors are being burnt due to
improper grounding of the IR2110 chips. The maximum gate-source voltage at any transistor on the H-
Bridge is ±20 [V]. If this limit is exceeded, the transistor breaks down and becomes a short. This is an
issue because current will then always flow through the shorted transistor no matter the signal at the
gate. In order to fix this, proper grounding techniques must be taken into account. By having each COM
or Vsson the IR2110 having its own unique path to a common ground will get rid of large voltage
transients at the chips COM pin. The large voltage transients can cause fluctuations at the gate which
may be larger than the 20 [V] limit. This is an important fix for any digital chip in an engineering design.
One big issue that has plagued the drive circuitry since the beginning is the motor vibrations that
occur when pedal assistance is provided. This is believed to have caused many other issues in the drive
circuitry mainly frying the H-bridge after throttling for a period of time. The motor vibrations were
thought to be caused by a number of things in the system. When the issue was first discovered it was
thought that the problem arose from improper timing of signals at the gates of the H-bridge transistors.
By measuring the signals at the gate of each transistor then comparing them with the signals outputted
Page 57
by the microcontroller it was determined that the timing of the PWM signals was not at fault. The next
hypothesis was that there was some back-EMF that was seen at the source and drain of the floating half
H-bridge during any one state. This could cause some current flow in the half H-bridge that was meant
to be doing nothing. This would make the most sense considering the noise the motor makes sounds
like a phase of the motor is misfiring.
The first attempt of fixing this issue was using a pair of anti-parallel diodes connected in series with
the phase and H-bridge, in order to block the back-EMF. After checking the signals in and out of the H-
bridges it was seen that these diodes did in fact clean up the gate signals and the back-EMF seemed to
disappear, but due to the design of the parallel circuit the back-EMF could still get through the circuit.
Thus it was determined that a diode circuit that could be switched on and off would work to our
advantage. This was created using the same anti-parallel series connection as the diodes but replacing
them with thyristors. These devices allow for a gate signal to be sent whenever the system needed to
block signals from getting through. This design worked on prototype board as it cleaned up the
incoming signals to the H-bridge and lessened the motor vibration noise, but it did not work properly on
the PCB designed for the drive circuitry.
After solving a majority of the issues with the drive circuitry on prototype circuits the next logical
step was to create a PCB layout for the drive circuitry to isolate any issues that prototype circuits can
cause, which include improper grounding and unknown signal variations. Due to large stray inductances
found in the perf board circuits ground loops could occur and cause the COM pin in the IR2110 chips to
fluctuate, as stated above. This is solved for by creating a PCB that minimizes these stray inductances by
designing for a digital and analog ground that has a short path to each COM pin. In order to test if the
PCB design was up to standards for proper grounding a PCB was created using the campuses board
router. With the help of Professor Peterson, 3 routing boards were created to test the main drive
circuitry. After soldering the board and testing it was determined that the PCB layout seemed sufficient
Page 58
to stop any ground issues from reappearing. Thus with the routing board design fully tested the next
design phase was implemented, ordering actual PCBs from APC.
Thanks to the routing boards the group had created, the APC board that would be made for the
drive circuitry had already been mostly completed. The only things to be added were protection
schemes for the H-bridge and the regeneration circuitry that could be copy pasted into the design. As a
consequence of the previous routing board tests it was found that the H-bridge would need protection
from any transients in the system, which was mainly due to the inductive spike found on the motor.
This was solved for relatively simply using diodes in parallel with each MOSFET. These diodes are
designed to catch the inductive spike before it destroys the circuitry in the H-bridge, they are known as
flyback diodes.
After completing the PCB design for the drive circuitry and regeneration an extended amount of
debugging began for this board. The drive circuitry and regeneration board did not have too many
issues prevalent at the beginning. Due to the routing board tests the drive circuitry had very little issues
when paired with the regeneration board. The main issue with combining these boards was the
possibility of the regeneration and pedal assist being on at the same time. This was solved for by having
feedback through the microcontroller and the brake throttle that would shut-off the pedal assist the
moment the brake throttle was depressed.
As stated previously the thyristor circuit for motor vibrations did not work properly on the drive and
regeneration PCB. This was likely due to the inability of the gate signals to supply the necessary amount
of current to both the thyristor gates and the high and low inputs to the IR2110 gate drivers. This was
evident due to some of the BJT transistors used in level shifting braking under added stress from the
thyristors. Thus it was decided to keep the motor vibrations in order to have a working system with
some slight vibrations when riding.
Page 59
Regeneration
There are several considerations that must be taken into account during the design of the
regeneration system. The first of these considerations is that the back-EMF of a PMAC motor is 3-phase
AC; this is demonstrated in Figure 40. The three phases of the motor were probed and the wheel was
turned to observe the generated back-EMF. The battery for the system, however, must be charged using
a DC current. It will be necessary to have a rectification circuit in the regeneration system.
Figure 40. The back-EMF of the motor used in this project is 3-Phase AC.
A second consideration is that the amount of electric braking force is directly related to the strength
of the stator magnetic field. At low mechanical speeds, the magnitude of the induced back-EMF will be
low and consequently the induced current and stator magnetic field will be low as well. If the stator
magnetic field is weak then there will be little electric braking force achievable. For this reason, the
mechanical hand brake on the bicycle must remain or else it will not be possible to bring the bicycle to a
complete stop.
Third, the battery used in the project is meant to be charged at 56 [V] and a maximum of 2 [A]. The
induced back-EMF from the motor will not be a constant 56 [V]; in fact, most of the time it can be
expected to be lower than this. Therefore it will be necessary to include circuitry in the regeneration
system that can raise the back-EMF to the appropriate charging voltage.
Page 60
Finally, the battery has a maximum charge level that should not be exceeded. Regeneration should
not be attempted if the battery is at its maximum charge capacity- refer to the battery research section
for more information.
With these considerations in mind, the initial regeneration system was designed. The block diagram
of this system is shown in Figure 41.
Figure 41. The initial system level diagram for regeneration is shown above.
As shown in Figure 41, the system is designed to work as follows:
The user sends input via a brake-lever to the microcontroller specifying that
regeneration is desired.
The controller sends the proper signals to the boost and rectification circuitry to ensure
that the back-EMF of the motor is raised to the appropriate DC charging voltage of the battery
(56 [V]).
The controller must also cease to send drive signals to the motor-drive circuitry because
it is not desired that electric braking and electric driving occur simultaneously.
There must be feedback from the battery to the microcontroller specifying the battery
charge level in order to protect against overcharging.
Page 61
The initial regeneration design focused on limiting the number of components added to the final
product package. The design utilized the MOSFETs in the H-Bridge drive circuitry to accomplish both the
boosting and rectification of the motor’s back-EMF49. The basic DC-DC boost converter circuit from
which this regeneration design was based is shown in Figure 42.
Figure 42. The basic boost converter circuit.
In the basic boost converter, the theoretical voltage transfer function is given by the equation:
In the equation, D is the duty ratio of the switch. As the equation shows, the output voltage can be
increased by increasing the amount of time that the switch is closed. For the purposes of this project,
the boost circuit would be constructed in the following way: the input voltage would be supplied by the
motor back-EMF, the inductor would be provided by the inductance of the motor’s stator windings, the
lower H-bridge MOSFET would serve as the switching device, and the upper H-bridge MOSFET would
serve as the diode (accomplished by leaving the MOSFET off and utilizing its internal diode). The battery
would represent the load. This circuit would be repeated 3 times (once for each phase of the motor) and
the upper MOSFETs would also serve as a 3-phase rectifier. The end result would be a DC-voltage with
magnitude greater than that of the motor’s back-EMF.
This design would have required that only one additional input device be added to the electric
bicycle system. The majority of the regeneration design would then be code-based and so multiple
Page 62
simulations of this design were completed. A model used for the simulation of this design is shown in
the appendix on page 79. In the model, the motor has been replaced with a 3-phase voltage source.
Several simulations were run to determine the effect of various parameters on the functionality of
the system. The results of these experiments are shown below. Figure 43 shows the basic operation of
the system. For this simulation, inductance was set to 10 [uH], the capacitance 680 [uF], the input
voltage 3 [V] at 60 [Hz] and the duty ratio set to 60%. The output voltage is of greater magnitude than
the back-EMF and it is approaching a steady-state DC output. Figure 44 shows the effect of increasing
the frequency of the back-EMF to 120 [Hz]. As the plot demonstrates, an increase in the frequency of
the back-EMF has no effect on the output voltage waveform. Figure 45 shows the effect of increased
inductance ( 100 [uH]) on the output; from the plot it is clear that a greater value of inductance results
in less voltage boost but steady-state operation occurs much sooner. The plots in Figure 46 show the
result of decreasing the duty ratio of the switch to 40% (the inductance value was left high for this
experiment). As expected, decreasing the duty ratio of the switch resulted in a lower magnitude output
voltage.
Figure 43. The basic operation of the regeneration circuit is shown above.
Page 63
Figure 44. Increasing the frequency of the input voltage does not have an effect on the output voltage of the circuit.
Figure 45. A larger value of inductance results in less voltage boost, but a flatter output voltage.
Figure 46. Decreasing the duty ratio of the bottom H-bridge MOSFETs results in less voltage boost at the output.
Page 64
There were several considerations that needed to be made with this regeneration design. First,
while the simulations show that an increase in back-EMF frequency does not affect the output voltage,
the back-EMF magnitude is not constant with frequency. The amount of boost required to achieve the
correct charging voltage varies with the magnitude of the back-EMF and so it is necessary to know the
relationship between the back-EMF magnitude and frequency. This relationship is derived in the Motor
Characterization portion of our research section. Secondly, if the internal inductance of the motor was
to be used as the boost inductor it is necessary to know what the value of this inductance is. However,
as mentioned in the research portion of our paper, we were unable to determine the internal
inductance of the stator windings. This was one of a number of problems with the initial regeneration
design.
Another major issue with the initial design for regeneration was that it could not provide
overvoltage protection for the battery. The system was only capable of boosting and rectifying the
motor’s back-EMF. If the EMF was to increase to a magnitude greater than the safe charging voltage of
the battery it would not be possible to lower this voltage and the battery could potentially be damaged.
A further problem with this design was that it required testing with the H-Bridge circuit that was still
under construction and design by the motor-drive engineer. This hamstrung the progress of the
regeneration system design.
Due to these design issues, a second regeneration system design was made. This new design
separated the regeneration circuitry from the drive circuitry. It also included overvoltage protection for
the battery and required less complicated feedback control design. The system level diagram of this
second regeneration system is shown in Figure 47.
Page 65
Figure 47. The system level diagram for the re-designed regeneration system is shown above.
The new system functions as follows:
The user sends input via a brake-lever to the microcontroller specifying that
regeneration is desired.
The controller shuts down the drive circuitry and sends a signal to close the Regen-
Switch thereby connecting the rectified back-EMF to the battery via the buck-boost integrated
circuit.
The buck-boost integrated circuit takes the rectified back-EMF and handles the
translation of this voltage to the charging voltage of 56 [V].
Feedback from the battery to the microcontroller specifies the battery charge level in
order to protect against overcharging.
This design also includes overvoltage protection for the battery because the buck-boost integrated
circuit is capable of both raising voltages below the required charging voltages and lowering voltages
that are above the safe charging voltage.
The selection of the components for the buck-boost integrated circuit now constituted the bulk of
the regeneration system design. An LM5118 wide voltage range buck-boost controller from Texas
Instruments was selected for the buck-boost circuitry50. This controller is capable of accepting input
voltages in the range of 5 to 75 [V] and translating them to an output voltage anywhere in the same
Page 66
range. Therefore, we can design the controller to output 56 [V] and it will accept any input voltage in the
5-75 [V] range and properly translate it to an output voltage of 56 [V]. This is the exact functionality
desired for the regeneration system because, although the back-EMF magnitude will vary drastically
depending on the speed of the bicycle, the charging voltage requirement does not vary.
A schematic showing the LM5118 and the proper components to produce a 56 [V] output is shown in
the appendix on page 80. The components were selected using the same Web Bench tool discussed
earlier in the Power Systems section22. The basic functionality of the controller is as follows:
If the input voltage of the system is greater than the desired output voltage then the
lower MOSFET will remain off and the circuit will resemble a simple DC-DC Buck converter. The
duty ratio will be adjusted according to the buck transfer function ( ) in order to
properly output the desired charging voltage.
If the input voltage to the system is less than the desired output voltage, then the upper
and lower MOSFETs will be supplied with the same duty ratio and the circuit will resemble a
buck-boost converter. The duty ratio will be adjusted according to the buck-boost transfer
function (
) in order to output the desired charging voltage.
This regeneration circuit was constructed and the ability to properly boost a rectified back-EMF to
the proper charging voltage of 56 [V] was demonstrated. However, although the circuit worked perfectly
under no load conditions, we were unable to make it function properly when loaded with either the
battery or a purely resistive load. The debugging of the LM5118 IC was complicated and eventually we
were forced to abandon it and redesign the regeneration system for a third time.
The third and final regeneration design functioned very similarly to the second design, and the
system level diagram shown in Figure 47 is still valid. In the final design, the LM5118 buck-boost IC was
replaced with a much simpler 5-pin boost IC: the LT117051. This IC is capable of receiving input voltages
in the range of 3-60 [V] and raising them to a voltage within that same range. The charging voltage of
Page 67
our battery is 56 [V] and so this IC was well suited to our needs. The selection of components for this IC
was aided by the use of an application note which discussed both boost-circuit design and on/off control
of the IC [app note]. The finalized schematic showing the regeneration system is shown in the appendix
on page 81.
This simpler IC was much easier to design and debug with, and a functioning circuit that was able to
rectify the motor’s back-EMF, and boost the voltage to 56 [V] while loaded with the 48 [V] battery was
quickly constructed. While the LT1170 was much easier to use than the LM5118, there was one feature
of the LM5118 that was missed: the ability to buck voltages exceeding the charging voltage of 56 [V]. As
a boost converter, the LT1170 is incapable of providing this functionality. In this third regeneration
design, if the rectified back-EMF were to exceed 56 [V] this voltage would be present at the battery and
could potentially cause damage. Furthermore, the LT1170 is only rated up to 60 [V], and so any input
voltage greater than this would destroy the IC.
By replacing the LM5118 with the LT1170 the ability to load the circuit was gained, however
overvoltage protection was lost. It was necessary to add additional circuitry to provide this protection.
Ultimately, overvoltage protection was accomplished through the use of a high-sensitivity power PCB
relay52. A functional diagram of the overvoltage protection circuitry is shown in Figure 48.
Figure 48. Functional diagram of the overvoltage protection scheme.
Page 68
The relay is configured to be normally closed. The rectified back-EMF voltage appears at the Zener
diode and at one of the relay’s switched inputs. When the back-EMF is lower than 56 [V] in magnitude
the rectified waveform is allowed to pass through the normally closed relay. However, when the back-
EMF reaches 56 [V] or greater, there is enough current through the Zener diode and control coil of the
relay that the relay opens and the rectified back-EMF is not able to reach the LT1170 or the battery.
One consequence of implementing overvoltage protection in this way is that when the back-EMF
exceeds 56 [V] it is not possible to engage the electric brake because no current can flow to the battery.
However, the magnitude of the back-EMF is related to the speed of the bicycle and would only exceed
56 [V] when the speed of the bicycle exceeds 50 [mph] (based on the equations relating back-EMF to
electrical frequency and electrical frequency to mechanical speed presented in the Motor
Characterization section of this report). The electric brake control is integrated to the mechanical brake
lever. Therefore, at very high speeds, only the mechanical brake would engage until the bike speed was
decreased such that the back-EMF was lowered to safe levels. At that point, the electric brake would
then turn on to help aide the slowing of the bike.
With the regeneration and overvoltage protection circuitry designed the only remaining challenge
was the on/off control of the electric brake. The AN19FC application note for the LT1170 was useful in
determining how to accomplish this control53. The application note described that the current limit of
the LT1170 could be controlled by regulating the voltage at the VC pin. By lowering this voltage to 0 [V]
the current limit is brought to 0 [A] and the chip is effectively turned off. This knowledge allowed the
on/off control of the electric brake to be designed.
Initially, a MOSFET was used to accomplish on/off control. The drain of the MOSFET was connected
to the VC pin and the source connected to ground such that the VC pin could be brought to 0 [V] by
controlling the MOSFET gate voltage with the microcontroller. This design worked in initial tests when a
power supply was used as the input voltage source, but the design failed when the battery was used as
Page 69
the voltage source. It was determined that the MOSFET was entering triode region when the battery
was used and therefore the voltage at the VC pin was never tied directly to ground and the electric
brake always remained partially on.
In the second design phase of the regeneration on/off control the MOSFET was replaced with a relay
identical to the one used for overvoltage protection. The relay was again configured to be normally
closed, this time connecting the VC pin to ground. The control coil was connected to 12 [V] through the
electric brake switch such that when the switch was closed 12 [V] was present at the control coil,
thereby opening the relay, disconnecting the VC pin from ground, and turning on the boost circuit and
therefore engaging the electric brake. This on/off control scheme functioned perfectly but there was
one flaw: because the control coil of the relay required 12 [V] the control of the electric brake was
independent of the microcontroller. This meant that the user could potentially try to drive the motor
and engage the electric brake simultaneously which was not an allowable functionality. The on/off
control needed to be redesigned such that it was not independent of the microcontroller.
The final electric brake on/off control scheme was also accomplished using a relay. However, this
time the relay was a much smaller 3.3 [V] solid state relay. The new relay was configured such that it
was normally open and could be closed by turning on an internal LED. The control of this LED was
handled by the microcontroller. The electric brake switch was wired such that when the brake lever was
depressed a voltage would be present at one of the input pins of the microcontroller. When the
microcontroller did not detect this voltage, the control signal sent to the relay was high such that the
LED would be on, the relay closed, and the VC pin of the LT1170 connected to ground. When no voltage
was detected at the brake lever pin of the micro, the user was free to drive the motor. When the brake
lever was depressed and a voltage was present at the input of the microcontroller, the output signal to
the relay would be low such that the LED was off, the relay open, and the VC pin of the LT1170
disconnected from ground. In this matter the electric brake was turned on. In addition to turning on the
Page 70
electric brake, the microcontroller also turned off the motor drive signals and ignored any attempts by
the user to drive the motor while the electric brake was engaged.
The completion of the on/off control design represented the completion of the regeneration
system. In the lab, we were able to observe all the desired functionality. In one test, the voltage at the
battery was probed and the wheel was forcibly spun for 15 [s] while the electric brake was engaged. The
team was able to observe a rise in the battery voltage (in the range of 10 [mV]) thus verifying the ability
to recharge the battery using the electric brake.
Page 71
Budget
Our goal for this project is to produce an electric bicycle conversion kit at a price-point comparable
to similar products available on the market. Conversion kits which offer similar features to those we plan
to offer typically cost in the range of $1000. However, most kits do not offer a regenerative braking
feature. At this point, the majority of the expense for this project has already been paid for. The to-date
costs are summarized below.
Part Company Total Price Date Ordered
Microcontroller DSPIC33FJ128MC802 Microchip $0.00 1/11/13
Microstick 2 Microchip $63.79 1/14/13
Microcontroller DSPIC33FJ128MC802 Microchip $0.00 1/14/13
Engineering Notebooks Amazon $67.96 1/15/13
Motor and Controller Kit E-Bike Direct $443.90 1/15/13
Battery and Charger NiMH 10 AH Battery Space $492.59 1/17/13
Binders/Dividers UCSC Bookstore $31.33 1/22/13
Test Harness 3.5mm Headphone Radioshack 17.29 1/25/13
Extra Motor Cable E-bike kit 36 1/29/13
Wire + Connectors Radioshack 28.82 1/29/13
Return Connectors Radioshack -4.88 1/29/13
Battery Connectors Capitola Hobbies 8.63 1/29/13
Discrete Parts Halted 43.71 2/15/13
Cermaic Capacitors Radioshack 11.91 2/16/13
Electrolytic/Cermaic Capacitors Frys 56.57 2/18/13
High Ripple Capacitors DigiKey 35.47 2/21/13
Power MOSFETS Future Electronics 42.26 2/24/13
Discrete Components (DIP Adapters) Protoadvantage 35.45 3/1/13
ProtoBoards Radioshack 12.68 3/1/13
LCD DigiKey 62.01 3/1/13
Resistors/Current Sense Resistors/LM324s DigiKey 73.1 3/6/13
Gate Drivers Arrow Electronics 30.24 3/14/13
Discrete Parts (Protoboard, DIP Adapters) Sparkfun 29.64 2/12/13
ProtoBoards Radioshack 12.47 2/8/13
Gate Drivers Arrow Electronics 14.88 2/14/13
Gate Drivers Arrow Electronics 24.9 2/27/13
Headers/Protoboard BELS 20 3/12/13
Discrete Components (caps, inductors, diodes) DigiKey 40.48 3/8/13
Discrete Components(perf boards) Radioshack 12.47 3/21/13
Gate Drivers Arrow electronics 33.84 4/5/13
Discrete Components Digikey 50.32 4/9/13
Capacitors and Resistors Mouser 29.31 4/12/13
Power Systems and Microcontroller PCBs APC 165.1 4/22/13
MDF Probuild 8.75 4/22/13
Diodes and Relays Arrow Electronics 74.91 4/24/13
Relays Arrow Electronics 21.12 4/25/13
Glue and Sanding Block Westside Hardware 7 4/26/13
LCD and Capacitors Digikey 59.89 4/30/13
MOSFETS/Microcontroller Arrow electronics 62.44 5/1/13
MDF and Metal Brackets Probuild 19.55 5/1/13
PCB Board AP Circuits 194.76 5/3/13
Discrete Components(caps, diodes) Digikey 19.75 5/3/13
Connectors Radioshack 15 5/11/13
Screws Westside Hardware 18.72 5/11/13
MDF Probuild 13.25 5/13/13
Rear Bike Rack Walmart 16.69 5/14/13
Discrete Components Digikey 41.37 5/14/13
MOSFETS Arrow electronics 47.33 5/15/13
Screws Westside Hardware 9.8 5/19/13
Paint Orielly 18.45 5/19/13
Screws, Bungee Cords and Straps Westside Hardware 23.76 5/20/13
Solid State Relays and Gate Drivers Arrow Electronics 34.36 5/25/13
1st Quarter Total 2nd Quarter Total Project Total
$1,731.20 997.94 $2,729.14
Page 72
While the budget up to this point goes over $1000, this includes research and development costs.
The final bill of materials and cost to implement will still be far below this price point.
At the end of our project we had gone over the estimated budget by about $700. This is not too bad
considering all of the parts that had been destroyed while testing the systems. The second PCB was also
not expected in our first budget which added close to $200 to the final cost. Overall the price of the
design and implementation of the Hybricycle worked out well.
An estimated cost of one finished prototype including the motor controller, motor, LCD, throttles
and all necessary connectors would be $700. This does not include the cost of the battery. The price
point of our Hybricycle system compares relatively well compared to the price of an E-bike you can find
online.
Conclusion
We were ultimately able to complete and fully integrate all the components of our project and
assemble a working prototype electric bicycle. However, the prototype was not without flaws. The
motor vibration problems were never eradicated and the H-Bridge circuitry was prone to failure. If more
work were to be done on this project in the future the design of more robust motor drive circuitry would
be an area to focus on (potentially using pre-made H-Bridges rather than building them from MOSFETS).
Moreover, more protection circuitry could have been added to prevent catastrophic failures. The PCB
layout could also be improved to decrease switching transients from stray inductances.
While we were forced to make certain design compromises due to time constraints we were still
able to meet our minimum specifications we set at the beginning of the design process.
Page 73
References
1. http://www.goldenmotor.com/e-Bike-DIY/DIY-ebikekit.php
2. http://www.stealthelectricbikesusa.com/
3. http://ww1.prweb.com/prfiles/2011/09/07/8778840/DSCF9213.JPG
4. http://www.thelashop.com/48v-500w-26-inch-rear-wheel-electric-bicycle-motor-conversion-kit.html?gclid=CL6YgZfW2LcCFY1DMgod3BcAKQ#.UTmWTTeME7o?utm_source=GoogleShopping&utm_medium=organic?utm_source=googlepla&utm_medium=cpc
5. http://www.motostrano.com/Stealth-Bomber-Electric-Bike-p/bomber.htm?gclid=CIPo043W2LcCFc9AMgod530AuQ&click=2
6. http://www.e-bikekit.com/
7. http://www.matrixorbital.com/
8. http://media.nashbar.com/images/nashbar/products/large/NB-SSRF-NCL-SIDE.jpg
9. http://www.powerstream.com/NiMH.htm
10. http://members.toast.net/joerger/pic2/discharge.gif
11. J. Kopera (25 June 2004). "Inside the Nickel Metal Hydride Battery". Cobasys. Retrieved 2011-09-10.
12. S. Chapman. “Electric Machinery Fundamentals, Fifth Edition”. McGraw Hill (2005).
13. http://www.e-bikekit.com/ebike-kits/electric-bike-motor
14. http://www.electricbike.com/regenerative-brakes/
15. http://www.ecospeed.com/regenbraking.pdf
16. AN857 “Brushless DC Motor Control Made Easy”. Microchip. http://ww1.microchip.com/downloads/en/AppNotes/00857B.pdf
17. AN1916 “3-Phase BLDC Motor Control with Hall Sensors Using 56800/E Digital Signal Controllers”. Freescale Semiconductor. http://www.freescale.com/files/product/doc/AN1916.pdf
18. AN786 “Driving Power MOSFETs in High-Current, Switch Mode Regulators”. Microchip. http://ww1.microchip.com/downloads/en/appnotes/00786a.pdf
19. An978 “HV Floating MOS-Gate Driver ICs”. International Rectifier. http://www.irf.com/technical-info/appnotes/an-978.pdf
20. http://www.dimensionengineering.com/info/switching-regulators
21. SLV477A “Basic Calculation of a Buck Converter’s Power Stage”. Texas Instruments. http://www.ti.com/lit/an/slva477a/slva477a.pdf
22. http://www.ti.com/lsds/ti/analog/webench/power.page
23. WebBench. Texas Instruments. http://www.ti.com/lsds/ti/analog/webench/power.page
24. Basic Calculation of a Buck Converter’s Power Stage. Texas Instruments. SLV477A. http://www.ti.com/lit/an/slva477a/slva477a.pdf\
25. Component Calculator for BUCK Converters. http://www.ti.com/tool/buck-convcalc
26. Power Electronics: A First Course. Ned Mohan. 2012
27. Power Stage Designer of Most Commonly Used Switch Mode Power Supplies http://www.ti.com/tool/powerstage-designer
28. A beginner’s guide to switching regulators http://www.dimensionengineering.com/info/switching-regulators
29. AN-1253 Wide-Input, High Voltage Buck Converter. http://www.ti.com/lit/an/snoa426b/snoa426b.pdf
30. Input and Output Noise in Buck Converters Explained, http://pdfserv.maximintegrated.com/en/an/AN986.pdf
Page 74
31. It's a Buck; It's a Boost, No! It's a Switcher! http://www.ti.com/lit/wp/snva549/snva549.pdf http://www.ti.com/lit/wp/snva574/snva574.pdf http://www.ti.com/lit/wp/snva547/snva547.pdf http://sva.ti.com/assets/en/appnotes/techedge_sep2003.pdf
32. Input and Output Capacitor Selection. Texas Instruments. SLTA055. http://www.ti.com/lit/an/slta055/slta055.pdf
33. AN-556 Introduction to Power Supplies http://www.ti.com/lit/an/snva006b/snva006b.pdf
34. Layout Guidelines for Switching Power Supplies. Texas Instruments. AN1149. http://www.ti.com/lit/an/snva021c/snva021c.pdf
35. Selecting Inductors for Buck Converters. Texas Instruments. AN1197. http://www.ti.com/lit/an/snva038b/snva038b.pdf
36. Simple Switcher PCB Layout Guidelines Texas Instruments. AN1229. http://www.ti.com/lit/an/snva054c/snva054c.pdf
37. http://www.e-bikekit.com/shop/images/products/ebk-twst-trs.jpg
38. Power Electronics: A First Course by Ned Mohan.
39. APT0403 “Power MOSFET Tutorial”. http://www.microsemi.com/document-portal/doc_download/14692-mosfet-tutorial
40. www.ti.com/product/lm2673
41. “dsPIC33FJ32MC302/304, dsPIC33FJ64MCX02/X04 and dsPIC33FJ128MCX02/X04 Data Sheet”. Microchip. http://ww1.microchip.com/downloads/en/DeviceDoc/70291E.pdf
42. http://www.actel.com/documents/Dual_Kit_Block_Commutation_With_Hall_Sensors_UG.pdf
43. “Nickel-metal hydride battery”. http://en.wikipedia.org/wiki/Nickel%E2%80%93metal_hydride_battery
44. http://www.microchip.com/TechDoc.aspx?type=ReferenceManuals
45. http://bldc.wdfiles.com/local--files/bldc-and-8051/Three_phase_BLDC_internal_diagram.jpg
46. http://e2e.ti.com/resized-image.ashx/__size/550x0/__key/CommunityServer-Discussions-Components-Files/471/3568.120_5F00_bldc_5F00_hall.JPG
47. http://2.bp.blogspot.com/_0GFbtQlca4/UD9sCRNMojI/AAAAAAAAAH8/2jNqzSYTRZU/s1600/310px-H_bridge_svg.png
48. http://www.innovatia.com/Design_Center/DC_images/image254.gif
49. “Regenerative Braking of BLDC Motors”. Microchip. http://ww1.microchip.com/downloads/en/DeviceDoc/Regenerative%20Braking%20of%20BLDC%20Motors.pdf
50. LM5118 “Wide Voltage Range Buck-Boost Controller”. Texas Instruments. http://www.ti.com/lit/ds/symlink/lm5118.pdf
51. LT1170 “High Efficiency Switching Regulators”. Linear Technology. http://cds.linear.com/docs/en/datasheet/117012fg.pdf
52. “G2R Power PCB Relay”. Omron. http://www.omron.com/ecb/products/pdf/en-g2r.pdf
53. AN19FC “LT1070 Design Manual”. Linear Technology. http://cds.linear.com/docs/en/application-note/an19fc.pdf
Page 75
Appendix
Power Rails
12V Rail
5V Rail
3.3V Rail
Page 76
Microcontroller
Page 77
PWM Level Shifter
Page 78
Gate Driver
Page 79
H-Bridge
Initial Regeneration Model
Page 80
Regeneration Buck-Boost Circuit
Page 81
Final Regeneration Circuit with Overvoltage Protection
Page 82
Microcontroller Code /* * File: Main.c * Author: rchavez * * Created on January 29, 2013, 12:09 PM */ #include <stdio.h> #include <stdlib.h> #include <pwm.h> #if defined(__dsPIC33F__) #include "p33fxxxx.h" #elif defined(__PIC24H__) #include "p24hxxxx.h" #endif #define FCY 49747500 #define BAUDRATE 19200 #define BRGVAL ((FCY/BAUDRATE)/16)-1 _FOSCSEL(FNOSC_FRC); _FOSC(FCKSM_CSECMD & OSCIOFNC_ON); _FWDT(FWDTEN_OFF); _FPOR(FPWRT_PWR128); _FICD(0xFFDF); _FGS(GCP_OFF); /*Declarations*/ unsigned int DmaBuffer = 0; char * wheelF; char buffer[5]; float wheelFrequencyDIV1 = 0, wheelFrequencyDIV2 = 0, wheelFrequencyMUL1 = 0, wheelFrequencyMUL2 = 0, wheelFrequencyMUL3 = 0; static int screen_Init = 0, write_Speed = 0, write_Batt = 0, update_Data = 0, screen_Toggle = 0, percentData = 0;
int i = 0, regenON = 0, countFreqFlag = 0, countHigh = 0, SW = 0, delayU1 = 0, clearDISP = 0, toggle = 1, deadTIME = 0, stateTrans = 0, wheelFrequency = 0, wheelFrequencyMPH = 0; long int an2_SAMP = 0, an1_SAMP = 0, an0_SAMP = 0, hall_1_Read = 0, hall_2_Read = 0, hall_3_Read = 0, brake_Lever = 0; int BufferA[4][8] __attribute__((space(dma), aligned(64))); int BufferB[4][8] __attribute__((space(dma), aligned(64))); char myARR[4] = 0xA0, 0x01, 0xFE, 0x58; void Clock_Output_Config(void); void PWM_Config(void); void ADC_DMA_Config(void); void Uart_Config(void); void FrequencyCount_Config(void); void PWMADCSamples(int* Buf); void BatteryADCSamples(int* Buf1); void Init_Screen(void); void Write_Speed(void); void Write_Batt(void); void Update_Data(void); void __attribute__((interrupt, no_auto_psv)) _DMA5Interrupt(void) //Switch between Primary and Secondary Ping-Pong buffers if(DmaBuffer == 0) PWMADCSamples(&BufferB[1][0]); BatteryADCSamples(&BufferB[0][0]); else PWMADCSamples(&BufferB[1][0]); BatteryADCSamples(&BufferB[0][0]); DmaBuffer ^= 1; IFS3bits.DMA5IF = 0; //Clear the DMA Channel 5 interrupt flag void __attribute__ ((interrupt, no_auto_psv)) _T1Interrupt(void) countFreqFlag = 1; //Set Flag to start counting frequency IFS0bits.T1IF = 0; //clear timer1 interrupt flag. T1CONbits.TON = 0; //Stop Timer 1 TMR1 = 0x0000; //Clear Timer 1 Register TMR5 = 0x0000; TMR4 = 0x0000; //Clear timer 4 register PR5 = 0x0002; PR4 = 0xF716; //load period value reg 4 (1 Second) => 49.7MHz/(256 Prescaler) = .194 MHz => 2F716/.194MHz = 1 Second T4CONbits.TON = 1; //Start Timer 4 void __attribute__ ((interrupt, no_auto_psv)) _T5Interrupt(void) countFreqFlag = 0; //Clear Flag to stop counting frequency IFS1bits.T5IF = 0; //clear timer4 interrupt flag. wheelFrequency = countHigh; //do something with wheel frequency wheelFrequencyMPH = (((float)wheelFrequency/22.0)*70*3.1415926*3600)/63360.0; countHigh = 0; T4CONbits.TON = 0; //Stop timer4 TMR5 = 0x0000; //Clear 32-bit TMR4 = 0x0000; //register---- PR1 = 0x0032;
T1CONbits.TON = 1; void __attribute__ ((interrupt, no_auto_psv)) _U1TXInterrupt(void) IFS0bits.U1TXIF = 0; //Clear TX interrupt flag if(screen_Toggle == 0) Init_Screen(); else if(screen_Toggle == 1) Write_Speed(); else if(screen_Toggle == 2) Write_Batt(); else if(screen_Toggle == 3) Update_Data(); int main (void) Clock_Output_Config(); PWM_Config(); ADC_DMA_Config(); Uart_Config(); FrequencyCount_Config();
Page 83
while (1) while(countFreqFlag) if(PORTAbits.RA2) while(PORTAbits.RA2); countHigh++; //This is the frequency (F = countHigh/1second) void PWMADCSamples(int * Buf) hall_1_Read = PORTAbits.RA2; //Read RA2 Pin for Hall Sensor 1 hall_2_Read = PORTAbits.RA3; //Read RA3 Pin for Hall Sensor 2 hall_3_Read = PORTBbits.RB4; //Read RB4 pin for Hall Sensor 3 brake_Lever = PORTAbits.RA0; //Read RA0 pin for Brake Lever an1_SAMP = (long int)(*Buf); //Apply Duty PDC1 = ((an1_SAMP + 16128)>>2); //cycle based PDC2 = PDC1; //on ADC register PDC3 = PDC2; //read (AN1 input) if(an1_SAMP > 18000) PDC1 = 8400; //cycle based PDC2 = PDC1; //on ADC register PDC3 = PDC2; //P1OVDCON = 0x0024; if(!brake_Lever) P2OVDCON = 0x0000; if((hall_1_Read & hall_2_Read & hall_3_Read) | ((!hall_1_Read) & (!hall_2_Read) & (!hall_3_Read))) // Pedal Assist State Machine
P1OVDCON = 0x0000; else if(~hall_1_Read & ~hall_2_Read & hall_3_Read) // if(stateTrans == 3) // P1OVDCON = 0x0000; // for(deadTime = 0; deadTime < 30; deadTime++) // Nop(); // // if(an1_SAMP < -9000) P1OVDCON = 0x0000; else P1OVDCON = 0x2400; stateTrans = 1; else if(~hall_1_Read & hall_2_Read & ~hall_3_Read) // if(stateTrans == 6) // P1OVDCON = 0x0000; // for(deadTime = 0; deadTime < 30; deadTime++) // Nop(); // // if(an1_SAMP < -9000) P1OVDCON = 0x0000; else P1OVDCON = 0x0900; stateTrans = 2; else if(~hall_1_Read & hall_2_Read & hall_3_Read) // if(stateTrans == 2) // P1OVDCON = 0x0000; // for(deadTime = 0; deadTime < 30; deadTime++) // Nop(); // // if(an1_SAMP < -9000) P1OVDCON = 0x0000; else P1OVDCON = 0x2100; stateTrans = 3; else if(hall_1_Read & ~hall_2_Read & ~hall_3_Read) // if(stateTrans == 5) // P1OVDCON = 0x0000; // for(deadTime = 0; deadTime < 30; deadTime++) // Nop(); // // if(an1_SAMP < -9000) P1OVDCON = 0x0000; else P1OVDCON = 0x1200; stateTrans = 4; else if(hall_1_Read & ~hall_2_Read & hall_3_Read) // if(stateTrans == 1) // P1OVDCON = 0x0000; // for(deadTime = 0; deadTime < 30; deadTime++) // Nop(); // // if(an1_SAMP < -9000) P1OVDCON = 0x0000; else P1OVDCON = 0x0600; stateTrans = 5; else if(hall_1_Read & hall_2_Read & ~hall_3_Read) // if(stateTrans == 4) // P1OVDCON = 0x0000; // for(deadTime = 0; deadTime < 30; deadTime++) // Nop(); // // if(an1_SAMP < -9000) P1OVDCON = 0x0000; else P1OVDCON = 0x1800; stateTrans = 6; else if(brake_Lever) P1OVDCON = 0x0000; P2OVDCON = 0x0003; void BatteryADCSamples(int * Buf1) an0_SAMP = (long int)(*Buf1); //an0 sample void Clock_Output_Config(void) /* Configure PLL prescaler, PLL postscaler, PLL divisor */ PLLFBD=52; /* M = PLLFBD + 2 */
Page 84
CLKDIVbits.PLLPOST=0; /* N1 = 2 */ CLKDIVbits.PLLPRE=0; /* N2 = 2 */ CLKDIVbits.FRCDIV=0; __builtin_write_OSCCONH(0x01); /* New Oscillator FRC w/ PLL */ __builtin_write_OSCCONL(0x01); /* Enable Switch */ while(OSCCONbits.COSC != 0b001); /* Wait for new Oscillator to become FRC w/ PLL */ while(OSCCONbits.LOCK != 1); /* Wait for Pll to Lock */ /* Now setup the ADC and PWM clock for 120MHz ((FRC * 16) / APSTSCLR ) = (7.37 * 16) / 1 = ~ 120MHz*/ TRISAbits.TRISA4 = 0; /* Set as a digital output */ TRISBbits.TRISB13 = 0; /* Set as a digital output */ TRISAbits.TRISA2 = 1; //Set RA2 as input for hall sensor 1 TRISAbits.TRISA3 = 1; //Set RA3 as input for hall sensor 2 TRISBbits.TRISB4 = 1; //Set RB4 as input for hall sensor 3 TRISAbits.TRISA0 = 1; //Set RA0 as input for Brake Lever LATAbits.LATA4 = 1; LATBbits.LATB13 = 1; void PWM_Config(void) PWM1CON2bits.OSYNC = 1; //Out overrides via the P1OVDCON register are synchronized to the PWM //time base by setting the OSYNC bit PWM2CON2bits.OSYNC = 1; PTPER = 4250; /* PTPER (period register = ((1 / 400kHz) / 1.04ns) = 2404, where 400kHz is the desired switching frequency and
1.04ns is PWM resolution. */ P2TPER = 3000;
/*~~~~~~~~~~~~~~~~~~~~~~~ PWM1 Configuration ~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ PWMCON1bits.PEN1H = 1; /* PWM2H is controlled by GPIO module */ PWMCON1bits.PEN1L = 1; /* PWM2L is controlled by PWM module */ PWMCON1bits.PMOD1 = 1; /* Select Independent Output PWM mode */ PDC1 = 0; /* Initial Duty cycle */ // P1DTCON2bits.DTS1A = 1; /* Deadtime setting */ /*~~~~~~~~~~~~~~~~~~~~~~~ PWM2 Configuration ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ PWMCON1bits.PEN2H = 1; /* PWM2H is controlled by GPIO module */ PWMCON1bits.PEN2L = 1; /* PWM2L is controlled by PWM module */ PWMCON1bits.PMOD2 = 1; /* Select Independent Output PWM mode */ PDC2 = 0; /* Initial Duty cycle */ /*~~~~~~~~~~~~~~~~~~~~~~~ PWM3 Configuration ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ PWMCON1bits.PEN3H = 1; /* PWM2H is controlled by GPIO module */ PWMCON1bits.PEN3L = 1; /* PWM2L is controlled by PWM module */ PWMCON1bits.PMOD3 = 1; /* Select Independent Output PWM mode */ PDC3 = 0; /* Initial Duty cycle */ /*~~~~~~~~~~~~~~~~~~~~~~~ PWM4 Configuration ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ PWM2CON1bits.PEN1H = 1; PWM2CON1bits.PEN1L = 1; PWM2CON1bits.PMOD1 = 1; P2DC1 = 0; //P1DTCON2bits.DTS2A = 64; /* Deadtime setting */ PWM2CON2bits.IUE = 1; PWM1CON2bits.IUE = 1; P1DTCON1bits.DTAPS = 0; P1DTCON1bits.DTA = 64; P1DTCON2bits.DTS3A = 0; P1DTCON2bits.DTS2A = 0; P1DTCON2bits.DTS1A = 0; P1DTCON2bits.DTS3I = 0; P1DTCON2bits.DTS2I = 0; P1DTCON2bits.DTS1I = 0; P1TCONbits.PTEN = 1; /* Enable the PWM Module */ P2TCONbits.PTEN = 1; void ADC_DMA_Config(void) //AD1PCFGL = 0x0001; /*~~~~~~~~~~~~~~~~~~~~~~~ ADC Set Up For Channel 0-3 sampling ~~~~~~~~~~~~*/ AD1CON1bits.FORM = 3; //Data Output Format: Signed Fractional AD1CON1bits.SSRC = 2; //Sample Clock Source: Timer3 & Timer5 Trigger ADC Conversion For ADC1 & ADC2 Respectively AD1CON1bits.ASAM = 1; //Sampling Begins Immediately After Last Conversion. SAMP Bit is auto-set AD1CON1bits.AD12B = 0; //10-bit, 4 channel ADC Operation AD1CON1bits.SIMSAM = 0; //Samples CH0,CH1,CH2 and CH3 sequentially AD1CON2bits.BUFM = 0; //Always starts filling the buffer from the start address AD1CON2bits.CSCNA = 1; //Scan Inputs for CHO+ during sample A bit AD1CON3bits.ADRC = 0; //ADC Clock is derived from system clock AD1CON3bits.ADCS = 63; //ADC Conversion Clock 0 = 1 * Tcy = TAD, 63 = 64*Tcy =TAD AD1CHS0bits.CH0SA = 2; //Select AN0 for CH0 +ve input AD1CHS0bits.CH0NA = 0; //Select VREF- for CH0 -ve input AD1CHS123bits.CH123SA = 1; //Select AN3 for CH1 +ve input //Select AN4 for CH2 +ve input //Select AN5 for CH3 +ve input AD1CHS123bits.CH123NA=0; //Select VREF- for CH1/CH2/CH3 -ve inputs //AD1CSSH = 0x0000; //Skip S AD1CSSL = 0x003C; //0x000F Scan AIN0, AIN1, AIN2, AIN3 Inputs //Scanning only used for Sequential Sampling. /*~~~~~~~~~~~~~~ Set up Timer3 to trigger for ADC1 Conversions ~~~~~~~~~~~~~*/ TMR3 = 0x0000; PR3 = 4999; //Trigger ADC1 every 378.7 micro seconds IFS0bits.T3IF = 0; //Clear the Timer3 Interrupt Flag IEC0bits.T3IE = 0; //Disable Timer3 interrupt T3CONbits.TON = 1; //Start Timer3 /*~~~~~~~~~~~~Set up DMA Chan5 for Peripheral Indirect Addressing~~~~~~~~~~~*/ DMA5CONbits.AMODE = 2; //Peripheral Indirect Addressing Mode DMA5CONbits.MODE = 2; //Continous, Ping-Pong Modes enabled. (Allows for bufferA to be processed by cpu while //bufferB is bieng used by DMA DMA5PAD = (volatile unsigned int)&ADC1BUF0; //Point DMA to ADC1BUF0 DMA5CNT = 31; //Transfer N+1 Number of requests before data block transfer is considered complete.
Page 85
DMA5REQ = 13; //Assigns the peripher IRQ to DMA Channel 5 DMA5STA = __builtin_dmaoffset(BufferA); //Offset DMA5STA Address Register with BufferA DMA5STB = __builtin_dmaoffset(BufferB); //Offset DMA5STB Address Register with BufferB IFS3bits.DMA5IF = 0; //Clear the DMA interrupt flag bit IEC3bits.DMA5IE = 1; //Enables DMA Channel 5 Interrupt when Block transfer is complete. IPC15bits.DMA5IP = 7; //DMA highest priority. //DMA5CONbits.HALF = 0; //Interrupt initaited when all the data has been moved. (Defaults to 0). DMA5CONbits.CHEN = 1; //Enable DMA Channel 5 AD1CON1bits.ADDMABM = 0; //DMA buffers are build in scatter/gather mode AD1CON2bits.SMPI = 3; //4 ADC Buffers AD1CON4bits.DMABL = 3; //Each buffer contains 8 words/16 bytes IFS0bits.AD1IF = 0; //Clear the A/D Interrupt Flag bit IEC0bits.AD1IE = 0; //Do not Enable A/D Interrupt AD1CON1bits.ADON = 1; //Turn on the A/D Converter AD1PCFGLbits.PCFG0 = 1; AD1PCFGLbits.PCFG1 = 0; AD1PCFGLbits.PCFG2 = 0; AD1PCFGLbits.PCFG3 = 0; void Uart_Config(void) /*~~~~~~~~~~~~~~~~~~~~~ Set up Uart1 for RP6 Transmit ~~~~~~~~~~~~~~~~~~~~~~~*/ RPOR3bits.RP6R = 3; //map U1Tx to RP6 U1MODEbits.STSEL = 0; //1 stop Bit U1MODEbits.PDSEL = 0; //8 data bits, No Parity U1MODEbits.ABAUD = 0; //Auto Baud Disabled U1MODEbits.BRGH = 0; //Low speed mode... Aribitrary since we are not recieving any data. U1BRG = BRGVAL; //BAUD Rate setting for 19200
U1STAbits.UTXISEL0 = 0; //Interrupt after one TX character is transmitted U1STAbits.UTXISEL1 = 0; U1STAbits.UTXINV = 1; //xor bits with 1; IEC0bits.U1TXIE = 1; //Enable UART TX interrupt U1MODEbits.UARTEN = 1; //Enable UART U1STAbits.UTXEN = 1; //Enable UART TX for(delayU1 = 0; delayU1 < 5178; delayU1++); //Wait 104 microSeconds to transmit first symbol (Delay required for UART) void FrequencyCount_Config(void) /*~~~~~~~~~~~~~~ Set up Timer1 to trigger for Frequency Counter ~~~~~~~~~~~~~*/ T1CONbits.TON = 0; //Stop any Timer1 operation T1CONbits.TCS = 0; //Select internal instruction cycle clock T1CONbits.TGATE = 0; //Disable gated timer mode T1CONbits.TCKPS = 0; //Select 1:1 prescaler TMR1 = 0x0000; //Clear timer register PR1 = 0x0032; //load period value IFS0bits.T1IF = 0; //Clear timer interrupt flag IEC0bits.T1IE = 1; //Enable timer1 interrupt T1CONbits.TON = 1; //Start Timer /*~~~~~~~~~~~~~~ Set up Timer4 & Timer5 to trigger for Frequency Counter ~~~~*/ T5CONbits.TON = 0; //Stop any timer5 operation T4CONbits.TON = 0; //Stop any timer4 operation T4CONbits.T32 = 1; //Enable 32-bit timer mode (Timer4 Least Significant) T4CONbits.TCS = 0; //Select internal instruction cycle clock T4CONbits.TGATE = 0; //Disable gated timer mode T4CONbits.TCKPS = 3; //Select 1:256 prescaler IFS1bits.T5IF = 0; //Clear timer interrupt flag IEC1bits.T5IE = 1; //Enable timer1 interrupt void Init_Screen(void) if(screen_Init == 0) U1TXREG = 0xFE; screen_Init = 1; else if(screen_Init == 1) U1TXREG = 0x58; screen_Init = 0; screen_Toggle = 1; void Write_Speed(void) if(write_Speed == 0) U1TXREG = 0xFE; write_Speed = 1; else if(write_Speed == 1) U1TXREG = 0x48; write_Speed = 2; else if(write_Speed == 2) U1TXREG = 'S'; write_Speed = 3; else if(write_Speed == 3) U1TXREG = 'p'; write_Speed = 4; else if(write_Speed == 4) U1TXREG = 'e'; write_Speed = 5; else if(write_Speed == 5) U1TXREG = 'e'; write_Speed = 6; else if(write_Speed == 6) U1TXREG = 'd'; write_Speed = 7; else if(write_Speed == 7) U1TXREG = ' '; write_Speed = 8; else if(write_Speed == 8) U1TXREG = 0xFE; write_Speed = 9; else if(write_Speed == 9) U1TXREG = 0x47; write_Speed = 10; else if(write_Speed == 10) U1TXREG = 0x09; write_Speed = 11; else if(write_Speed == 11) U1TXREG = 0x01; write_Speed = 12; else if(write_Speed == 12) U1TXREG = ' '; write_Speed = 13;
Page 86
else if(write_Speed == 13) U1TXREG = ' '; write_Speed = 14; else if(write_Speed == 14) U1TXREG = ' '; write_Speed = 15; else if(write_Speed == 15) U1TXREG = ' '; write_Speed = 16; else if(write_Speed == 16) U1TXREG = ' '; write_Speed = 17; else if(write_Speed == 17) U1TXREG = ' '; write_Speed = 18; else if(write_Speed == 18) U1TXREG = ' '; write_Speed = 19; else if(write_Speed == 19) U1TXREG = ' '; write_Speed = 0; screen_Toggle = 2; void Write_Batt(void) if(write_Batt == 0) U1TXREG = 0xFE; write_Batt = 1; else if(write_Batt == 1) U1TXREG = 0x47; write_Batt = 2; else if(write_Batt == 2) U1TXREG = 0x01;
write_Batt = 3; else if(write_Batt == 3) U1TXREG = 0x02; write_Batt = 4; else if(write_Batt == 4) U1TXREG = 'B'; write_Batt = 5; else if(write_Batt == 5) U1TXREG = 'a'; write_Batt = 6; else if(write_Batt == 6) U1TXREG = 't'; write_Batt = 7; else if(write_Batt == 7) U1TXREG = 't'; write_Batt = 8; else if(write_Batt == 8) U1TXREG = 'e'; write_Batt = 9; else if(write_Batt == 9) U1TXREG = 'r'; write_Batt = 10; else if(write_Batt == 10) U1TXREG = 'y'; write_Batt = 11; else if(write_Batt == 11) U1TXREG = ' '; write_Batt = 12; else if(write_Batt == 12) U1TXREG = 0xFE; write_Batt = 13; else if(write_Batt == 13) U1TXREG = 0x47; write_Batt = 14; else if(write_Batt == 14) U1TXREG = 0x0D; write_Batt = 15; else if(write_Batt == 15) U1TXREG = 0x02; write_Batt = 16; else if(write_Batt == 16) U1TXREG = ' '; write_Batt = 17; else if(write_Batt == 17) U1TXREG = ' '; write_Batt = 18; else if(write_Batt == 18) U1TXREG = ' '; write_Batt = 19; else if(write_Batt == 19) U1TXREG = ' '; write_Batt = 0; screen_Toggle = 3; void Update_Data(void) //start at 1,7 for speed //start at 2,9 for batt if(update_Data == 0) U1TXREG = 0xFE; update_Data = 1; else if(update_Data == 1) U1TXREG = 0x47; update_Data = 2; else if(update_Data == 2) U1TXREG = 0x07; update_Data = 3; else if(update_Data == 3) U1TXREG = 0x01; sprintf(buffer, "%d", wheelFrequencyMPH); if (wheelFrequencyMPH < 10) buffer[1] = ' '; wheelF = &buffer[0]; update_Data = 4; else if(update_Data == 4) if((*wheelF) != 0) U1TXREG = *wheelF++; if((*wheelF) == 0) update_Data = 5; else U1TXREG = '0'; update_Data = 5; else if(update_Data == 5) U1TXREG = 0xFE; update_Data = 6; else if(update_Data == 6) U1TXREG = 0x47;
Page 87
update_Data = 7; else if(update_Data == 7) U1TXREG = 0x09; update_Data = 8; else if(update_Data == 8) U1TXREG = 0x02; update_Data = 9; else if(update_Data == 9) if(an0_SAMP >= 16448) //send 100 if(percentData == 0) U1TXREG = '1'; percentData = 1; else if(percentData == 1) U1TXREG = '0'; percentData = 2; else if(percentData == 2) U1TXREG = '0'; percentData = 0; update_Data = 10; else if((an0_SAMP >= 11712) && (an0_SAMP < 16448)) //send 80//11712 if(percentData == 0) U1TXREG = '8'; percentData = 1; else if(percentData == 1) U1TXREG = '0'; percentData = 2; else if(percentData == 2) U1TXREG = ' '; percentData = 0; update_Data = 10; else if((an0_SAMP >= 11392) && (an0_SAMP < 11712)) //send 60//11392
if(percentData == 0) U1TXREG = '6'; percentData = 1; else if(percentData == 1) U1TXREG = '0'; percentData = 2; else if(percentData == 2) U1TXREG = ' '; percentData = 0; update_Data = 10; else if((an0_SAMP >= 11008) && (an0_SAMP < 11392)) //send 40//11008 if(percentData == 0) U1TXREG = '4'; percentData = 1; else if(percentData == 1) U1TXREG = '0'; percentData = 2; else if(percentData == 2) U1TXREG = ' '; percentData = 0; update_Data = 10; else if((an0_SAMP >= 10172) && (an0_SAMP < 11008)) //send 20//10172 if(percentData == 0) U1TXREG = '2'; percentData = 1; else if(percentData == 1) U1TXREG = '0'; percentData = 2; else if(percentData == 2) U1TXREG = ' '; percentData = 0; update_Data = 10; else if((an0_SAMP >= 4096) && (an0_SAMP < 10172)) //send 0 if(percentData == 0) U1TXREG = '0'; percentData = 1; else if(percentData == 1) U1TXREG = ' '; percentData = 2; else if(percentData == 2) U1TXREG = ' '; percentData = 0; update_Data = 10; else if(an0_SAMP < 4096) P1OVDCON = 0x0000; else if(update_Data == 10) U1TXREG = '%'; update_Data = 0; screen_Toggle = 1;