ArmandMollaGarciaTFG v5

Download as pdf or txt
Download as pdf or txt
You are on page 1of 89

3Cat3 3-axes ADCS using Reaction

Wheels and Magnetorquers

A Degree’s Thesis submitted to the


Escola Tècnica Superior d’Enginyeria de Telecomunicació de Barcelona
Universitat Politècnica de Catalunya
by
Armand Mollà Garcia

In partial fulfilment
of the requirements for the degree in
ELECTRONIC SYSTEMS ENGINEERING

Advisor: Professor Adriano Camps

June 27, 2016


Abstract

Standardized CubeSats, with a mass between 1 and 10 Kg, and a volume defined by the
number of 10x10x10 cm3 cubic units that implement it, need compact and effective attitude
determination and control systems. For fast maneuvers, a reaction wheels system is the best
option. In the near future, University’s own CubeSat program with 3 Cat3 mission, aims to
use this subsystem. The objective of this thesis is to continue developing this attitude control
system implementing the control algorithms for controlling the motors. Most of the development
has been carried out using a test board from Texas Instruments before experimenting with
the final hardware. The boards which control the motors in the satellite are based on the
development board and the motors, from Maxon motors, are special for being able to work in
vacuum conditions. A control system with speed feedback from Hall effect sensors and current
sensors has been developed. FOC has been the algorithm used, with the aim of achieving a
smooth and precise performance. All the results have been obtained evaluating the motors’
behaviour under speed and acceleration tests. All motors and boards have been tested under
the same conditions to simulate slow speed variations, similar to the ones necessary to make
the satellite rotate in space.

i
Resumen

Los CubeSats estandarizados, con una masa de entre 1 y 10 Kg, y un volumen definido por el
número de unidades cúbicas de 10x10x10 cm3 que lo forman, necesitan sistemas de control y
determinación de actitud compactos y efectivos. Para maniobras rápidas, un sistema basado
en Reaction Wheels es la mejor opción. En el futuro, el programa de CubeSats propio de la
universidad, con la misión 3 Cat-3, pretende usar este subsistema. El objetivo de esta tesis
es continuar con el desarrollo de este sistema de control de actitud implementando los algo-
ritmos necesarios para controlar los motores. Gran parte del desarrollo se ha llevado a cabo
usando una placa de desarrollo de Texas Instruments, antes de experimentar con el hardware
definitivo. Las placas que controlan los motores en el satélite están basadas en la placa de
desarrollo y, los motores, de Maxon motors, son especı́ficos para poder funcionar en el vacı́o.
Un sistema de control con realimentación de la velocidad calculada usando sondas Hall y sen-
sores de corriente ha sido desarrollado. Se ha utilizado el algoritmo denominado FOC para
lograr una mayor suavidad y precisión de funcionamiento. Todos los resultados se han obtenido
evaluando el comportamiento de los motores bajo test de velocidad y aceleración. Todos los
motores y placas se han testeado bajo las mismas condiciones para simular variaciones lentas
de velocidad, similares a las necesarias para hacer rotar el satélite en el espacio.

ii
Resum

Els CubeSats estandarditzats, amb una massa d’entre 1 i 10 Kg, i un volum definit pel nombre
d’unitats cúbiques de 10x10x10 cm3 que el formen, necessiten sistemes de control i determi-
nació d’actitud compactes i eficaços. Per maniobres ràpides, un sistema basat en Reaction
Wheels és la millor opció. En el futur, el programa de CubeSats propi de la universitat, amb
la missió 3 Cat-3, pretén utilitzar aquest subsistema. L’objectiu d’aquest tesi és continuar amb
el desenvolupament d’aquest sistema de control d’actitud implementant els algorismes nec-
essaris per controlar els motors. Gran part del desenvolupament s’ha dut a terme utilitzant
una placa de desenvolupament de Texas Instruments, abans d’experimentar amb el hardware
definitiu. Les plaques que controlen els motors en el satèl•lit estan basades en la placa de
desenvolupament i, els motors, de Maxon motors, són especı́fics per poder funcionar en el
buit. Un sistema de control amb realimentació de la velocitat calculada utilitzant sondes Hall i
sensors de corrent ha estat desenvolupat. S’ha utilitzat l’algorisme denominat FOC per acon-
seguir una major suavitat i precisió de funcionament. Tots els resultats s’han obtingut avaluant
el comportament dels motors sota tests de velocitat i acceleració. Tots els motors i plaques
s’han testejat sota les mateixes condicions per simular variacions lentes de velocitat, similars
a les necessàries per fer rotar el satèl•lit a l’espai.

iii
To everyone who has supported me along this process.

iv
Acknowledgements

I am very grateful for the opportunity I have been given to work in the 3 Cat-3 project in the
NanoSat Lab. I want to thank my advisor Professor Adriano José Camps Carmona and all the
laboratory members. Specially for the wide knowledge I have achieved and the challenging
experience that has made me give my best.
Special thanks to former students Mr. Albert Bolet and Mr. Jordi Macià for their invaluable
help and advice regarding the Reaction Wheels system they started developing.
Finally, thanks to all the 3 Cat team members for their support when any difficulty came up
and, of course, for the great working atmosphere in the NanoSat Lab.
Revision history and approval record

Revision Date Purpose


0 16/05/2016 Document creation
1 30/05/2016 Project Advisor first revision
2 20/06/2016 Project Advisor second revision
3 26/06/2016 Project Advisor final revision

Document Distribution List


Name e-mail
Armand Mollà Garcia [email protected]
Adriano José Camps Carmona [email protected]

Written by: Armand Mollà Garcia Reviewed by: Adriano Camps Carmona
Date 16/05/2016 Date 26/06/2016
Name Armand Mollà Garcia Name Adriano José Camps Carmona
Position Project Author Position Project Advisor

vi
Contents

List of Figures ix

List of Tables xi

List of Acronyms xi

1 Introduction 1

2 State of the art of Reaction Wheels 3


2.1 BLDC Motors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.2 Hall effect sensors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.3 Clarke and Park transforms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.4 BLDC motor control implementations . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.4.1 PID controllers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.4.2 Field Oriented Control (FOC) . . . . . . . . . . . . . . . . . . . . . . . . . 8

3 Methodology and Project Development 12


3.1 System overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
3.1.1 RW as part of the ADCS . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
3.1.1.1 General overview . . . . . . . . . . . . . . . . . . . . . . . . . . 12
3.1.1.2 The Masterboard and its link with the RW . . . . . . . . . . . . . 13
3.1.2 RW functioning and their interaction with the magnetorquers . . . . . . . 14
3.1.2.1 RW actions and behaviour . . . . . . . . . . . . . . . . . . . . . 14
3.1.2.2 Momentum unloading . . . . . . . . . . . . . . . . . . . . . . . . 15
3.2 Development hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
3.2.1 F28069M Microcontroller . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
3.2.2 TI DRV8312 Motor Driver . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3.2.3 Motor Anaheim BLY17 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3.3 Satellite final hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3.3.1 Motor controllers PCBs . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.3.2 Maxon EC32 Flat and flywheel . . . . . . . . . . . . . . . . . . . . . . . . 17
3.3.3 Hardware general configuration . . . . . . . . . . . . . . . . . . . . . . . . 18
3.4 Final implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
3.4.1 Software design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
3.4.2 PCBs modifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
3.4.3 How to command the motor controllers . . . . . . . . . . . . . . . . . . . 21

vii
4 Results 23
4.1 Development kit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
4.1.1 Kit parameters identification . . . . . . . . . . . . . . . . . . . . . . . . . . 23
4.1.2 Performance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
4.2 Satellite motors and PCBs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
4.2.1 Maxon motors’ parameters identification . . . . . . . . . . . . . . . . . . . 25
4.2.2 Performance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

5 Budget 29

6 Conclusions and Future Development 30

Bibliography 32

A Critical Design Review Document 34

B PCBs schematics 39
B.1 Motor PCBs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
B.2 FTDI board . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39

C Scilab code 43

D F28069M Code 45
D.1 MAIN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
D.1.1 main.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
D.1.2 main.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
D.2 user.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
D.3 hal.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65

E Results Complement 68
E.1 Inertia units transformation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
E.2 Inertia histograms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69

F Anaheim BLY17 motor datasheet 71

G Maxon EC32 Flat motor datasheet 75

viii
List of Figures

2.1 Maryland Aerospace ADCS module including RW with a price of 25.000 US


dollars [1] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.2 Aspect of UPC nanosat lab RW system . . . . . . . . . . . . . . . . . . . . . . 4
2.3 A three-phase synchronous motor with a one permanent magnet pair pole rotor
[2] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.4 A three-phase inverter [2] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.5 Hall effect sensors output signals . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.6 Reference frames transformations [3] . . . . . . . . . . . . . . . . . . . . . . . . 7
2.7 Block diagram for a closed speed loop with PI controller [2] . . . . . . . . . . . 8
2.8 FOC flow diagram overview [4] . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.9 Insta-SPIN MOTION Control with Mechanical Sensor and and FAST Software
Sensor [5] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2.10 Applied Torque Disturbance Comparison . . . . . . . . . . . . . . . . . . . . . . 11
2.11 SpinTAC Move Curve Descriptions . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.12 S-curve representation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

3.1 Block diagram of the entire Attitude Determination and Control System (ADCS)
system. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.2 Serial Peripheral Interface (SPI) link between motor control boards and Mas-
terboard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
3.3 Variation of the angular velocity of the Reaction Wheels (RW) starting at 0 rpm
-simulated with Matlab by Aleix Calderón in his degree thesis-. . . . . . . . . . 14
3.4 Development DRV8312-C2-KIT by Texas Instruments [6] . . . . . . . . . . . . . 16
3.5 Final Printed Circuit Board (PCB) design (a) and the dimensions reduction it
supposed (b) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.6 Maxon EC32 Flat, the flywheel currently used and a flywheel design proposal . 17
3.7 Preliminary RW system design . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
3.8 Flow diagram of the software’s functioning mechanism . . . . . . . . . . . . . . 19
3.9 Connections done to simulate a low resolution encoder . . . . . . . . . . . . . . 20
3.10 Hardware modifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
3.11 Different speed (top) and acceleration (middle) references and the motor’s
speed evolution (bottom). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

4.1 Slow speed progression at 1rpm/s . . . . . . . . . . . . . . . . . . . . . . . . . 24


4.2 Speed progression with different accelerations . . . . . . . . . . . . . . . . . . 24
4.3 Slow speed progression at 1.5rpm/s . . . . . . . . . . . . . . . . . . . . . . . . 26

ix
4.4 Speed variations with different successive positive and negative accelerations . 26
4.5 Speed variation from 2000 Revolutions Per Minute (RPM)s to 100 RPMs and
fixed speed zoomed areas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
4.6 Speed variation from -1000 to 1000 RPMs and the central area zoomed. . . . . 28

6.1 Proposed design for the RW system . . . . . . . . . . . . . . . . . . . . . . . . 31

B.1 Socket connector and power circuit . . . . . . . . . . . . . . . . . . . . . . . . . 40


B.2 DRV8312 driver and motor current/voltage sensing . . . . . . . . . . . . . . . . 41
B.3 Micro Controller Unit (MCU) connections . . . . . . . . . . . . . . . . . . . . . . 41
B.4 PCB layout -top layer- . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
B.5 Future Technology Devices International (FTDI) board layout -top layer- . . . . 42

E.1 BLY17 inertia values histogram . . . . . . . . . . . . . . . . . . . . . . . . . . . 69


E.2 EC32Flat 1 inertia values histogram . . . . . . . . . . . . . . . . . . . . . . . . 69
E.3 EC32Flat 2 inertia values histogram . . . . . . . . . . . . . . . . . . . . . . . . 70
E.4 EC32Flat 3 inertia values histogram . . . . . . . . . . . . . . . . . . . . . . . . 70

x
List of Tables

4.1 Kit parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23


4.2 Maxon EC32Flat motors’ parameters . . . . . . . . . . . . . . . . . . . . . . . . . 25

5.1 Detailed project cost . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29

E.1 BLY17 inertia values table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69


E.2 EC32Flat 1 inertia values table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
E.3 EC32Flat 2 inertia values table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
E.4 EC32Flat 3 inertia values table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70

xi
Acronyms list

AC Alternating Current IC Integrated Circuit

ADC Analog to Digital Converter LED Light Emitting Diode

ADCS Attitude Determination and Control LEO Low Earth Orbit


System
MCU Micro Controller Unit
AEP Advanced Engineering Project
PID Proportional Integrative Derivative
BLDC BrushLess Direct Current
PCB Printed Circuit Board
DC Direct Current
PWM Pulse Width Modulation
EPS Electrical Power Subsystem
QEP Enhanced Quadrature Encoder Pulse
FAST Flux Angle Speed Torque
RPM Revolutions Per Minute
FOC Field Oriented Control
RW Reaction Wheels
FTDI Future Technology Devices Interna-
tional SI International System of Units

GPIO General Purpose Input/Output SPI Serial Peripheral Interface

HAL Hardware Abstraction Layer UPC Universitat Politècnica de Catalunya

I2C Inter-Integrated Circuit USB Universal Serial Bus

xii
Chapter 1

Introduction

The ADCS in a satellite is crucial to guarantee a proper orientation towards a defined target.
A wide range of payloads and subsystems have this requirement, e.g. Earth remote sensors,
communication systems, solar panels orientation and camera pointing.
This system can be divided in two: attitude determination and attitude control, which need
to work perfectly together.

1. Attitude determination is the part in charge of acknowledging the satellites orientation with
a given coordinate system, it is the sensing part of the system. Some sensors typically
used are gyroscopes, accelerometers, Sun sensors, Earth sensors and star trackers.

2. Attitude control is the block of actuators that allow the satellite to change its attitude using
the feedback from the sensors. Depending on the end application and payloads require-
ments, the actuators are selected as all of them have pros and cons. When high pointing
accuracy is required as in 3 Cat-3 (medium resolution camera), three-axes active stabi-
lization and star trackers is the selected scheme. In 3 Cat-2, the payload is an antenna
and the actuators are magnetorquers.

The 3 Cat-3 satellite is a 6 unit nano-satellite currently being developed at the Universitat
Politècnica de Catalunya (UPC) NanoSat Lab for an Earth observation mission supported by
the Institut Cartogràfic i Geològic de Catalunya and the Institute of Space Studies of Catalunya.
The payload consists of a powerful camera that needs precise pointing, which leads us to
pursue an accurate ADCS with magnetorquers and RW.
3 Cat-1 and 3 Cat-2 are the two previous missions developed at the UPC NanoSat Lab. Both

projects have met an end and will be launched on July 2016. These satellites do not have a
RW subsystem, they only include magnetorquers as the requirements for both missions have
not made it mandatory. As a faster manoeuvring of the satellite is desired for 3 Cat-3, the RW
are a must.
The purpose of this thesis is to implement and test the control software of the RW brushless
DC motors assuring the subsystem fulfils the requirements to guarantee a proper operation
when having to interact with the magnetorquers and the attitude determination systems. The
inclusion of RW is going to be one of the major improvements in the 3 Cat-3 CubeSat.
A huge work had been previously done by former degree thesis students and the hardware

1
of the RW and its configuration was already established. Albert Bolet and Jordi Macià were in
charge of starting the development and designing the hardware respectively.
The remaining part to complete the subsystem was the accurate control of the motor’s
torque and speed as the system is based on the Angular Momentum Conservation principle,
which states that the total angular momentum of a system is constant – if no external torque is
applied -.
The design developed in this degree thesis needs to fulfil the requirements listed below.

Project Requirements

• Constant speed feedback in order to constantly supervise the motor behaviour and cor-
rect the possible errors with celerity. The control loop needs to run at least at 1000 Hz.

• Speed sensing using current sensors as well as Hall effect sensors for redundancy pur-
poses. The maximum relative error needs to be as low as possible, a 5% relative error is
acceptable.

• Smooth speed change -acceleration- as it is directly related to the torque given by the
motor and the flywheel, which is the most important parameter to control. The changes
between different acceleration commands need to be instantaneous.

• Use of Maxon EC32 flat motors and the hardware designed by Jordi Macià with its MCU
and motor driver while correctly identifying all the parameters needed.

• Follow the system configuration initially defined by Albert Bolet in his degree thesis, where
a masterboard gives torque orders to the motors according to calculations with the attitude
determination data and what the satellite is wanted to do.

• The RW system needs to be able to understand acceleration or torque commands, which


are closely related by the inertia of the motor as a constant.

The idea at the beginning of the project was to develop the motor control, redesign the
masterboard -which decides the torques needed from each motor through specific algorithms-
and start implementing some these algorithms. The motor control has actually occupied most
of the time, and the development of the algorithms for the attitude control has now become
part of another student‘s degree thesis. Redesigning the masterboard as a reduced size PCB,
was left apart as it was decided that a much versatile ADCS masterboard should be designed,
which is a much more complex task.
During the project development, a continuous supervision of the project advisor, Professor
Adriano José Camps has been performed. Also, three specific meetings have been done to
check the project development status. Detailed work plan, tasks, milestones and Gantt diagram
can be found in the Critical Design Review document attached in Appendix A.

2
Chapter 2

State of the art of Reaction Wheels

One of the main problems of CubeSat nanosatellites is the attitude control, which is mainly
done using a passive control - magnets - or magnetorquers - coils - because they are cheap
and have low consumption. If the CubeSat mission requires a quick attitude maneuver, these
systems cannot provide enough torque to rotate the spacecraft quickly. For that reason, some
universities and also companies have developed or are developing RW systems. Some com-
panies (e.g. Clyde Space, Blue Canyon Technologies, Maryland Aerospace...) sell finished
systems at very high prices, and that is the reason why some universities opt to build them
themselves.

Figure 2.1: Maryland Aerospace ADCS module including RW with a price of 25.000 US dollars [1]

Thrusters are also common actuators when high torques are required over short periods of
time. They can be easily implemented, but they require fuel and their life is limited.
To build a RW system, normally four wheels are used in order to have a redundant one,
but in a CubeSat, where volume is an important restriction, three wheels -one per each of the
three dimensions- are enough. The motors used, due to its high efficiency and cleanness, are
BrushLess Direct Current (BLDC) motors. In addition, they must be prepared to work in vacuum
conditions and need Braycode vacuum greases. The sensors used for the speed feedback can
be either Hall effect sensors or quadrature encoders.
3 Cat-3 mission is going to use this technology because the performance required is crucial.

It will also be the first UPC nanosat lab test of their new attitude control system. Our RW system
is not still optimized neither in power consumption nor in volume, and it occupies almost one

3
unit of a CubeSat. The masterboard has not yet been integrated with the system.

Figure 2.2: Aspect of UPC nanosat lab RW system

2.1 BLDC Motors

The BLDC motor is an Alternating Current (AC) synchronous motor with permanent magnets
on the rotor -moving part-, and windings on the stator -fixed part-. Permanent magnets create
the rotor flux and the energized stator windings create electromagnet poles. The rotor is at-
tracted by the energized stator phase. By using the appropriate sequence to supply the stator
phases, a rotation is induced to the rotor as it chases after the electromagnet poles. This is the
fundamental action used in synchronous permanent magnet motor.

Figure 2.3: A three-phase synchronous motor with a one permanent magnet pair pole rotor [2]

On the stator side, three-phase motors are the most common ones. These offer a good
compromise between precise control and the complexity of the power electronics required to
control the three stator currents. The more poles in the rotor, the more precise its control will
be, but the manufacturing costs raise and there is also a point where the torque no longer
increases.

4
BLDC motors are one of the two types of permanent magnet synchronous motors and the
one we have particular interest in. Its differential characteristic is that it is fed with direct Pulse
Width Modulation (PWM) currents signals through a three phase inverter, not with sinusoidal
currents. As a consequence, its control becomes simpler. Fig. 2.4 shows the scheme of the
inverter.

Figure 2.4: A three-phase inverter [2]

2.2 Hall effect sensors

One of the most common, cheap, easy-to-use, and available sensors used are the Hall effect
sensors [7]. Normally with three of them it is possible to calculate relatively well the speed of
the motor -when more precision is needed, the sensors used are encoders, which can detect
thousands of different positions in a single rotation-. Its behaviour is easy to understand and it
can be observed in Fig. 2.5.

Figure 2.5: Hall effect sensors output signals

The Hall sensors generate a pulse every time the rotor passes in front of them and the
number of pole pairs of the motor corresponds to the number of pulses generated by each
sensor in one complete rotation of the motor. In our case, both the motor Nema 17 [F] from

5
the Texas Instruments kit and the MaxonEC32flat [G] enclose three Hall sensors and have four
pole pairs.
In a closed-loop control of a motor, the speed calculation is done indirectly if only current
sensors are used. That means that irregularities in the currents due to undesired inductions or
unknown sources can vary this measurement. As a consequence, the control feedback could
have a bias or even state the motor is spinning when it is actually stopped. As a satellite’s
hardware cannot be modified once it is launched, and these phenomenons can not be avoided,
direct measure sensors are needed.

2.3 Clarke and Park transforms

When working with three phase motors, there is a mathematical background which is used in
various control schemes [8]. Some transforms are performed in order to have a simpler system
of variables, and to be able to easily control the motor’s behaviour, in this particular case, the
motor’s torque. This is the case of the Field Oriented Control (FOC) control algorithm.
The electric torque of an AC induction motor can be described by the interaction between
the rotor currents and the flux wave resulting from the stator currents induction.
The Clarke transform uses the three-phase currents ia , ib and ic to calculate currents in the
two-phase orthogonal stator axis: iα and iβ . These two currents in the fixed coordinate plane
are transformed to the isd and isq currents components in the d,q rotating reference frame with
the Park transform. See Fig. 2.6 for a better understanding of the frames transformations.
Currents isd , isq and the instantaneous flux angle ρ, calculated by the motor flux model, are
used to calculate the electric torque of an AC induction motor.
The Clarke transform converts the three-phase system into a two-phase orthogonal system,
its mathematical description is the following:

2 2
iα = · ia − (ib − ic ), (2.1)
3 3
2
iβ = √ (ib − ic ), (2.2)
3
2
io = (ia + ib + ic ), (2.3)
3

where iα and iβ are the components in an orthogonal reference frame and io is the homopo-
lar component of the system. Considering the particular case with iα superposed with ia and
ia + ib + ic = 0, the transformation can be done as:

iα = ia , (2.4)
1 2
iβ = √ ia + √ ib , (2.5)
3 3
ia + ib + ic = 0. (2.6)

6
The Park transform rotates the previous frame representation over an angle θ according to
the formulas:

isd = iα · cos(θ) + iβ · sin(θ), (2.7)


isq = −iα · sin(θ) + iβ · cos(θ). (2.8)

The inverse Park and Clarke transforms are also used. Reversing the process, the formulas
are the following:

iα = isd · cos(θ) − isq · sin(θ), (2.9)


iβ = isd · sin(θ) + isq · cos(θ), (2.10)

ia = iα , (2.11)

1 3
ib = − iα + iβ , (2.12)
2 √2
1 3
ib = − iα − iβ . (2.13)
2 2

Figure 2.6: Reference frames transformations [3]

These mathematics are already pre-implemented in the F28069M MCU, as well as Proportional
Integrative Derivative (PID) controllers and other functionalities. This lets the user benefiting
from it by connecting the different blocks but not having to build them from scratch.

2.4 BLDC motor control implementations

There are different ways to achieve the desired results when talking about a motor’s perfor-
mance. The implementation of the control is important depending on the target behaviour.
For this project, with Texas Instruments’ hardware and software used, some options with pre-
implemented methods have been useful. Various techniques have been implemented although
only one has met the specifications.

7
2.4.1 PID controllers

The first attempt to control the motors was done with the simplest algorithm: a speed PID
controller, and a current PID controller. They were tested separately and finally, combined
together.
The control had a speed feedback from three Hall effect sensors. Fig. 2.7 shows the block
diagram of a PI speed controller. Note that this configuration does not integrate the Clarke and
Park transform modules, as it does not use them.

Figure 2.7: Block diagram for a closed speed loop with PI controller [2]

With the feedback from the sensors and a reference set by the user, the software controls
six PWM which drive the motor’s phases through the three phase inverter.
In the case of a current controller, the scheme is the same, but the feedback is performed
using the current sensors of each phase. When these feedbacks are put together, both the
current and the rate of change of the PWM signals can be changed, and the speed and torque
can be controlled.
Due to poor support from the developer -Texas Instruments- and limited knowledge, the mo-
tor did not have a soft behaviour and the acceleration -torque- could not be controlled precisely
when the two controllers were put together. With the availability of other control techniques, it
was left apart.

2.4.2 Field Oriented Control (FOC)

FOC (or vector control) is a more advanced method which uses the Park and Clarke transforms
previously described, converting the three-phase static reference frame of the stator windings,
to the two axes rotating reference frame. [4] This is previously done to the signals being pro-
cessed by the PI controllers. It allows the controller to operate on the resulting vector of the
three phase currents rather than controlling each phase independently. The result is a smoother

8
and accurate control and the elimination of torque ripple.

Figure 2.8: FOC flow diagram overview [4]

The electrical study of the Direct Current (DC) motor shows that the torque produced and
the flux can be independently used. The strength of the field excitation sets the value of the
flux. The key point here is that the windings are managed to keep the flux produced by the
rotor windings orthogonal to the stator field. Then generating a near optimal torque all the time.
According to the electromagnetic laws, the torque produced in the synchronous machine is
equal to vector cross product of the two existing magnetic fields:

~ stator × B
Tem = B ~ rotor , (2.14)

This expression shows that the torque is maximum if the stator and the rotor magnetic fields
are orthogonal. If this condition is ensured all the time, the torque ripple is reduced and a better
dynamic response is obtained. Torque variations increase when the orthogonality is lost.
With decoupled control of the magnetization, the torque producing component of the stator
flux can now be thought of as an independent torque control. To decouple the torque and flux, it
is necessary to use several mathematical transforms, and this is where the microcontrollers add
the most value. With the MCU used in this project, these mathematics are pre-implemented.
This control was also implemented in the RW system and it was able to control speed
and acceleration of the motors, nevertheless, this was accomplished exclusively using current
sensors, and making an estimation of the speed. Hall effect sensors needed to be integrated
with this control to close the feedback loop. Again, due to poor support from the manufacturer
-Texas Instruments- and the complexity of the pre-implemented control software, the integration
of the sensors was not possible.

9
InstaSPIN-MOTIONT M

InstaSPIN-MOTION [5] is the commercial name of a variation of the FOC control, which adds
some possibilities and some improved performance. The possibility of easier integration for
Hall effect sensors has been one of the strong reasons for using it. The kernel of the algorithm
is the same, based on the Clarke and Park transforms. The overview of the complete control
block diagram can be seen in Fig. 2.9.

Figure 2.9: Insta-SPIN MOTION Control with Mechanical Sensor and and FAST Software Sensor [5]

Note that this block diagram is more complex than the two ones previously seen. This
control has the benefits from the FOC, and it achieves even a better adjusting process and
performance. It also allows the use of Hall effect sensors or an encoder -Enhanced Quadrature
Encoder Pulse (QEP) module in the diagram-. The combination of a sensorless and a sensored
control is explained in section 3.4.
Insta-SPIN MOTION has the benefits of using is the Flux Angle Speed Torque (FAST) uni-
fied observer and the SpinTAC. The observer is a block that measures the rotor flux -magnitude,
angle, and speed- as well as the shaft torque in a sensorless FOC system. It provides exhaus-
tive information using the current sensors to have the best sensorless control possible. In ad-
dition, its output angular speed can be easily toggled by the calculation from the speed sensor
-Hall effect sensors or encoder-. SpinTAC ensures optimal performance across dynamic speed
and position ranges, it simplifies the references setting and parameters adjustment stages.
SpinTAC Move generates a profile based on starting velocity or position, desired velocity or
position, and configured system limitations for acceleration and jerk. Jerk represents the rate
of change of acceleration. A larger jerk will increase the acceleration at a faster rate. This can
be configured as desired when having to develop the control algorithms.
Controlling more precisely the torque applied at any instant ensures a better stability of the

10
speed and acceleration. A graph comparing the response of the SpinTAC controller versus a
simple PI controller is shown in Fig. 2.10, as well as the different configurations of SpinTAC in
Fig. 2.11

Figure 2.10: Applied Torque Disturbance Comparison

Figure 2.11: SpinTAC Move Curve Descriptions

The S-curve follows a particular mathematical expression which allows to know exactly how
these variations are made. It is called Sigmoid Curve [9] and it is used to model phenomenons
in a wide range of different fields. Its expression and shape are:

1
S(t) = (2.15)
1 + e−t

Figure 2.12: S-curve representation

Although FAST unified observer is a tool used for sensorless control, it has been useful
for the project development and for the final software implementation. The real benefit of this
control has been an easier integration of the Hall effect sensors.

11
Chapter 3

Methodology and Project


Development

The actions to be taken by the actuators and the hardware used are described in this chapter.
Both are responsible for the requirements and limitations of the project. The development of
the project will also be explained, with the hardware modifications proposed, and the software
developed for the motor controllers.

3.1 System overview

It is important to understand what is going to be around the RW system when having to develop
it. How is it going to be used is also crucial to know to fulfil the requirements. This section will
discuss the functioning of the RW system and its interaction with other parts of the satellite.
Starting from a general point of view and, afterwards, talking about its direct relationship with
the magnetorquers.

3.1.1 RW as part of the ADCS

3.1.1.1 General overview

The RW system is part of a more complex and important part of the satellite, the ADCS, which
encompasses many elements. An overview of the different elements and relationships between
them is made in this section. The block diagram in Fig. 3.1 shows the elements present in the
ADCS system.
The elements in the diagram can be classified in tow groups: the sensors and the actuators.
RW are one of the actuators, together with the magnetorquers. Some of the sensors are still in
development with the aim of having them all ready for the 3 Cat-3 mission.
To make all the parts work together, there is going to be a ”Brain” -an MCU- which is going
to control all the elements and actions performed. It will be in charge of receiving the attitude
commands and, from the information gathered by the sensors, and the torques introduced by
the actuators, give the satellite the right orientation.

12
Figure 3.1: Block diagram of the entire ADCS system.

3.1.1.2 The Masterboard and its link with the RW

The ADCS algorithms are complex and become even more difficult to manage when having
to relate the attitude determination system to the control one as any phenomena need to be
taken into account. The controller in charge of the attitude needs to be capable to assume all
this work. It has to make complex mathematics calculus, be able to implement modules such
as PIDs or PWMs and communicate through different interfaces like SPI or Inter-Integrated
Circuit (I2C). Until now, the MCU used has been a STM32F429 Microcontroller embedded in
the Discovery kit from STMicroelectronics [10].
At the beginning of this thesis, one of the tasks was to redesign the Discovery board to make
it fit into the nanosatellite as it would be the final masterboard used. However, it was left apart
because of various limitations. Together with other members of the laboratory, the decision
was that a new board should be built from scratch. This new board would not be based on
the Discovery kit, but following the CubeSat standard which would include connections and
interfaces for all the sensors and actuators needed. The MCU would also be replaced by a
lower power consumer one and with similar computing capabilities. Regarding all that, the task
became more complex and, perhaps, part of a future project or thesis about ADCS integration.
For the particular case of the RW, the communication with the Masterboard is achieved via
SPI. This bus was chosen by Albert Bolet in his thesis as it is easily configurable and both, the
STM32F429 and the TMSF28069M MCUs supported it. The motor controllers give speed and
acceleration information to the Masterboard and it calculates the error by comparing them to the
reference values calculated, and gives new orders. Each of the three driver boards is identified
by a chip select signal which determines which of them is communicating to the Masterboard.
This part was implemented by Jordi Macià during his bachelor thesis as he was in charge of
upgrading the hardware to a 3-axes system. Fig. 3.2 shows the configuration of the SPI link.

13
Figure 3.2: SPI link between motor control boards and Masterboard

3.1.2 RW functioning and their interaction with the magnetorquers

3.1.2.1 RW actions and behaviour

The RW have to be used in a particular way so as to make the system stable, ensure a secure
operation not damaging other parts and respecting the physic analyses. For 3 Cat-3, reaction
wheels are chosen in front of momentum wheels. Using the same hardware, the difference is
found in its operation [11]. A reaction wheel is spun up or down to create the torque and force
the vehicle to rotate. A momentum wheel is always spinning at a very high speed and that
creates a stabilization of the spacecraft, making it resistant to changing its attitude. Several
problems caused by the momentum bias generated by moving parts rotating at high speeds
appeared in the analysis and the option of momentum wheels was dismissed. This gives some
freedom to the motor control, as it does not have to work at high speeds.
As well as having to change the satellites attitude towards a desired reference, the system
will also have to compensate disturbance torques at every moment and also make the space-
craft rotate at the same rate as it does around the Earth to preserve the nadir pointing. This
means that each wheel has to periodically accelerate and decelerate in a sinusoidal manner
to keep the angular momentum constant in the inertial reference frame as the satellite rotates
around the Earth. The disturbance torques cause an increase of the amplitude of this sinusoid,
which will be discussed later. Fig. 3.3 shows this behaviour along two orbits, having as the
initial pointing the commanded one and without initial angular velocity of the satellite.

Figure 3.3: Variation of the angular velocity of the RW starting at 0 rpm -simulated with Matlab by Aleix
Calderón in his degree thesis-.

14
3.1.2.2 Momentum unloading

Disturbance torques are not periodic and, as a result of this, RW need to be constantly applying
torque to compensate for attitude perturbations. This was seen in the previous section, where
the sinusoidal form of the wheels’ speed tended to increase without limit.
It is crucial to solve this problem as otherwise, once wheels have been accelerated to their
maximum angular velocity, they would not be able to produce torque in that direction any more.
To reduce the angular velocity of the RW while maintaining the attitude, known as momen-
tum unloading or desaturation, an external torque is needed. For spacecraft in Low Earth
Orbit (LEO) such as the 3 Cat-3, magnetorquers are the most common actuator to provide this
external torque.
The magnetorquers apply a torque by generating a magnetic dipole moment proportional
to the error of the angular momentum:

~ = Kdesat L~e × B,
M ~ (3.1)

where Kdesat is a proportionality constant and L~e , the angular momentum error, is the differ-
ence between the commanded angular momentum and the current one. This dipole momentum
interacts with the Earth’s magnetic field to cause a torque

~τdesat = M ~ = −Kdesat B 2 L~⊥ .


~ ×B (3.2)
e

For the RW control algorithm, nothing has to be changed at all. As soon as the magnetor-
quers apply the desaturation torques, the RW act in the opposite direction, keeping the attitude
steady while adjusting their angular velocity. When implementing the control algorithm, the
speed of the RW does not have to go below 200 RPM, which is enough to avoid momentum
bias inaccuracy.

3.2 Development hardware

The hardware used for the development has consisted on a specific kit provided by Texas
Instruments to experiment with three phase motors. It was chosen by Albert Bolet, the former
student who started the design of the RW system. Its different parts are briefly described in
this section.

3.2.1 F28069M Microcontroller

Texas Instruments F28069M [12] is the chosen MCU to control the motors - one dedicated
MCU for each motor because many of General Purpose Input/Output (GPIO) and Analog to
Digital Converter (ADC) are needed for sensing and controlling -. This MCU is provided by
Texas Instruments, and it is specifically designed to work with BLDC motors. The main reasons
for choosing this MCU are that a lot of pre-implemented functions, examples and libraries are

15
Figure 3.4: Development DRV8312-C2-KIT by Texas Instruments [6]

available -e.g. PID, Parke and Clark Transforms, PWM, current sensing-. In addition, it allows
to work with a Quadrature Encoder, which is not exactly what has been used, but it has helped
to the inclusion of a mechanical sensor, making the speed direct measure possible.

3.2.2 TI DRV8312 Motor Driver

This Texas Instruments Integrated Circuit (IC) [13], is a triple half-H bridge driver, and it is
intended to drive a three-phase motor. It provides total control of each individual half-H bridge
- total torque, acceleration and speed control -. The IC has three different pins for each phase,
and three extra pins to control the whole motor. For each phase we can find two pins to drive
the phase, and another to sense the current flowing trough the phase - very useful for FOC.

3.2.3 Motor Anaheim BLY17

The BLY17 [14] is the motor used for experimentation, the one provided in the Texas Instru-
ments development kit. Its manufacturer is Anaheim and the specifications can be found in
Appendix F. A NEMA 17 stepper motor is a stepper motor with a 1.7 x 1.7 inch faceplate. It is
provided with the Hall effect sensors needed for the control desired.
This motor is very different from the ones used in the final design of the RW system but, via
software, it has been possible to identify various motor parameters which has made the control
of different motors simpler. The basis of the control algorithm are the same and the voltages
and currents to be given to the motor only needed to be scaled to work appropriately.

3.3 Satellite final hardware

Apart from the mentioned components used for the development of the control, there is a
hardware which is going to be present in the satellite layout. It performs exactly the same
actions and it has the same components, but in a format that fits in a CubeSat -the requirement
is to fit into one unit of 10x10x10 cm3 - and working under specific conditions.

16
3.3.1 Motor controllers PCBs

The development board used in the project had large dimensions and also was oversized in
amount of connections and features to allow the user experiment under different situations.
Once the RW control application was defined, the parts of the board needed could be selected
to delete the rest. With that, the possibility of building a PCB which could fit in the satellite
appeared. Jordi Macià‘s bachelor thesis consisted of building this board (Fig. 3.5).

(a) Motor controller PCB (b) Inter-comparison

Figure 3.5: Final PCB design (a) and the dimensions reduction it supposed (b)

There was a very intense work on designing it and, of course, soldering all the components
correctly, and finally making it function properly.

3.3.2 Maxon EC32 Flat and flywheel

The EC 32 Flat motors [15] manufactured by Maxon are lubricated with Braycote grease to
be able to work in vacuum. They were chosen by the author of this thesis and Albert Bolet
during the Advanced Engineering Project (AEP) subject one year before the creation of this
document. They are three phase BLDC motors and include Hall effect sensors. Furthermore,
despite being a reduced size motor (diameter of 32 mm) they can provide a large torque (25.1
mN·m). The datasheet and the complete drawings are attached in Appendix G.
To give the system an additional amount of inertia, flywheels had to be attached to the
motors. The ideal flywheel has low mass and high inertia. The current design was done by the
previous student working on the RW and it still needs to be improved. In Fig. 3.6 the current
design and an ideal one, proposed by Aleix Calderón, are shown.

(a) Current flywheel (b) Current flywheel (c) Ideal flywheel de-
sign

Figure 3.6: Maxon EC32 Flat, the flywheel currently used and a flywheel design proposal

17
3.3.3 Hardware general configuration

In his bachelor science thesis, Jordi Macià proposed a configuration to fit the reaction wheels
and their controllers in a 1U cube of the satellite -3 Cat-3 is going to be a 6U satellite-. Fig. 3.7
shows this preliminary design.

Figure 3.7: Preliminary RW system design

The three boards are mounted as a stack and fit perfectly in a 1U. Once mounted, they all
can be programmed at the same time with the SPI bus connected to the top board. The size of
the motors and boards did not make it possible to mount all of them on the same level and use
only a half of the 1U volume.
The supporting parts of the motors were built using a 3D printer and are not the ones for
the space borne version, as this material degrades with time and vibration. They could also be
redesigned in order to occupy less space. In addition, the design has spots of volume unused,
what means it still has to be optimized. The ideal final design would include the reaction wheels,
the magnetorquers and the ADCS masterboard all inside a 1U module. Something ambitious,
but achievable.

3.4 Final implementation

3.4.1 Software design

This final section of the Development chapter is dedicated to the explanation of the final control
software, how the motors’ control has been achieved and the use of the Hall sensors.
As seen in the previous chapter, the control finally used is based on the FOC algorithm
and with the added functionalities available with instaSPIN-MOTION as it also allowed the use
of Hall sensors. However, the control using the Hall sensors at all angular speeds was not
possible. Some problems came up with the motor initial spin-up. To make it work the rotor had
to be forced manually, something which is impractical.
To bypass this issue the idea of mixing two controls came up and became the final solution
indeed. A sensorless control has been used to spin-up the motor and, after a certain number of
RPMs, a flag enables the control change and the Hall effect sensors start doing their function,
as pointed out in section 2.4.2.
When this point is reached, unless the motors need to be stopped for a long time, the open-
loop control never has to be used again. Even if the motor’s rotation has to change its direction,

18
the closed-loop control is able to provide this behaviour. Because of that, the open-loop spin-up
is not critical for the satellite, the only need is to have the motors spinning. In the case some
disturbance appears when starting the motors due to problematic current lectures, this will be
gradually cancelled out. Although, it will not be difficult to balance as the control toggle is set at
100 RPM and there is not enough time to produce fatal disturbances. The flow diagram in Fig.
3.8 shows how the combination of the two controls works.

Figure 3.8: Flow diagram of the software’s functioning mechanism

Note that there are various stages before starting the motor control: the Hardware Abstrac-
tion Layer (HAL) module contains the configuration of the MCU’s pins and must be one of the
first stages. User.h provides the information of the system, such as the motor and board pa-
rameters, and all the definitions that determine the software’s functioning. Finally, modules like
the ADC converters, QEP module and the timers used have to be enabled and linked to com-
plement the HAL initializations. SystemFlag is a binary flag that determines when to start the
control sequence and can also stop it whenever it is needed. The stator resistance is recalcu-
lated instead of being defined in the user.h file because it is easy, and does not need to move
the rotor. The only con is that it takes a few seconds, but it is not critical.
This software has been developed with the Texas Instruments kit and, afterwards, tested
with the ADCS hardware prototype. The solution finally implemented has come after several
failed attempts -only using PID modules, and different closed-loop controls combinations-.
The closed-loop solution has become more complicated to achieve than expected as the
hardware and software from Texas Instruments is not ready to handle Hall effect sensors. Its
mechanical sensor solution is a quadrature encoder -which can provide thousands of different
positions per each spin of the rotor-, and the pre-implemented software solutions are difficult to
modify. Our own boards to control the motors, although they are self-built, they are still based
on the development board design, therefore they perform the same way and support the same
software.

19
The solution has been to use the Hall effect sensors as if they were a low resolution encoder,
then, entering their signals through the QEP module of the microcontroller. This is the reason
for the modifications explained in Section 3.4.2. The signals expected from an encoder have
been simulated connecting two Hall sensors to the A and B inputs -as they are only used to
count the pulses- and the third input -the index signal- could be replaced by software processing
as it is used to reset a counter. Fig. 3.9 compares the Hall sensors signals with the ones
expected from an encoder.

Figure 3.9: Connections done to simulate a low resolution encoder

The remaining task, regarding the software part, is the implementation of the SPI communi-
cation -joining the work performed by Albert Bolet and Jordi Macià with the software developed
in this bachelor’s science thesis-.

3.4.2 PCBs modifications

Due to the need of using the QEP module of the MCU, the motor controller PCBs have been
modified. A beta version of the boards was previously tried in order not to damage the final
ones, but it was unsuccessful and the experimentation had to be done directly with the last
design of the PCBs. As a consequence, modifications in the conditioning part of the Hall effect
sensors’ signals -to enable the MCU read them- have been done, as this part of the boards had
never been tested before. The first modification to be done was to connect two nodes in order
to make the signals go through the desired GPIOs of the microcontroller. The lectures had to be
specifically done through some particular GPIOs and, when tried to change it via software, the
program did not run. Connecting the inputs via hardware has been the only solution possible.
The second modification, also done in the Hall sensors signals conditioning part, has come
from a wrong connected voltage shifter. The PCB is designed so as to use the shifter in the
reverse way, but is is not reversible, the inputs and outputs need to be correctly connected. It
has been removed and fixed with an auxiliary board and cables to switch the connections. Fig.
3.10 shows the aspect of the fix done and the schematic of this last modification [16].

20
(a) Shifter connections chaged (b) Fixed PCB aspect

Figure 3.10: Hardware modifications

As it can be seen, few pads of the IC are used and that is because it was thought to support
the encoder and the Hall effect sensors. The encoder would use three of the input/outputs and
the Hall sensors the other three. As our design simulates an encoder only three pairs of pins
would be used but, as one of the signals is not needed and could be replaced by software,
only two pairs of pins are used. For a future board redesign, a different level shifter with less
channels could be used.

3.4.3 How to command the motor controllers

Once the software has been implemented, the next key point is the way in which it will under-
stand orders and execute them.
The ADCS algorithm determines the required torque of each motor. These values will be
computed these values at a specific rate. This first step is to convert from torque to angular
acceleration, which is easily accomplished by executing some simple conversions.
The next step is that motors need to be constantly accelerating or decelerating and changing
this value -in most of the cases-, but they also require a speed order. The solution is simple:
give a very low speed -it could even be in the opposite direction- when they have to decelerate
or the motors maximum rated speed when they have to accelerate. While these speeds are not
reached, the motors will keep accelerating or decelerating as desired. If it had not been this
way, once the reference speed had been reached, the acceleration command would have been
ignored and no torque would have been applied. If the acceleration command is set to zero,
the speed reference is ignored and the motor stays spinning at the speed it was rotating at the
moment it received the order. Fig.3.11 shows this operation -remember that the acceleration
is directly related to the torque by a constant, the inertia of the rotor-. A real example of this
behaviour can be found in the Results Chapter 4.
The information sent or received through the SPI bus can be configured easily and, when it
has to be finally decided, any possibility will be available. An option would be to send a sign flag
for the torque command and, depending on it, the controllers’ MCUs would know which speed
reference to set.

21
Figure 3.11: Different speed (top) and acceleration (middle) references and the motor’s speed evolution
(bottom).

The vertical lines in Fig.3.11 mark the instants when speed and acceleration references
change. Note how the speed reference makes the function of being the sign of the acceleration.
When acceleration is set to zero the speed is maintained at the value it was. This is how the
designed system works.

22
Chapter 4

Results

In this chapter, the results obtained are shown for both the development kit and the final hard-
ware. The tests have consisted of executing the code and characterizing the motors‘ behaviour.
Obtaining the parameters of the motors and the boards and plotting the speed evolutions on
graphs are the results shown in this chapter. All the motors and PCBs have been tested sep-
arately to independently identify the parameters, and be able to run the same software with
different configurations.

4.1 Development kit

4.1.1 Kit parameters identification

For the software to know the motor and board actually used, their parameters have to be previ-
ously identified. All of them but the inertia are directly calculated by the software. The provider
suggests calculating the inertia of a motor ten times or more and, then, setting as the result the
average value.
Table 4.1: Kit parameters

Motor
Rs [Ω] 0.41712
Lsd [H] 0.0006374
Lsq [H] 0.0006374
Flux [VpHz] 0.035159
Inertia [pu/(pu/s2 )] 0.0135
Board
IA offset [mA] -0.864467204
IB offset [mA] -0.866962671
IC offset [mA] -0.868413985
VA offset [mV] 0.310694873
VB offset [mV] 0.307737291
VC offset [mV] 0.306734324

The procedure to calculate the inertia in International System of Units (SI) units, as well as
the histograms used to identify it, are explained in Appendix E.

23
4.1.2 Performance

The results obtained with the development kit are shown as speed progressions in the following
graphs. Different accelerations as well as very low acceleration progressions have been tested.
These tests have been done acquiring data at a slower sampling rate than the real control does
for convenience. More precisely, one sample per every 500 control loops has been taken.
Figure 4.1 shows the motor accelerating constantly at a certain value. This test has been
done in order to verify that the control is able to make the motor accelerate slowly during a long
period of time. In this case, the acceleration has been set at 1 RPM per second. The cloud of
samples would not have let to appreciate the tiny variations if the test had been shorter. This
noise is treated more specifically in Appendix E. A good behaviour has been obtained as the
samples draw a perfect line from the initial speed value to the final one, which indicates the
acceleration has been correctly maintained during the test.

Figure 4.1: Slow speed progression at 1rpm/s

Figure 4.2 shows also a speed progression, but this time with varying acceleration. The
motor has been commanded to accelerate at different speeds, simulating a possible real sit-
uation. At the moment it receives the orders, the acceleration changes instantaneously with
the software configuration used. The different stages draw perfect lines, which is the behaviour
aimed. While the reference speed is not reached, the motor is able to keep accelerating at the
desired accelerations. For the test, the reference speed has been set to 2000 RPM and the
accelerations have been 2, 4 and 8 RPM/s, in this order.

Figure 4.2: Speed progression with different accelerations

24
4.2 Satellite motors and PCBs

The same process as before has been followed to test the small boards with the Maxon
EC32Flat motors.

4.2.1 Maxon motors’ parameters identification

The parameters are shown in the same format as for the development kit. Table 4.2 contains
the parameters of all three EC32Flat motors.

Table 4.2: Maxon EC32Flat motors’ parameters

Motors 1 2 3
Rs [Ω] 1.837922 1.793522 1.950386
Lsd [H] 0.00072354 0.00074802 0.00072085
Lsq [H] 0.00072354 0.00074802 0.00072085
Flux [VpHz] 0.02203494 0.02208626 0.02181357
Inertia [pu/(pu/s2 )] 0.04144 0.04153 0.04157
Boards 1 2 3
IA offset [mA] -0,8644672 -0,8648289 -0,8681313
IB offset [mA] -0,8669627 -0,8700601 -0,8654397
IC offset [mA] -0,8684139 -0,8664956 -0,8614185
VA offset [mV] 0.3106949 0.3045508 0.3023646
VB offset [mV] 0.3077373 0.3041387 0.3015241
VC offset [mV] 0.3067343 0.3033315 0.3022492

Note that the inertias of the EC32Flat motors are larger than the inertia calculated for the
BLY17 motor. Although the EC32Flat have smaller dimensions, their inertia is grater because
of the flywheels used.

4.2.2 Performance

The software was successfully tested with the final PCBs after implementing the modifications
explained in Chapter 3. More precisely, PCB ]2 with its motor were tested. Board ]1 has
not been modified and board ]3 was built with a MCU different from the others, which has no
licence to execute some parts of the code. Spin-TAC is a copyrighted module, and a particular
MCU has different versions depending on whether it has licence or not to use it. This was never
experienced before although the identifications of the MCUs differ in some digits. It will have to
be replaced by a valid one to execute the software developed.
The testing has been performed in the same way as for the development kit. Slow speed
evolutions and successively varying acceleration commands.
Figure 4.3 shows a slow speed evolution to verify, in the same way as for the development
kit, that the control is able to introduce tiny variations in the speed of the motor. The result is the
line expected, which demonstrates that the constant low acceleration is hold during the whole
test. In this case, the acceleration chosen has been 1.5 RPM/s. Apart from the success of
the test, a mention has to be made about the grater dispersion of the speed samples in some

25
instants -around 130, 180, 300, 420 seconds-. This is due to disturbances caused by touching
slightly the rotor when wanting to verify its temperature.

Figure 4.3: Slow speed progression at 1.5rpm/s

Figure 4.4 demonstrates that both positive and negative accelerations are achieved suc-
cessfully. Moreover, when zero acceleration is commanded to the motor, the speed stays fixed.
This is the behaviour expected and described in Chapter 3. According to the last section of this
chapter 3.4.3, the speed reference was set to a high value for positive accelerations and a low
one for negative accelerations. During the test, these reference speeds are never reached.

Figure 4.4: Speed variations with different successive positive and negative accelerations

Another issue to be verified has been the low speed performance, where the rotation is
more likely to become rough. Some controls have problems when the angular speed goes
blow 1000 RPMs, and that had to be avoided. The control developed has been able to provide
stable speed and good performance in a range between 2100 RPMs and 100 RPMs.
Figure 4.5 shows the motor spinning at almost the mentioned speed limits, as well as the
fixed speed regions zoomed. Something clear that the error is greater when the speed is lower.
This is due to the way of calculating the speed using the Hall effect sensors. If the speed
diminishes, the time between the Hall sensors’ pulses increases and, because the samples
are taken at a constant rate, less pulses are detected. When the speed calculation uses lower
values, the differences between them lead to an increase of the relative error.

26
Figure 4.5: Speed variation from 2000 RPMs to 100 RPMs and fixed speed zoomed areas

The relative error is given for the speed limits mentioned - at 2000 RPMs and 100 RPMs-.
The relative speed measure errors can be calculated with the zoomed areas, looking at the
maximum differences from the ideal value. For the higher speeds, the maximmum difference
with respect the 2000 RPMs is 11 RPMs, which gives a relative error of 0.55 %. This value is
excellent. For the lower speeds, the situation is different and the error increases dramatically.
The worst measure differs 39 RPMs from the ideal 100 RPMs. Which is an error of 39 %.
However, the measures are always oscillating around the optimal value, they do not diverge.
This is what makes it possible to make the motor function properly. When the PWM signals are
driven to the the motor, their duty cycle oscillates as a consequence of this error. This oscillation
has the frequency of the measurements made -which is 500 times higher than the sampling rate
of these tests-, and it is too high for the motor to follow it, so the effect is the same as if it was
an almost constant voltage. The consequence of this phenomenon is a little vibration of the
motor.
The video below shows the motor decelerating and the good behaviour achieved at low
speeds although the commented error -100 RPMs in the final moments of the video-.

27
The error at low RPMs, however, makes it impossible to achieve a smooth control below
100 RPMs. This can be seen, for example, when the motor is asked to change its direction
of rotation. Near zero speed, the behaviour is irregular until it gains angular velocity again.
This situation could be either given or avoided, depending on the bias speed of theRW, which
depends on the torques to compensate and the actuation of the magnetorquers.
If it is found that, when developing the ADCS algorithms, these type of transitions become
necessary for the final application, some changes should be done. Possible solutions can be:

• To use more Hall sensors to increase the resolution of the lectures and reduce the error
at low speed.

• To use a quadrature encoder, which can provide huge resolution. However, this supposes
attaching a magnet to the rotor and having to place an encoder perfectly aligned.

• To change to an open-loop control when the motor’s angular speed is between 100 and
-100 RPMs. The less desirable solution, as the closed-loop control should be maintained.

Figure 4.6 shows a transition from -1000 to 1000 RPMs and the central area zoomed. It can
be observed that the region between 100 and -100 RPMs is where the values vary irregularly.

Figure 4.6: Speed variation from -1000 to 1000 RPMs and the central area zoomed.

28
Chapter 5

Budget

Table 5.1 shows the total cost of the project, taking into account the working hours and used
components.

Item Cost per unit Quantity Total Item Cost


Code Composer Studio 6.0 0e 1 0e
Scilab 0e 1 0e
Altium Designer 0e 1 0e
TexMaker 0e 1 0e
Auxiliar boards 0e 2 0e
DRV8312-69M-KIT 300 e 1 300 e
Motor PCBs 0e 3 0e
Maxon motors 235 e 3 705 e
Batteries Li-Ion 20 e 3 60 e
Hours 8e 800 6400 e
TOTAL COST - - 7465 e

Table 5.1: Detailed project cost

29
Chapter 6

Conclusions and Future Development

After some modifications of the work plan, the main objective of this thesis has been achieved:
to control the RW with a closed-loop algorithm using Hall effect sensors, and providing them
with the capability of obeying speed and acceleration instructions. The results show that, on
the one hand, the behaviour of the motors is the desired one, being able to maintain a specific
acceleration, applying it to accelerate or decelerate the motor, and following very slow speed
evolutions. The errors when rotating at a constant speed are very low when the speed is high
-0.55 %, which fulfils the requirements- and big when the speed is near zero -39%-, however,
the configuration of the system makes the control possible and a good performance is achieved
at low speeds although little vibrations appear.
On the other hand, the need of hardware modifications and the need to complete the soft-
ware indicate that there is still work to do. To finish the system different pieces have to be put
together as no additional parts need to be designed and implemented from scratch.
Future work regarding the hardware -motor control PCBs- lists the following tasks:

• Connect the Hall sensors’ pins to the encoder dedicated GPIOs.

• Redesign the connections for the voltage level shifter in the sensors’ signals conditioning
and, if possible, find a smaller level shifter with less channels.

• Remove the two buck-boost converters the PCB now includes. 3 Cat-3 Electrical Power
Subsystem (EPS) is going to be able to feed the boards with 3.3 V and 12 V, so no
conversions will have to be done [17].

• Remove the Light Emitting Diode (LED)s to reduce the power consumption.

• Build three boards with the specific MCUs needed -the third board now has a MCU without
licence to execute some copyrighted parts of the code used-.

• With all the previous modifications, redesign the control boards with different dimensions
or into different parts with the objective of fitting the motors and boards in a half of a
10x10x10 cm3 unit.

• Redesign the motor supports and build them in aluminium, as it is rigid and light.

30
With all these remaining hardware modifications, a new design for the RW module is pro-
posed. Fitting the RW in the lower half of the 10x10x10 cm3 volume is the major constraint of
this design. The new design could also propose new shapes and sizes for the motor controller
PCBs. However, it would be again a hard design and testing work as new problems would come
up. Figure 6.1 shows a proposal for a future configuration where the boards are divided in two
halves. This is done in order to keep the current size of the motors and flywheels. Another
option could be reducing the motors’ size if, after physics studies, it was found that the desired
response could be obtained with less momentum motors.

Figure 6.1: Proposed design for the RW system

Regarding the software part, the tasks remaining are:

• Improve the robustness of the code developed.

• Combine the developed code with the SPI communication.

• A requirement is a high frequency of the control loop execution and, with the MCU used, it
is a lot grater -9 times grater than needed-. The running frequency of the microcontroller
could be lowered in order to reduce power consumption while maintaining the motor’s
good monitoring.

Finally, to integrate the reaction wheels in the ADCS of the satellite and make them work
together with the attitude determination system and the magnetorquers:

• Study thoroughly which inertia will the motors be required to have, and redesign the
flywheels accordingly. Purchasing smaller dimensions motors -20mm diameter motors
are also offered by Maxon- could be an option which would help saving space.

• Develop control algorithms for target tracking using attitude determination data from the
Star Tracker and Sun sensors.

• Combine the RW actions with the magnetorquers to implement the momentum unloading
described in Section 3.1.2.2.

• Test the whole system with all the mentioned tasks completed and with the specific ADCS
masterboard.

31
Bibliography

[1] Mariland Aerospace. ”MAI-400 - 1/2U CubeSat ADCS”, 2010. URL http://maiaero.com/
products/s/mai-400/. [Online; accessed June-2016].

[2] Texas Instruments C2000 Systems and Applications Team. ”Trapezoidal Control of BLDC
Motors Using Hall Effect Sensors”. URL http://www.ti.com/tool/controlsuite. Con-
trolSUITE - [Online; downloaded Feb-2016].

[3] Microsemi. ”Park, Inverse Park and Clarke, Inverse Clarke Transformations MSS Software
Implementation - User Guide”, 2013.

[4] Texas Instruments C2000 Systems and Applications Team. ”Sensorless Field Oriented
Control of Multiple Permanent Magnet Motors”, 2010. URL ftp://ftp.ti.com/pub/dml/
DMLrequest/Christy_FTP-10-30-12/controlSUITE/development_kits/LVMultiAxis+
PfcKit_v1.4/2xPM_Sensorless_v1_1/~Doc/Sensorless%20FOC%20of%202xPM.pdf.
[Online; accessed May-2016].

[5] Texas Instruments. ”TMS320F28069M InstaSPIN™-MOTION Software - Technical Ref-


erence Manual”, 2014. URL http://www.ti.com/lit/ug/spruhj0b/spruhj0b.pdf. [On-
line; accessed May-2016].

[6] Texas Instruments. ”DRV8312 Baseboard Hardware Reference Guide”, 2012.

[7] Wikipedia. ”Hall effect sensor”, 2010. URL https://en.wikipedia.org/wiki/Hall_


effect_sensor. [Online; accessed May-2016].

[8] Texas Instruments. ”Clarke and Park Transforms on the TMS320C2xx”, 1997. URL http:
//www.ti.com/lit/an/bpra048/bpra048.pdf. [Online; accessed May-2016].

[9] Mark Humphrys. ”Continuous output, the sigmoid function”, 1990. Properties of the sig-
moid, including how it can shift along axes and how its domain may be transformed.

[10] STMicroelectronics). ”UM1670 User Manual - Discovery kit for STM32F429”, 2013.

[11] Aleix Calderón. ”Attitude Control of 3 Cat-3 Using Reaction Wheels”, 2016. Universitat de
Barcelona, Facultat de Fı́sica.

[12] Texas Instruments. ”TMS320F2806x Piccolo™ Microcontrollers”, 2016. URL http://www.


ti.com/lit/ds/symlink/tms320f28069m.pdf. [Online; accessed May-2016].

32
[13] Texas Instruments. ”DRV83x2 Three-Phase PWM Motor Driver”, 2014. URL http://www.
ti.com/lit/ds/symlink/drv8312.pdf. [Online; accessed May-2016].

[14] Anaheim Automation. ”BLY17”, 2016. URL http://www.anaheimautomation.com/


products/brushless/brushless-motor-item.php?sID=143&pt=i&tID=96&cID=22. [On-
line; accessed June-2016].

[15] Maxon. ”Maxon DC motor und Maxon EC motor”, 2011. URL


http://www.maxonmotor.es/medias/sys_master/root/8804419469342/
DC-Das-wichtigste-ueber-maxonmotoren-11-DE-EN-ES-036-1.pdf?attachment=
true. [Online; accessed June-2016].

[16] ON Semiconductors. ”MC14504B - Hex Level Shifter for TTL to CMOS or CMOS to
CMOS”, 2014. URL http://www.onsemi.com/pub_link/Collateral/MC14504B-D.PDF.
[Online; accessed May-2016].

[17] Arnau Solanelles. ”Modular and Scalable Electrical Power System for Nanosatellites”,
2016. Universitat Politècnica de Catalunya, Escola Tècnica Superior d’Enginyeria de Tele-
comunicacions de Barcelona.

[18] Jordi Macià. ”Design and Implementation of a Reaction Wheels Control System Hard-
ware”, 2016. Universitat Politècnica de Catalunya, Escola Tècnica Superior d’Enginyeria
de Telecomunicacions de Barcelona.

[19] Albert Bolet. ”Reaction Wheel-Based 3-axes Attitude Control Systems for Nano-Satellites”,
2015. Universitat Politècnica de Catalunya, Escola Tècnica Superior d’Enginyeria de Tele-
comunicacions de Barcelona.

[20] Texas Instruments. ”TMS320x2806x - Technical Reference Manual”, 2011.

[21] Assaad Farhat, Jighjigh Ivasc, Ye Lu, Alan Snapp. ”Attitude Determination and Con-
trol System for CubeSat”, 2013. URL https://m.wpi.edu/Pubs/E-project/Available/
E-project-030113-141835/unrestricted/2013_ADC_Report_Final.pdf. Worcester
Polytechnic Institute - [Online; accessed May-2016].

[22] Texas Instruments. ”InstaSPIN-FOCT M and InstaSPIN-MOTIONT M - User’s Guide”, 2014.


URL http://www.ti.com/lit/ug/spruhj1f/spruhj1f.pdf. [Online; accessed June-
2016].

[23] Adam Reynolds. LineStream Technologies). ”InstaSPIN-MOTION - Position Control Motor


commissioning”, 2013.

[24] Valdemir Carrera, Adolfo Graciano da Silva and Hélio Koiti Kuga. ”A Dynamic Friction
Model for Reaction Wheels, 2006.

[25] Microsom Inc. Members of the Technical Staff, Attitude Systems Operation and Com-
puter Sciences Corporation. ”Spacecraft Attitude Determination and Control, 1999.

33
Appendix A

Critical Design Review Document

Critical Design Review document delivered on May 8th. The Gantt diagram has undergone a
final modification to meet with the project final development.

34
Document: CDR.pdf Project Critical Review
Date: 8/5/2016 3Cat3 3-axes ADCS using
Rev: 01 RW and Magnetorquers
Page 5 of 8

1. GENERAL COMMENTS ABOUT THE WORK PROGRESS

1.1. Incidences

The main incidence in the project has been that Work Package three (WP3) has become much
more complicated than it was expected to be, to control the motors with a closed loop using the Hall
effect sensors is not trivial.

This incidence has affected the other work packages as it has taken almost all the available time
and some of the tasks have been simplified.

Other incidences also have occurred as the unknown complexity of developing the control code for
the reaction wheels system (WP4) and the constraints of redesigning the master board (WP1) as it
is not only a matter of giving orders to the reaction wheels but to control all the sensors and
actuators of the ADCS.

1.2. Work Plan modifications

WP1 was first tried to be completed -to design a PCB which performed the STM32 Discovery
board task of giving orders to the motors’ PCBs- but then abandoned due to the incidence
mentioned regarding this work package.

WP2 has been given less time than expected and the distribution modification is not at an
advanced level.

WP3 has eclipsed the rest of packages becoming the main task of the project and taking most
of the time.

WP4 and WP5 (and, by consequence, WP6) have been descoped due to time constraints.

A work package has been added (the new WP4) remarking the difference on developing the
code with the demonstration kit from Texas Instruments and making it work with the PCBs
developed in a previous TFG.
Document: CDR.pdf Project Critical Review
Date: 8/5/2016 3Cat3 3-axes ADCS using
Rev: 01 RW and Magnetorquers
Page 6 of 8

2. UPDATED WORK PLAN

2.1. Updated Work Packages, Tasks and Milestones

Project:Redesign the configuration of the reaction wheels. WP ref: WP2


Major constituent: hardware Sheet 2 of 6
Short description: Redesign the configuration of the reaction Planned start date: 18/04/2016
wheels in order to achieve the best inertia and to make it occupy Planned end date: 22/04/2016
the lowest volume possible.
Start event: KO
End event: Hardware
redistributed.
Internal task T3: Redistribute the elements into the volume of Deliverables: Dates(project
10x10x10 cm3. -3D files week): 8

Project: Perform the motors control adding Hall sensors WP ref: WP3
information
Major constituent: Software Sheet 3 of 3
Be able to read the motors speed through the Hall effect sensors Planned start date: 29/02/2016
and add its information to the calculations in order to make the Planned end date: 1/06/2016
control more robust adding redundancy.
(Objectives 2 and 3) Start event: KO
End event: Speed control
validated.
Internal task T1: Sense the motors’ speed using the Hall effect Deliverables: Dates(project
sensors. -Software files week): 13
Internal task T2: Add the new information to the control and close -Validation
the loop. plan
Internal task T3: Test the control with the new software

Project: Motor control using Hall sensors with 3Cat-3 hardware WP ref: WP4
Major constituent: software and hardware Sheet 4 of 6
Short description: Accomplish the same results from WP3 but Planned start date:1/06/2016
now with our own PCB for the control of the motors and the real Planned end date: 27/06/2016
motors the nanosatellite is going to use.
Start event: Speed control
validated with development kit
End event: Speed control
validated with specific
hardware.
Internal task T1: Motors parameters identification Deliverables: Dates(project
Internal task T2: Achieve the closed loop control -Software files week): 17
Internal task T3: Test the control with the new software -Validation
plan
Document: CDR.pdf Project Critical Review
Date: 8/5/2016 3Cat3 3-axes ADCS using
Rev: 01 RW and Magnetorquers
Page 7 of 8

Milestones

WP# Task# Short title Milestone / deliverable Date (week)


3 1,2 Speed and acceleration Hall sensors and control 12
control with development kit code finished
3 3 Validate the Hall sensors’ Motor tests/Validation plan 13
software
2 1 New hardware configuration New configuration 3D 8
scheme drawing
4 1,2 Speed and acceleration Hall sensors and control 16
control with specific code finished
hardware
4 3 Validate the Hall sensors’ Motor tests/Validation plan 17
software
Document: CDR.pdf Project Critical Review
Date: 8/5/2016 3Cat3 3-axes ADCS using
Rev: 01 RW and Magnetorquers
Page 8 of 8

2.2. Updated Time Plan (Gantt diagram)


Appendix B

PCBs schematics

B.1 Motor PCBs

The final design of the PCBs used developed by the former student Jordi Macià is shown in this
appendix. The board schematics and layout can be seen in Figures B.1, B.2, B.3 and B.4.

B.2 FTDI board

The FTDI board has been used to connect the motor boards via Universal Serial Bus (USB)
cable to the computer and program them. As it is not useful once the motor boards have been
loaded with the software, it was built separately in order not to occupy space in the satellite. Its
layout is showed in Figure B.5.

39
Figure B.1: Socket connector and power circuit

40
Figure B.2: DRV8312 driver and motor current/voltage sensing

Figure B.3: MCU connections

41
Figure B.4: PCB layout -top layer-

Figure B.5: FTDI board layout -top layer-

42
Appendix C

Scilab code

Scilab has been used to gather the speed information and then plot it as the debug tool could
not store data for a long time. The code of the application used is the content of this appendix.
1 // Read . txt file with speed information
2 clear ;
3 datafile = uigetfile ([ " *. txt " ] , " " ," Data file " ,% t ) ;
4

5 // Open the datafile ( quit if we can ’t )


6 fid = mopen ( datafile , ’r ’) ;
7 if ( fid == -1)
8 error ( ’ cannot open datafile ’) ;
9 end
10

11 // Loop over all lines in the file , reading them one at a time
12 num_samples = 1;
13 val0 = 0;
14

15 // Store the speed variables in val1 and differences between them in acc
16 while ~ meof ( fid ) do
17 [ num_read , val1 (1 , num_samples ) ] = mfscanf ( fid , ’% d ’) ;
18 dif ( num_samples ) = ( val1 ( num_samples ) - val0 ) /2;
19 val0 = val1 ( num_samples ) ;
20 num_samples = num_samples + 1;
21 end
22

23 xvector =[1:( num_samples -2) ];


24 // close the datafile
25 mclose ( fid ) ;
26

27 // speed and difference units conversion


28 speedData = val1 ./16777.216;
29 difference = dif ./16777.216;
30 difference (1) = 0;
31

32 // time axis calculation for one sample every 250 loop counts
33 totalTime = length ( val1 ) /19; // 9.5 if 500 loop counts
34 [ time ] = linspace (0 , totalTime , length ( val1 ) ) ;
35

36 // plot the speed and differences progression

43
37 subplot (121) ;
38 plot ( time , - speedData , ’ - roo ’) ;
39 ylabel ( " Speed ( rpm ) " ) ;
40 xlabel ( " Time ( s ) " ) ;
41 xtitle ( " Slow speed progression " ) ;
42 xgrid (1 , 1 , 7)
43

44 subplot (122) ;
45 plot ( time , difference , ’ - goo ’) ;
46 ylabel ( " Speed samples differences ) " ) ;
47 xlabel ( " Time ( s ) " ) ;
48 xtitle ( " Values dispersion " ) ;
49 xgrid (1 , 1 , 7)

frame

44
Appendix D

F28069M Code

Appendix with the main code of the application. Main.h and hal.c are also included as files with
some relevance. Minor changes were implemented in other files not included in this document.

D.1 MAIN

This is the code specifically run by the application. main.h complements the main.c file with
initializations and defines.

D.1.1 main.c

1 // ! SpinTAC Velocity Controller using a quadrature encoder for feedback


2 // !
3

4 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
5 // the includes
6

7 // system includes
8 # include < math .h >
9 # include " main . h "
10

11 # ifdef FLASH
12 # pragma CODE_SECTION ( mainISR , " ramfuncs " ) ;
13 # endif
14

15 // Include header files used in the main function


16

17

18 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
19 // the defines
20

21 # define LED_BLINK_FREQ_Hz 5
22

23

24 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
25 // the globals
26

45
27 uint_least16_t g Co un ter _u pd ate Gl ob als = 0;
28

29 bool F l a g _ L a t c h _ so f t w a r e U p d a t e = true ;
30

31 CTRL_Handle ctrlHandle ;
32

33 HAL_Handle halHandle ;
34

35 USER_Params gUserParams ;
36

37 HAL_PwmData_t gPwmData = { _IQ (0.0) , _IQ (0.0) , _IQ (0.0) };


38

39 HAL_AdcData_t gAdcData ;
40

41 _iq gMaxCurrentSlope = _IQ (0.0) ;


42

43 # ifdef FAST_ROM_V1p6
44 CTRL_Obj * controller_obj ;
45 # else
46 CTRL_Obj ctrl ; // v1p7 format
47 # endif
48

49 ENC_Handle encHandle ;
50 ENC_Obj enc ;
51

52 SLIP_Handle slipHandle ;
53 SLIP_Obj slip ;
54

55 ST_Obj st_obj ;
56 ST_Handle stHandle ;
57

58 uint16_t gLEDcnt = 0;
59

60 // Variables for storing speed samples


61 bool storeSpeed = false ;
62 bool st oreOverflowFlag = false ;
63 _iq speedData [10000];
64 uint32_t speedSampleRate = 500;
65 uint32_t loopCounter = 0;
66 uint32_t index = 0;
67

68 // Boolean to switch between controls


69 bool sensoredControl = false ;
70

71 volatile MOTOR_Vars_t gMotorVars = MOTOR_Vars_INIT ;


72

73 # ifdef FLASH
74 // Used for running BackGround in flash , and ISR in RAM
75 extern uint16_t * RamfuncsLoadStart , * RamfuncsLoadEnd , * RamfuncsRunStart ;
76 # endif
77

78

79 # ifdef DRV8301_SPI

46
80 // Watch window interface to the 8301 SPI
81 D RV _ S PI _ 8 301_Vars_t gDrvSpi8301Vars ;
82 # endif
83 # ifdef DRV8305_SPI
84 // Watch window interface to the 8305 SPI
85 D RV _ S PI _ 8 305_Vars_t gDrvSpi8305Vars ;
86 # endif
87

88 _iq g Flux_pu_to_Wb_sf ;
89

90 _iq g F lu x _ pu_to_VpHz_sf ;
91

92 _iq g T o r q u e _ L s _ I d _ I q _ p u _ t o _ N m _ s f ;
93

94 _iq g T o r q u e _ F l u x _ I q _ p u _ t o _ N m _ s f ;
95

96 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
97 // the functions
98

99 void main ( void )


100 {
101 uint_least8_t estNumber = 0;
102

103 # ifdef FAST_ROM_V1p6


104 uint_least8_t ctrlNumber = 0;
105 # endif
106

107 // Only used if running from FLASH


108 // Note that the variable FLASH is defined by the project
109 # ifdef FLASH
110 // Copy time critical code and Flash setup code to RAM
111 // The RamfuncsLoadStart , RamfuncsLoadEnd , and RamfuncsRunStart
112 // symbols are created by the linker . Refer to the linker files .
113 memCopy (( uint16_t *) & RamfuncsLoadStart ,( uint16_t *) & RamfuncsLoadEnd ,( uint16_t
,→ *) & RamfuncsRunStart ) ;
114 # endif
115

116 // initialize the hardware abstraction layer


117 halHandle = HAL_init (& hal , sizeof ( hal ) ) ;
118

119

120 // check for errors in user parameters


121 U S ER _ ch e ckForErrors (& gUserParams ) ;
122

123

124 // store user parameter error in global variable


125 gMotorVars . UserErrorCode = USER_getErrorCode (& gUserParams ) ;
126

127

128 // do not allow code execution if there is a user parameter error


129 if ( gMotorVars . UserErrorCode != U SE R_ Err or Co de_ No Er ror )
130 {
131 for (;;)

47
132 {
133 gMotorVars . Flag_enableSys = false ;
134 }
135 }
136

137

138 // initialize the user parameters


139 USER_setParams (& gUserParams ) ;
140

141

142 // set the hardware abstraction layer parameters


143 HAL_setParams ( halHandle ,& gUserParams ) ;
144

145

146 // initialize the controller


147 # ifdef FAST_ROM_V1p6
148 ctrlHandle = CTRL_initCtrl ( ctrlNumber , estNumber ) ; // v1p6 format (06 xF
,→ and 06 xM devices )
149 controller_obj = ( CTRL_Obj *) ctrlHandle ;
150 # else
151 ctrlHandle = CTRL_initCtrl ( estNumber ,& ctrl , sizeof ( ctrl ) ) ; // v1p7 format
,→ default
152 # endif
153

154

155 {
156 CTRL_Version version ;
157

158 // get the version number


159 CTRL_getVersion ( ctrlHandle ,& version ) ;
160

161 gMotorVars . CtrlVersion = version ;


162 }
163

164

165 // set the default controller parameters


166 CTRL_setParams ( ctrlHandle ,& gUserParams ) ;
167

168

169 // setup faults


170 HAL_setupFaults ( halHandle ) ;
171

172

173 // initialize the interrupt vector table


174 H A L _ i n i t I nt Ve ct orT ab le ( halHandle ) ;
175

176

177 // enable the ADC interrupts


178 HAL_ enableAdcInts ( halHandle ) ;
179

180

181 // enable global interrupts


182 H A L _ e n a b leGlobalInts ( halHandle ) ;

48
183

184

185 // enable debug interrupts


186 HA L_ en ab leDebugInt ( halHandle ) ;
187

188

189 // disable the PWM


190 HAL_disablePwm ( halHandle ) ;
191

192 // initialize the ENC module


193 encHandle = ENC_init (& enc , sizeof ( enc ) ) ;
194

195

196 // setup the ENC module


197 ENC_setup ( encHandle , 1 , USER_MOTOR_NUM_POLE_PAIRS , USER_MOTOR_ENCODER_LINES ,
,→ 0 , USER_IQ_FULL_SCALE_FREQ_Hz , USER_ISR_FREQ_Hz , 8000.0) ;
198

199

200 // initialize the SLIP module


201 slipHandle = SLIP_init (& slip , sizeof ( slip ) ) ;
202

203

204 // setup the SLIP module


205 SLIP_setup ( slipHandle , _IQ ( gUserParams . ctrlPeriod_sec ) ) ;
206

207

208 // initialize the SpinTAC Components


209 stHandle = ST_init (& st_obj , sizeof ( st_obj ) ) ;
210

211

212 // setup the SpinTAC Components


213 ST_setupVelCtl ( stHandle ) ;
214 ST_setupPosConv ( stHandle ) ;
215

216

217 # ifdef DRV8301_SPI


218 // turn on the DRV8301 if present
219 HAL_enableDrv ( halHandle ) ;
220 // initialize the DRV8301 interface
221 HAL_setupDrvSpi ( halHandle ,& gDrvSpi8301Vars ) ;
222 # endif
223

224 # ifdef DRV8305_SPI


225 // turn on the DRV8305 if present
226 HAL_enableDrv ( halHandle ) ;
227 // initialize the DRV8305 interface
228 HAL_setupDrvSpi ( halHandle ,& gDrvSpi8305Vars ) ;
229 # endif
230

231 // enable DC bus compensation


232 C T R L _ s e t F l a g _ e n a b l e D c B u s C o m p ( ctrlHandle , true ) ;
233

234

49
235 // compute scaling factors for flux and torque calculations
236 gFlu x_pu_to_Wb_sf = U S E R _ c o m p u t e F l u x _ p u _ t o _ W b _ s f () ;
237 g F lu x _p u _to_VpHz_sf = U S E R _ c o m p u t e F l u x _ p u _ t o _ V p H z _ s f () ;
238 g T o r q u e _ L s _ I d _ I q _ p u _ t o _ N m _ s f = U S E R _ c o m p u t e T o r q u e _ L s _ I d _ I q _ p u _ t o _ N m _ s f () ;
239 g T o r q u e _ F l u x _ I q _ p u _ t o _ N m _ s f = U S E R _ c o m p u t e T o r q u e _ F l u x _ I q _ p u _ t o _ N m _ s f () ;
240

241

242 for (;;)


243 {
244 // Waiting for enable system flag to be set
245 while (!( gMotorVars . Flag_enableSys ) ) ;
246

247 // Dis - able the Library internal PI . Iq has no reference now


248 C T R L _ s e t F l a g _ e n a b l e S p e e d C t r l ( ctrlHandle , false ) ;
249

250 // loop while the enable system flag is true


251 while ( gMotorVars . Flag_enableSys )
252 {
253 CTRL_Obj * obj = ( CTRL_Obj *) ctrlHandle ;
254 ST_Obj * stObj = ( ST_Obj *) stHandle ;
255

256 // increment counters


257 g C ou nt er_ up da teG lo ba ls ++;
258

259 // enable / disable the use of motor parameters being loaded from user . h
260 C T R L _ s e t F l a g _ e n a b l e U s e r M o t o r P a r a m s ( ctrlHandle , gMotorVars .
,→ F l a g_en ableU serP aram s ) ;
261

262 // enable / disable Rs recalibration during motor startup


263 E S T _ s e t F l a g _ e n a b l e R s R e c a l c ( obj - > estHandle , gMotorVars . Flag_enableRsRecal c
,→ ) ;
264

265 // enable / disable automatic calculation of bias values


266 C T R L _ s e t F l a g_ e n a b l e O f f s e t ( ctrlHandle , gMotorVars . Fl ag_en able Offse tcal c ) ;
267

268

269 if ( CTRL_isError ( ctrlHandle ) )


270 {
271 // set the enable controller flag to false
272 C TR L_ s et F la g_ e na b le Ct r l ( ctrlHandle , false ) ;
273

274 // set the enable system flag to false


275 gMotorVars . Flag_enableSys = false ;
276

277 // disable the PWM


278 HAL_disablePwm ( halHandle ) ;
279 }
280 else
281 {
282 // update the controller state
283 bool fl ag_c trlSt ateC hange d = CTRL_updateState ( ctrlHandle ) ;
284

285 // enable or disable the control

50
286 C TR L_ s et F la g_ e na b le Ct r l ( ctrlHandle , gMotorVars . Flag_Run_Identify ) ;
287

288 if ( fl ag_c trlS tateC hang ed )


289 {
290 CTRL_State_e ctrlState = CTRL_getState ( ctrlHandle ) ;
291

292 if ( ctrlState == CTRL_State_OffLine )


293 {
294 // enable the PWM
295 HAL_enablePwm ( halHandle ) ;
296 }
297 else if ( ctrlState == CTRL_State_OnLine )
298 {
299 if ( gMotorVars . Fl ag_e nable Offs etcal c == true )
300 {
301 // update the ADC bias values
302 HAL_updateAdcBias ( halHandle ) ;
303 }
304 else
305 {
306 // set the current bias
307 HAL_setBias ( halHandle , HAL_SensorType_Current ,0 , _IQ (
,→ I_A_offset ) ) ;
308 HAL_setBias ( halHandle , HAL_SensorType_Current ,1 , _IQ (
,→ I_B_offset ) ) ;
309 HAL_setBias ( halHandle , HAL_SensorType_Current ,2 , _IQ (
,→ I_C_offset ) ) ;
310

311 // set the voltage bias


312 HAL_setBias ( halHandle , HAL_SensorType_Voltage ,0 , _IQ (
,→ V_A_offset ) ) ;
313 HAL_setBias ( halHandle , HAL_SensorType_Voltage ,1 , _IQ (
,→ V_B_offset ) ) ;
314 HAL_setBias ( halHandle , HAL_SensorType_Voltage ,2 , _IQ (
,→ V_C_offset ) ) ;
315 }
316

317 // Return the bias value for currents


318 gMotorVars . I_bias . value [0] = HAL_getBias ( halHandle ,
,→ HAL_SensorType_Current ,0) ;
319 gMotorVars . I_bias . value [1] = HAL_getBias ( halHandle ,
,→ HAL_SensorType_Current ,1) ;
320 gMotorVars . I_bias . value [2] = HAL_getBias ( halHandle ,
,→ HAL_SensorType_Current ,2) ;
321

322 // Return the bias value for voltages


323 gMotorVars . V_bias . value [0] = HAL_getBias ( halHandle ,
,→ HAL_SensorType_Voltage ,0) ;
324 gMotorVars . V_bias . value [1] = HAL_getBias ( halHandle ,
,→ HAL_SensorType_Voltage ,1) ;
325 gMotorVars . V_bias . value [2] = HAL_getBias ( halHandle ,
,→ HAL_SensorType_Voltage ,2) ;
326

51
327 // enable the PWM
328 HAL_enablePwm ( halHandle ) ;
329 }
330 else if ( ctrlState == CTRL_State_Idle )
331 {
332 // disable the PWM
333 HAL_disablePwm ( halHandle ) ;
334 gMotorVars . Flag_Run_Identify = false ;
335 }
336

337 if (( C T R L _ g e t F l a g _ e n a b l e U s e r M o t o r P a r a m s ( ctrlHandle ) == true ) &&


338 ( ctrlState > CTRL_State_Idle ) &&
339 ( gMotorVars . CtrlVersion . minor == 6) )
340 {
341 // call this function to fix 1 p6
342 US ER _s oft wa re Upd at e1 p6 ( ctrlHandle ) ;
343 }
344

345 }
346 }
347

348

349 if ( ES T_is Motor Iden tifie d ( obj - > estHandle ) )


350 {
351 // set the current ramp
352 E S T _ s e t M a x C u rr e n t S l o p e _ p u ( obj - > estHandle , gMaxCurrentSlope ) ;
353 gMotorVars . Flag_MotorIdentified = true ;
354

355 // set the speed reference


356 CTRL_setSpd_ref_krpm ( ctrlHandle , gMotorVars . SpeedRef_krpm ) ;
357

358 // set the speed acceleration


359 CTRL_setMaxAccel_pu ( ctrlHandle , _IQmpy ( MAX_ACCEL_KRPMPS_SF , gMotorVars
,→ . MaxAccel_krpmps ) ) ;
360

361 // enable the SpinTAC Speed Controller


362 STVELCTL_setEnable ( stObj - > velCtlHandle , true ) ;
363

364 if ( EST_getState ( obj - > estHandle ) != EST_State_OnLine )


365 {
366 // if the estimator is not running , place SpinTAC into reset
367 STVELCTL_setEnable ( stObj - > velCtlHandle , false ) ;
368 }
369

370 if ( F l a g _ L a t c h _ s of t w a r e U p d a t e )
371 {
372 F l a g _ L a t c h _ so f t w a r e U p d a t e = false ;
373

374 USER_calcPIgains ( ctrlHandle ) ;


375

376 // initialize the watch window kp and ki current values with pre -
,→ calculated values
377 gMotorVars . Kp_Idq = CTRL_getKp ( ctrlHandle , CTRL_Type_PID_Id ) ;

52
378 gMotorVars . Ki_Idq = CTRL_getKi ( ctrlHandle , CTRL_Type_PID_Id ) ;
379

380 // initialize the watch window Bw value with the default value
381 gMotorVars . SpinTAC . VelCtlBw_radps = S T V E L C T L _ g e t B a n d w i d t h _ r a d p s (
,→ stObj - > velCtlHandle ) ;
382

383 // initialize the watch window with maximum and minimum Iq


,→ reference
384 gMotorVars . SpinTAC . VelCtlOutputMax_A = _IQmpy (
,→ S T V E L C T L _ g e tO u t p u t M a x i m u m ( stObj - > velCtlHandle ) , _IQ (
,→ U S E R _ I Q _ F U L L _ S C A L E _ C U R R E N T _ A ) ) ;
385 gMotorVars . SpinTAC . VelCtlOutputMin_A = _IQmpy (
,→ S T V E L C T L _ g e tO u t p u t M i n i m u m ( stObj - > velCtlHandle ) , _IQ (
,→ U S E R _ I Q _ F U L L _ S C A L E _ C U R R E N T _ A ) ) ;
386 }
387

388 }
389 else
390 {
391 F l a g _ L a t c h _ s of t w a r e U p d a t e = true ;
392

393 // the estimator sets the maximum current slope during


,→ identification
394 gMaxCurrentSlope = E S T _ g e t M a x C u r r en t S l o p e _ p u ( obj - > estHandle ) ;
395 }
396

397

398 // when appropriate , update the global variables


399 if ( g Co un ter _u pd ate Gl ob al s >= N U M _ M A I N _ T I C K S _ F O R _ G L O B A L _ V A R I A B L E _ U P D A T E )
400 {
401 // reset the counter
402 gC ou nt er_ up da te Glo ba ls = 0;
403

404 u p d a t e G l o b a l V a r i a b l e s _ m o t o r ( ctrlHandle , stHandle ) ;


405

406 // StoreSpeed into speedData vector if required


407 if ( storeSpeed )
408 {
409 loopCounter ++;
410 if ( loopCounter == speedSampleRate )
411 {
412 speedData [ index ] = gMotorVars . Speed_krpm ;
413 loopCounter = 0;
414 index ++;
415 if ( index >= 10000)
416 {
417 index = 0;
418 storeSpeed = false ;
419 storeOverflowFlag = true ;
420 }
421 else storeOverflowFlag = false ;
422 }
423 }

53
424 else
425 {
426 loopCounter = 0;
427 index = 0;
428 }
429 // Control toggle after initial spin - up
430 if ( gMotorVars . Speed_krpm > 1670000 || gMotorVars . Speed_krpm <
,→ -1670000) // IQ24 format , 100 rpm = 1677721
431 {
432 sensoredControl = true ;
433 }
434 }
435

436 // update Kp and Ki gains


437 updateKpKiGains ( ctrlHandle ) ;
438

439 // set the SpinTAC ( ST ) bandwidth scale


440 S T V E L C T L _ s e t B a n d w i d t h _ r a d p s ( stObj - > velCtlHandle , gMotorVars . SpinTAC .
,→ VelCtlBw_radps ) ;
441

442 // set the maximum and minimum values for Iq reference


443 S T V E L C T L _ s e t O u t p u t M a x i m u m s ( stObj - > velCtlHandle , _IQmpy ( gMotorVars .
,→ SpinTAC . VelCtlOutputMax_A , _IQ (1.0/ U S E R _ I Q _ F U L L _ S C A L E _ C U R R E N T _ A ) ) , _IQmpy
,→ ( gMotorVars . SpinTAC . VelCtlOutputMin_A , _IQ (1.0/
,→ U S E R _ I Q _ F U L L _ S C A L E _ C U R R E N T _ A ) ) ) ;
444

445 // enable / disable the forced angle


446 E S T _ s e t F l a g _ e n a b l e F o r c e A n g l e ( obj - > estHandle , gMotorVars .
,→ F l a g_en ableF orce Angl e ) ;
447

448 // enable or disable power warp


449 C T R L _ s e t F l a g _ e n a b l e P o w e r W a r p ( ctrlHandle , gMotorVars . Flag_enablePowerWarp )
,→ ;
450

451 # ifdef DRV8301_SPI


452 HAL_writeDrvData ( halHandle ,& gDrvSpi8301Vars ) ;
453

454 HAL_readDrvData ( halHandle ,& gDrvSpi8301Vars ) ;


455 # endif
456 # ifdef DRV8305_SPI
457 HAL_writeDrvData ( halHandle ,& gDrvSpi8305Vars ) ;
458

459 HAL_readDrvData ( halHandle ,& gDrvSpi8305Vars ) ;


460 # endif
461 } // end of while ( gFlag_enableSys ) loop
462

463

464 // disable the PWM


465 HAL_disablePwm ( halHandle ) ;
466

467 // set the default controller parameters ( Reset the control to re - identify
,→ the motor )
468 CTRL_setParams ( ctrlHandle ,& gUserParams ) ;

54
469 gMotorVars . Flag_Run_Identify = false ;
470

471 // setup the SpinTAC Components


472 ST_setupVelCtl ( stHandle ) ;
473 ST_setupPosConv ( stHandle ) ;
474

475 } // end of for (;;) loop


476

477 } // end of main () function


478

479

480 interrupt void mainISR ( void )


481 {
482

483 static uint16_t stCnt = 0;


484 CTRL_Obj * obj = ( CTRL_Obj *) ctrlHandle ;
485

486 // toggle status LED


487 if ( gLEDcnt ++ > ( uint_least32_t ) ( USER_ISR_FREQ_Hz / LED_BLINK_FREQ_Hz ) )
488 {
489 HAL_toggleLed ( halHandle ,( GPIO_Number_e ) HAL_Gpio_LED2 ) ;
490 gLEDcnt = 0;
491 }
492

493

494 // compute the electrical angle


495 if ( sensoredControl ) ENC_calcElecAngle ( encHandle , HAL_getQepPosnCounts (
,→ halHandle ) ) ;
496

497

498 // acknowledge the ADC interrupt


499 HAL_acqAdcInt ( halHandle , ADC_IntNumber_1 ) ;
500

501

502 // convert the ADC data


503 HAL_readAdcData ( halHandle ,& gAdcData ) ;
504

505

506 // Run the SpinTAC Components


507 if ( stCnt ++ >= I S R _ T I C K S _ P E R _ S P I N T A C _ T I C K ) {
508 if ( sensoredControl ) ST_runPosConv ( stHandle , encHandle , ctrlHandle ) ;
509 ST_runVelCtl ( stHandle , ctrlHandle ) ;
510 stCnt = 1;
511 }
512

513

514 if ( USER_MOTOR_TYPE == MOTOR_Type_Induction ) {


515 // update the electrical angle for the SLIP module
516 S L I P _ s et E le ct r ic a lA ng l e ( slipHandle , ENC_getElecAngle ( encHandle ) ) ;
517 // compute the amount of slip
518 SLIP_run ( slipHandle ) ;
519

520

55
521 // run the controller
522 CTRL_run ( ctrlHandle , halHandle ,& gAdcData ,& gPwmData , SLIP _get Magne ticA ngle (
,→ slipHandle ) , sensoredControl ) ;
523 }
524 else {
525 CTRL_run ( ctrlHandle , halHandle ,& gAdcData ,& gPwmData , ENC_getElecAngle (
,→ encHandle ) , sensoredControl ) ;
526 }
527

528 // write the PWM compare values


529 HAL_writePwmData ( halHandle ,& gPwmData ) ;
530

531

532 // setup the controller


533 CTRL_setup ( ctrlHandle ) ;
534

535 // if we are forcing alignment , using the Rs Recalculation , align the eQEP
,→ angle with the rotor angle
536 if (( EST_getState ( obj - > estHandle ) == EST_State_Rs ) && ( USER_MOTOR_TYPE ==
,→ MOTOR_Type_Pm ) && sensoredControl )
537 {
538 ENC_ setZeroOffset ( encHandle , ( uint32_t ) ( HAL _getQ epPo snMax imum ( halHandle ) -
,→ H A L _getQepPosnCounts ( halHandle ) ) ) ;
539 }
540

541 return ;
542 } // end of mainISR () function
543

544

545 void u p d a t e G l o b a l V a r i a b l e s _ m o t o r ( CTRL_Handle handle , ST_Handle sthandle )


546 {
547 CTRL_Obj * obj = ( CTRL_Obj *) handle ;
548 ST_Obj * stObj = ( ST_Obj *) sthandle ;
549

550

551 // get the speed estimate


552 gMotorVars . Speed_krpm = EST_getSpeed_krpm ( obj - > estHandle ) ;
553

554 // get the speed from eQEP


555 if ( sensoredControl ) gMotorVars . SpeedQEP_krpm = _IQmpy (
,→ S T P O S C O N V _ g e t V e l o c i t y F i l t e r e d ( stObj - > posConvHandle ) , _IQ (
,→ S T _ SPEED_KRPM_PER_PU ) ) ;
556

557 // get the real time speed reference coming out of the speed trajectory
,→ generator
558 gMotorVars . SpeedTraj_krpm = _IQmpy ( CT RL _ge tS pd _in t_ re f_p u ( handle ) ,
,→ E S T _get _pu_t o_kr pm_s f ( obj - > estHandle ) ) ;
559

560 // get the torque estimate


561 gMotorVars . Torque_Nm = USER _comp uteT orque _Nm ( handle ,
,→ gTorque_Flux_Iq_pu_to_Nm_sf , g T o r q u e _ L s _ I d _ I q _ p u _ t o _ N m _ s f ) ;
562

563 // get the magnetizing current

56
564 gMotorVars . MagnCurr_A = EST_getIdRated ( obj - > estHandle ) ;
565

566 // get the rotor resistance


567 gMotorVars . Rr_Ohm = EST_getRr_Ohm ( obj - > estHandle ) ;
568

569 // get the stator resistance


570 gMotorVars . Rs_Ohm = EST_getRs_Ohm ( obj - > estHandle ) ;
571

572 // get the stator inductance in the direct coordinate direction


573 gMotorVars . Lsd_H = EST_getLs_d_H ( obj - > estHandle ) ;
574

575 // get the stator inductance in the quadrature coordinate direction


576 gMotorVars . Lsq_H = EST_getLs_q_H ( obj - > estHandle ) ;
577

578 // get the flux in V / Hz in floating point


579 gMotorVars . Flux_VpHz = EST_getFlux_VpHz ( obj - > estHandle ) ;
580

581 // get the flux in Wb in fixed point


582 gMotorVars . Flux_Wb = USER_computeFlux ( handle , gFlux_pu_to_Wb_sf ) ;
583

584 // get the controller state


585 gMotorVars . CtrlState = CTRL_getState ( handle ) ;
586

587 // get the estimator state


588 gMotorVars . EstState = EST_getState ( obj - > estHandle ) ;
589

590 // Get the DC buss voltage


591 gMotorVars . VdcBus_kV = _IQmpy ( gAdcData . dcBus , _IQ ( U S E R _ I Q _ F U L L _ S C A L E _ V O L T A G E _ V
,→ /1000.0) ) ;
592

593 // get the Iq reference from the speed controller


594 gMotorVars . IqRef_A = _IQmpy ( S T V E L C T L _ g e t T o r q u e R e f e r e n c e ( stObj - > velCtlHandle ) ,
,→ _IQ ( U S E R _ I Q _ F U L L _ S C A L E _ C U R R E N T _ A ) ) ;
595

596 // gets the Velocity Controller status


597 gMotorVars . SpinTAC . VelCtlStatus = STVELCTL_getStatus ( stObj - > velCtlHandle ) ;
598

599 // get the inertia setting


600 gMotorVars . SpinTAC . I n e rt i a E st i m a te _ A p er k r p m = _IQmpy ( STVELCTL_getInertia ( stObj
,→ - > velCtlHandle ) , _IQ ( ST_SPEED_PU_PER_KRPM * U S E R _ I Q _ F U L L _ S C A L E _ C U R R E N T _ A )
,→ ) ;
601

602 // get the friction setting


603 gMotorVars . SpinTAC . F r i c t i o n E s t i m a t e _ A p e r k rp m = _IQmpy ( STVELCTL_getFriction (
,→ stObj - > velCtlHandle ) , _IQ ( ST_SPEED_PU_PER_KRPM *
,→ U S E R _ I Q _ F U L L _ S C A L E _ C U R R E N T _ A ) ) ;
604

605 // get the Velocity Controller error


606 gMotorVars . SpinTAC . VelCtlErrorID = STVELCTL_getErrorID ( stObj - > velCtlHandle ) ;
607

608 // get the Position Converter error


609 if ( sensoredControl ) gMotorVars . SpinTAC . PosConvErrorID = STPOSCONV_getErrorID (
,→ stObj - > posConvHandle ) ;

57
610

611 return ;
612 } // end of u p d a t e G l o b a l V a r i a b l e s _ m o t o r () function
613

614

615 void updateKpKiGains ( CTRL_Handle handle )


616 {
617 if (( gMotorVars . CtrlState == CTRL_State_OnLine ) && ( gMotorVars .
,→ F l a g_MotorIdentified == true ) && ( F l a g _ L a t c h_ s o f t w a r e U p d a t e == false ) )
618 {
619 // set the kp and ki speed values from the watch window
620 CTRL_setKp ( handle , CTRL_Type_PID_spd , gMotorVars . Kp_spd ) ;
621 CTRL_setKi ( handle , CTRL_Type_PID_spd , gMotorVars . Ki_spd ) ;
622

623 // set the kp and ki current values for Id and Iq from the watch window
624 CTRL_setKp ( handle , CTRL_Type_PID_Id , gMotorVars . Kp_Idq ) ;
625 CTRL_setKi ( handle , CTRL_Type_PID_Id , gMotorVars . Ki_Idq ) ;
626 CTRL_setKp ( handle , CTRL_Type_PID_Iq , gMotorVars . Kp_Idq ) ;
627 CTRL_setKi ( handle , CTRL_Type_PID_Iq , gMotorVars . Ki_Idq ) ;
628 }
629

630 return ;
631 } // end of updateKpKiGains () function
632

633

634 void ST_runPosConv ( ST_Handle handle , ENC_Handle encHandle , CTRL_Handle


,→ ctrlHandle )
635 {
636 ST_Obj * stObj = ( ST_Obj *) handle ;
637

638 // get the electrical angle from the ENC module


639 S T P O S C O N V _ s e t E l e c A n g l e _ e r e v ( stObj - > posConvHandle , ENC_getElecAngle ( encHandle
,→ ) ) ;
640

641 if ( USER_MOTOR_TYPE == MOTOR_Type_Induction ) {


642 // The CurrentVector feedback is only needed for ACIM
643 // get the vector of the direct / quadrature current input vector values
,→ from CTRL
644 S T P O S C O N V _ s e t C u r r e n t V e c t o r ( stObj - > posConvHandle , CTRL_getIdq_in_addr (
,→ ctrlHandle ) ) ;
645 }
646

647 // run the SpinTAC Position Converter


648 STPOSCONV_run ( stObj - > posConvHandle ) ;
649

650 if ( USER_MOTOR_TYPE == MOTOR_Type_Induction ) {


651 // The Slip Velocity is only needed for ACIM
652 // update the slip velocity in electrical angle per second , Q24
653 S L I P _ s etSlipVelocity ( slipHandle , S T P O S C O N V _g e t S l i p V e l o c i t y ( stObj - >
,→ posConvHandle ) ) ;
654 }
655 }
656

58
657

658 void ST_runVelCtl ( ST_Handle handle , CTRL_Handle ctrlHandle )


659 {
660 _iq speedFeedback , iqReference ;
661 ST_Obj * stObj = ( ST_Obj *) handle ;
662 CTRL_Obj * ctrlObj = ( CTRL_Obj *) ctrlHandle ;
663

664 // Get the mechanical speed in pu


665 speedFeedback = S T P O S C O N V _ g e t V e l o c i t y F i l t e r e d ( stObj - > posConvHandle ) ;
666

667 // Run the SpinTAC Controller


668 // Note that the library internal ramp generator is used to set the speed
,→ reference
669 S T V E L C T L _ s e t V e l o c i t y R e f e r e n c e ( stObj - > velCtlHandle , TRAJ_getIntValue ( ctrlObj
,→ - > trajHandle_spd ) ) ;
670 S T V E L C T L _ s e t A c c e l e r a t i o n R e f e r e n c e ( stObj - > velCtlHandle , _IQ (0.0) ) ; // Internal
,→ ramp generator does not provide Acceleration Reference
671 S T V E L C T L _ s e t V e l o c i t y F e e d b a c k ( stObj - > velCtlHandle , speedFeedback ) ;
672 STVELCTL_run ( stObj - > velCtlHandle ) ;
673

674 // select SpinTAC Velocity Controller


675 iqReference = S T V E L C T L _ g e t T o r q u e R e f e r e n c e ( stObj - > velCtlHandle ) ;
676

677 // Set the Iq reference that came out of SpinTAC Velocity Control
678 CTRL _setIq_ref_pu ( ctrlHandle , iqReference ) ;
679 }
680

681

682 // @ } // defgroup
683 // end of file

frame

D.1.2 main.h

1 // the includes
2

3 // modules
4 # include " sw / modules / math / src /32 b / math . h "
5 # include " sw / modules / memCopy / src / memCopy . h "
6 # include " sw / modules / est / src /32 b / est . h "
7 # include " sw / modules / svgen / src /32 b / svgen_current . h "
8 # include " sw / modules / fw / src /32 b / fw . h "
9 # include " sw / modules / slip / src /32 b / slip . h "
10

11 // platforms
12 # ifndef QEP
13 # include " sw / modules / ctrl / src /32 b / ctrl . h "
14 # else
15 # include " sw / modules / ctrl / src /32 b / ctrlQEP . h "
16 # endif
17 # include " hal . h "

59
18 # include " user . h "
19

20 // SpinTAC
21 # include " spintac_velocity . h "
22

23 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
24 // the defines
25

26 // Defines the number of main iterations before global variables are updated
27 # define N U M _ M A I N _ T I C K S _ F O R _ G L O B A L _ V A R I A B L E _ U P D A T E 1
28

29 // Defines the speed acceleration scale factor .


30 # define M AX_ACCEL_KRPMPS_SF _IQ ( U S E R _ M O T O R _ N U M _ P O L E _ PA I R S * 1000.0 /
,→ USER_TRAJ_FREQ_Hz / U S E R _ I Q _ F U L L _ S C A L E _ F R E Q _ H z / 60.0)
31

32 // Initialization values of global variables


33 # define MOTOR_Vars_INIT { false , \
34 false , \
35 false , \
36 true , \
37 false , \
38 true , \
39 true , \
40 true , \
41 false , \
42 CTRL_State_Idle , \
43 EST_State_Idle , \
44 USER_ErrorCode_NoError , \
45 {0 , CTRL_TargetProc_Unknown ,0 ,0} , \
46 _IQ (0.0) , \
47 _IQ (0.0) , \
48 _IQ ( -1) , \
49 _IQ ( -1) , \
50 _IQ (0.0) , \
51 _IQ (0.05) , \
52 _IQ20 (5.0) , \
53 _IQ (0.0) , \
54 _IQ (0.0) , \
55 _IQ ( USER_MAX_VS_MAG_PU ) , \
56 _IQ (0.1 * US ER_ MO TO R_M AX _C URR EN T ) , \
57 400 , \
58 _IQ (0.0) , \
59 _IQ (0.0) , \
60 0.0 , \
61 0.0 , \
62 0.0 , \
63 0.0 , \
64 0.0 , \
65 0.0 , \
66 0.0 , \
67 _IQ (0.0) , \
68 _IQ (0.0) , \
69 _IQ (0.0) , \

60
70 _IQ (0.0) , \
71 _IQ (0.0) , \
72 _IQ (0.0) , \
73 _IQ (0.0) , \
74 _IQ (0.8 * USER_MAX_VS_MAG_PU ) , \
75 _IQ (0.0) , \
76 _IQ (0.0) , \
77 _IQ (0.0) , \
78 _IQ (0.0) , \
79 {0 ,0 ,0} , \
80 {0 ,0 ,0} , \
81 ST_VARS_DEFAULTS }
82

83

84 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
85 // the typedefs
86

87 typedef struct _MOTOR_Vars_t_


88 {
89 bool Flag_enableSys ;
90 bool Flag_Run_Identify ;
91 bool F l ag_MotorIdentified ;
92 bool F l ag_e nable Forc eAngl e ;
93 bool F l a g _ e n a b l eF i e l d W e a k e n i n g ;
94 bool Fl ag_enableRsRecalc ;
95 bool F l ag_e nable User Param s ;
96 bool F l ag_e nable Offs etcal c ;
97 bool F l ag_enablePowerWarp ;
98

99 CTRL_State_e CtrlState ;
100 EST_State_e EstState ;
101

102 USER_ErrorCode_e UserErrorCode ;


103

104 CTRL_Version CtrlVersion ;


105

106 _iq IdRef_A ;


107 _iq IqRef_A ;
108 _iq S topSpeedRef_krpm ;
109 _iq SpeedRef_krpm ;
110 _iq SpeedTraj_krpm ;
111 _iq MaxAccel_krpmps ;
112 _iq20 MaxJrk_krpmps2 ;
113 _iq Speed_krpm ;
114 _iq SpeedQEP_krpm ;
115 _iq OverModulation ;
116 _iq R sOnLineCurrent_A ;
117 _iq S v g e n M a xM o d u la t i o n_ t i c ks ;
118 _iq Flux_Wb ;
119 _iq Torque_Nm ;
120

121 float_t MagnCurr_A ;


122 float_t Rr_Ohm ;

61
123 float_t Rs_Ohm ;
124 float_t RsOnLine_Ohm ;
125 float_t Lsd_H ;
126 float_t Lsq_H ;
127 float_t Flux_VpHz ;
128

129 _iq Kp_spd ;


130 _iq Ki_spd ;
131

132 _iq Kp_Idq ;


133 _iq Ki_Idq ;
134

135 _iq Vd ;
136 _iq Vq ;
137 _iq Vs ;
138 _iq VsRef ;
139 _iq VdcBus_kV ;
140

141 _iq Id_A ;


142 _iq Iq_A ;
143 _iq Is_A ;
144

145 MATH_vec3 I_bias ;


146 MATH_vec3 V_bias ;
147

148 ST_Vars_t SpinTAC ;


149

150 } MOTOR_Vars_t ;
151

152 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
153 // the function prototypes
154

155 // The main interrupt service ( ISR ) routine


156 interrupt void mainISR ( void ) ;
157

158 // Updates the global motor variables


159 void u p d a t e G l o b a l V a r i a b l e s _ m o t o r ( CTRL_Handle handle , ST_Handle stHandle ) ;
160

161 // Reset Ls Q format to a higher value when Ls identification starts


162 void CT RL_resetLs_qFmt ( CTRL_Handle handle , const uint_least8_t qFmt ) ;
163

164 // Recalculate Kp and Ki gains to fix the R / L limitation of 2000.0 and Kp


,→ limitation of 0.11
165 void recalcKpKi ( CTRL_Handle handle ) ;
166

167 // Calculates the maximum qFmt value for Ls identification , to get a more
,→ accurate Ls per unit
168 void C T R L _calcMax_Ls_qFmt ( CTRL_Handle handle , uint_least8_t * p_qFmt ) ;
169

170 // Updates Kp and Ki gains in the controller object


171 void updateKpKiGains ( CTRL_Handle handle ) ;
172

173 // Set electrical frequency limit to zero while identifying an induction motor

62
174 void setFeLimitZero ( CTRL_Handle handle ) ;
175

176 // Calculates Dir_qFmt for ACIM


177 void ac im_Dir_qFmtCalc ( CTRL_Handle handle ) ;
178

179 // @ } // defgroup
180 # endif // end of _MAIN_H_ definition

frame

D.2 user.h

user.h file contains the information of the motor and the board used -the parameters that have
been identified from each motor and board in the results Chapter 4-. It also has a lot of defines
such as clock frequencies, voltage and current limits of operation, number of voltage and cur-
rent sensors, encoder characteristics, scale factors for the parameters, etc. Finally, it contains
functions to set and update the parameters and error functions.
The file is very long and only a few parameters are shown. Basically the parameters of
the board and motor, which need to be modified every time the code is loaded to a different
hardware.
1 # ifndef _USER_H_
2 # define _USER_H_
3 ...
4 // Board 2 configured
5 // ADC current offsets for A , B , and C phases
6 # define I_A_offset ( -0.864467204)
7 # define I_B_offset ( -0.866962671)
8 # define I_C_offset ( -0.868413985)
9

10 // ADC voltage offsets for A , B , and C phases


11 # define V_A_offset (0.310694873)
12 # define V_B_offset (0.307737291)
13 # define V_C_offset (0.306734324)
14

15 ...
16

17 // Defines the system clock frequency , MHz


18 # define U SER_SYSTEM_FREQ_MHz (90.0)
19

20 // Defines the Pulse Width Modulation ( PWM ) frequency , kHz


21 # define USER_PWM_FREQ_kHz (45.0)
22 // Defines the Pulse Width Modulation ( PWM ) period , usec
23 # define U SER_PWM_PERIOD_usec (1000.0/ USER_PWM_FREQ_kHz )
24

25 // Defines the Interrupt Service Routine ( ISR ) frequency , Hz


26 # define USER_ISR_FREQ_Hz (( float_t ) USER_PWM_FREQ_kHz * 1000.0 / (
,→ float_t ) U S E R _ N U M _ P W M _ T I C K S _ P E R _ I S R _ T I C K )
27 // Defines the Interrupt Service Routine ( ISR ) period , usec

63
28 # define U SER_ISR_PERIOD_usec ( USER_PWM_PERIOD_usec * ( float_t )
,→ U S E R _ N U M _ P W M _ T I C K S _ P E R _ I S R _ T I C K )
29

30 ...
31

32 // Defines the default bandwidth for SpinTAC Control


33 // multiply it by 20 to convert into Bandwidth
34 # define U SER _SYST EM_B ANDW IDTH (35.0)
35

36 // Define each motor with a unique name and ID number


37 # define MotorKIT 113
38 # define MaxonEC32flat 110
39

40 // Uncomment the motor which should be included at compile


41 // Change manually the parameters for the three MaxonEC32flat motors
42 // # define USER_MOTOR MotorKIT
43 # define USER_MOTOR MaxonEC32flat
44

45 # elif ( USER_MOTOR == MotorKIT )


46 # define USER_MOTOR_TYPE MOTOR_Type_Pm
47 # define U S E R _ M O T O R _ N U M _ P O L E _ P A IR S (4)
48 # define USER_MOTOR_Rr ( NULL )
49 # define USER_MOTOR_Rs (0.41712)
50 # define USER_MOTOR_Ls_d (0.0006374188)
51 # define USER_MOTOR_Ls_q (0.0006374188)
52 # define U SER _MOTO R_RA TED_ FLUX (0.0351593)
53 # define U S E R _ M O T O R _ M A G N E T I Z I N G _ C U R R E N T ( NULL )
54 # define U S E R _ M O T O R _ R E S _ E S T _ C U R R E N T (1.0)
55 # define U S E R _ M O T O R _ I N D _ E S T _ C U R R E N T ( -1.0)
56 # define U S ER _MO TO R_ MA X_C UR RE NT (5.0)
57 # define U S E R _ M O T O R _ F L U X _ E S T _ F R E Q _ H z (20.0)
58 # define U S E R_ M O T OR _ E N CO D E R _L I N E S (4.0)
59 # define U S E R _ M O T O R _ M A X _ S P E E D _ K RP M (4.0)
60 # define U SER_SYSTEM_INERTIA (0.012)
61

62 # elif ( USER_MOTOR == MaxonEC32flat )


63 // Motor 2 now configured
64 # define USER_MOTOR_TYPE MOTOR_Type_Pm
65 # define U S E R _ M O T O R _ N U M _ P O L E _ P A IR S (4)
66 # define USER_MOTOR_Rr ( NULL )
67 # define USER_MOTOR_Rs (1.793522)
68 # define USER_MOTOR_Ls_d (0.0007479966)
69 # define USER_MOTOR_Ls_q (0.0007479966)
70 # define U SER _MOTO R_RA TED_ FLUX (0.02208626)
71 # define U S E R _ M O T O R _ M A G N E T I Z I N G _ C U R R E N T ( NULL )
72 # define U S E R _ M O T O R _ R E S _ E S T _ C U R R E N T (1.0)
73 # define U S E R _ M O T O R _ I N D _ E S T _ C U R R E N T ( -1.0)
74 # define U S ER _MO TO R_ MA X_C UR RE NT (3)
75 # define U S E R _ M O T O R _ F L U X _ E S T _ F R E Q _ H z (20.0)
76 # define U S E R_ M O T OR _ E N CO D E R _L I N E S (4.0)
77 # define U S E R _ M O T O R _ M A X _ S P E E D _ K RP M (6)
78 # define U SER_SYSTEM_INERTIA (0.0415)
79

64
80 ...
81

82 # endif // end of _USER_H_ definition

frame

D.3 hal.c

hal.c file implements the HAL, where the configuration of the microcontroller’s pins are done.
Due to the length of this file, only the fragments where the QEP module is involved are shown.
1 // enable the PIE interrupts associated with the ADC interrupts
2 PIE_enableAdcInt ( obj - > pieHandle , ADC_IntNumber_1 ) ;
3 // enable the ADC interrupts
4 ADC_enableInt ( obj - > adcHandle , ADC_IntNumber_1 ) ;
5

6 // initialize QEP driver


7 obj - > qepHandle [0] = QEP_init (( void *) QEP1_BASE_ADDR , sizeof ( QEP_Obj ) ) ;
8

9 // setup the QEP


10 HAL_setupQEP ( handle , HAL_Qep_QEP1 ) ;
11

12 // configure the interrupt sources


13 ADC_disableInt ( obj - > adcHandle , ADC_IntNumber_1 ) ;
14 ADC_setIntMode ( obj - > adcHandle , ADC_IntNumber_1 , AD C_Int Mode _Clea rFla g ) ;
15 ADC_setIntSrc ( obj - > adcHandle , ADC_IntNumber_1 , ADC_IntSrc_EOC7 ) ;
16

17 // EQEPA
18 GPIO_setMode ( obj - > gpioHandle , GPIO_Number_20 , GPIO_20_Mode_EQEP1A ) ;
19 G P I O _ s e t Q u al ific ation ( obj - > gpioHandle , GPIO_Number_20 , GPIO_Qual_Sample_3 ) ;
20

21 // EQEPB
22 GPIO_setMode ( obj - > gpioHandle , GPIO_Number_21 , GPIO_21_Mode_EQEP1B ) ;
23 G P I O _ s e t Q u al ific ation ( obj - > gpioHandle , GPIO_Number_21 , GPIO_Qual_Sample_3 ) ;
24

25 // STATUS
26 GPIO_setMode ( obj - > gpioHandle , GPIO_Number_22 , G P I O _ 2 2 _ M o d e _ G e n e r a l P u r p o s e ) ;
27

28 // EQEP1I
29 GPIO_setMode ( obj - > gpioHandle , GPIO_Number_23 , GPIO_23_Mode_EQEP1I ) ;
30 G P I O _ s e t Q u al ific ation ( obj - > gpioHandle , GPIO_Number_23 , GPIO_Qual_Sample_3 ) ;
31

32 // initialize the QEP clock


33 C L K _ e n a b l e Eqep1Clock ( obj - > clkHandle ) ;
34

35 // QEP setup function to be called from main . c


36 void HAL_setupQEP ( HAL_Handle handle , HAL_QepSelect_e qep )
37 {
38 HAL_Obj * obj = ( HAL_Obj *) handle ;
39

40

41 // hold the counter in reset

65
42 QEP_ reset_counter ( obj - > qepHandle [ qep ]) ;
43

44 // set the QPOSINIT register


45 Q E P _ s e t _ p os n_ i ni t _c ou n t ( obj - > qepHandle [ qep ] , 0) ;
46

47 // disable all interrupts


48 Q E P _ d i s a b l e _ a l l _ i n t e r r u p t s ( obj - > qepHandle [ qep ]) ;
49

50 // clear the interrupt flags


51 Q E P _ c l e a r _ a l l _ i n t e r r u p t _ f l a g s ( obj - > qepHandle [ qep ]) ;
52

53 // clear the position counter


54 Q E P _ c l e a r _p os n_ cou nt er ( obj - > qepHandle [ qep ]) ;
55

56 // setup the max position


57 Q E P _ s e t _ m ax _p os n_c ou nt ( obj - > qepHandle [ qep ] , (4* U S E R_ M O T OR _ E N CO D E R _L I N E S ) -1) ;
58

59 // setup the QDECCTL register


60 QE P_ se t_ QEP_source ( obj - > qepHandle [ qep ] , Q E P _Q s r c _Q u a d _C o u n t_ M o d e ) ;
61 Q E P _ d i s a ble_sync_out ( obj - > qepHandle [ qep ]) ;
62 Q E P _ s e t _ s w a p _q u a d _i n p ut s ( obj - > qepHandle [ qep ] , QEP_Swap_Not_Swapped ) ;
63 Q E P _ d i s a b le _g at e_i nd ex ( obj - > qepHandle [ qep ]) ;
64 // Q E P _ e n able _gate _ind ex ( obj - > qepHandle [ qep ]) ;
65 Q E P _ s e t _ e xt _c lo ck_ ra te ( obj - > qepHandle [ qep ] , QEP_Xcr_2x_Res ) ;
66 QE P_ se t_ A_polarity ( obj - > qepHandle [ qep ] , QEP_Qap_No_Effect ) ;
67 QE P_ se t_ B_polarity ( obj - > qepHandle [ qep ] , QEP_Qbp_No_Effect ) ;
68 Q E P _ s e t _ i nd ex _p ola ri ty ( obj - > qepHandle [ qep ] , QEP_Qip_No_Effect ) ;
69

70 // setup the QEPCTL register


71 Q E P_ s e t_ emu_control ( obj - > qepHandle [ qep ] , Q E P C T L _ F r e e s o f t _ U n a f f e c t e d _ H a l t ) ;
72 Q E P _ s e t _ p o s n _ c o u n t _ r e s e t _ m o d e ( obj - > qepHandle [ qep ] , QEPCT L_Pc rm_Ma x_Re set ) ;
73 // Q E P _ s e t _ p o s n _ c o u n t _ r e s e t _ m o d e ( obj - > qepHandle [ qep ] , QE PC T L_ Pc r m_ I nd ex _ Re s et ) ;
74 Q E P _ s e t _ s t r o be _ e v e n t _ i n i t ( obj - > qepHandle [ qep ] , QEPCTL_Sei_Nothing ) ;
75 Q E P _ s e t _ i n d e x_ e v e nt _ i ni t ( obj - > qepHandle [ qep ] , QEPCTL_Iei_Nothing ) ;
76 // Q E P _ s e t_ i n d ex _ e v en t _ i ni t ( obj - > qepHandle [ qep ] , Q E P C T L _ I e i _ R i s i n g _ E d g e _ I n i t ) ;
77 Q E P _ s e t _ i n d e x_ e v e n t _ l a t c h ( obj - > qepHandle [ qep ] , Q EP CTL _I el _R isi ng _E dge ) ;
78 QEP_ set_soft_init ( obj - > qepHandle [ qep ] , QEPCTL_Swi_Nothing ) ;
79 Q E P _ d i s a b le _u ni t_t im er ( obj - > qepHandle [ qep ]) ;
80 Q E P _ d i s a ble_watchdog ( obj - > qepHandle [ qep ]) ;
81

82 // setup the QPOSCTL register


83 Q E P _ d i s a b l e _ po s n _ co m p ar e ( obj - > qepHandle [ qep ]) ;
84

85 // setup the QCAPCTL register


86 Q E P_ d i sa ble_capture ( obj - > qepHandle [ qep ]) ;
87

88 // renable the position counter


89 QE P_ en ab le_counter ( obj - > qepHandle [ qep ]) ;
90

91

92 return ;
93 }

66
frame

67
Appendix E

Results Complement

Here, some issues mentioned in the Results Chapter 4 are clarified for a better understanding
and interpretation.

E.1 Inertia units transformation

The motor inertia is set by the SpinTAC speed controller using its initialization process. The unit
for inertia is P U/(pu/s2 ). Where PU is the user unit for current [A] and pu/s2 is the user unit
for acceleration [krpm/s]. Typically inertia is specified in Kg ∗ m2 or N ∗ m ∗ s2 . This particular
way of expressing the inertia makes it mandatory to scale the real world inertia to enable the
SpinTAC controller use it.
The equation below can be used to convert between inertia specified in Kg ∗ m2 and the
scaled units that are needed for the SpinTAC speed controller [22]:

PU ωN ORM × 2π
Inertia[ pu ]= × Inertia[Kg × m2 ] (E.1)
s2
ϕEM F × AN ORM × P P

where:

• ωN ORM is defined as the scale between frequency in Hz and frequency in pu in the


application

• ϕEM F is defined as the Back EMF in Webers of the motor, which corresponds with the
Flux parameter

• AN ORM is defined as the scale between current in amps and current in PU in the appli-
cation.

• PP is defined as the number of pole pairs in the motor.

68
E.2 Inertia histograms

As seen in Chapter 4, the motors’ inertias have been identified separately from the other param-
eters. In order to identify them, between ten and fifteen measures -depending on the number of
outliers eliminated- have been done with each motor and, to obtain their values, the histograms
here shown have been used. They show the number of times a measure has given a value in
a certain interval.

Nema 17 BLY17 motor

Measure Value
1 0.01465
2 0.01269
3 0.01009
4 0.01777
5 0.01687
6 0.01012
7 0.01775
8 0.01178
9 0.01168
10 0.01034
11 0.01355
12 0.01274
13 0.01168
14 0.01042
Mean 0.01253

Table E.1: BLY17 inertia values table Figure E.1: BLY17 inertia values histogram

Maxon motor 1

Measure Value
1 0.04146
2 0.04141
3 0.04142
4 0.04143
5 0.04143
6 0.04137
7 0.04148
8 0.04142
9 0.04152
10 0.04147
11 0.04138
12 0.04144
Mean 0.04144

Table E.2: EC32Flat 1 inertia values table


Figure E.2: EC32Flat 1 inertia values histogram

69
Maxon motor 2

Measure Value
1 0.04133
2 0.04175
3 0.04178
4 0.04144
5 0.04148
6 0.04133
7 0.04148
8 0.04163
9 0.04152
10 0.04148
11 0.04146
12 0.04154
Mean 0.04153

Table E.3: EC32Flat 2 inertia values table


Figure E.3: EC32Flat 2 inertia values histogram

Maxon motor 3

Measure Value
1 0.04170
2 0.04161
3 0.04164
4 0.04156
5 0.04139
6 0.04158
7 0.04152
8 0.04152
9 0.04168
10 0.04153
11 0.04167
12 0.04149
13 0.04144
Mean 0.04157

Table E.4: EC32Flat 3 inertia values table Figure E.4: EC32Flat 3 inertia values histogram

The histograms have helped choosing more adequate values for de inertia value determi-
nation. This value is used by the control to relate the acceleration of the rotor with the torque
really applied. It also has feedback from the current sensors to add redundancy to this calcula-
tion -the more current delivered to the motor, the more torque applied-. However, as the motors
never have to be forced by any external force, the torque can always be estimated by the rotor’s
angular speed variation.

70
Appendix F

Anaheim BLY17 motor datasheet

71
BLY17 Series - Brushless DC Motors
• 42mm Square Body
• Compact Size and Power Density
• Cost-Effective Replacement for Brush DC Motors
• Long Life and Highly Reliable
FEATURES

• Can Be Customized for:


- Maximum Speed
- Winding Current
- Shaft Options
- Cables and Connectors
• CE Certified and RoHS Compliant

The BLY17 Series Brushless DC Motors come in a compact package with high power density. These motors
are cost-effective solutions to many velocity control applications. They come in four different stack lengths
DESCRIPTION

to provide you with just the right torque for your application. A number of windings are available off-the-shelf
and all the motors can be customized to fit your machine requirements. The motors come in a standard 8-lead
configuration with three wires for the phases and five wires for the hall sensors. We can also customize the
windings to perfectly match your voltage, current, and maximum operating speed. Special shaft modifica-
tions, cables and connectors are also available upon request.

Line to Line to Back Rotor


Rated Rated Rated Peak Rated Torque “L”
Line Line EMF Inertia Weight
Model # Voltage Speed Power Torque Current Constant Length
Resistance Inductance Voltage (oz-in- (lbs)
(V) (RPM) (W) (oz-in) (A) (oz-in/A) (in)
(ohms) (mH) (VkRPM) sec2)
BLY171S-15V-8000 15 8000 26 14 2.2 0.35 0.35 1.98 1.14 0.00034 0.66 1.59
BLY171S-17V-8000 17 8000 42 21 3.6 0.20 0.26 1.98 1.14 0.00034 0.66 1.59
BLY171S-24V-4000 24 4000 26 27 1.8 1.50 2.10 4.96 2.45 0.00034 0.66 1.59
BLY172S-17V-9500 17 9500 70 30 6.4 0.09 0.09 1.56 0.90 0.00068 0.99 2.37
BLY172S-24V-2000 24 2000 41 63.72 3.6 1.60 2.70 8.78 5.00 0.00068 0.99 2.37

BLY172S-24V-4000 24 4000 53 54 3.5 0.80 1.20 5.81 3.35 0.00068 0.99 2.37
BLY173S-24V-4000 24 4000 77 79 4.9 0.46 0.70 5.38 3.10 0.00102 1.43 3.19
SPECIFICATIONS

BLY174S-24V-4000 24 4000 104 106 7.0 0.30 0.50 5.32 3.10 0.001359 1.76 3.95
BLY174S-24V-12000 24 2000 41 38.2 3.6 0.07 0.08 1.97 1.02 0.00068 0.99 2.37
BLY171D-17V-8000 17 8000 42 21 3.6 0.20 0.26 1.98 1.14 0.00034 0.66 1.59
BLY171D-24V-1400 24 1400 9.8 27 0.9 8.00 10.50 10.62 8.42 0.00034 0.66 1.59
BLY171D-24V-2800 24 2800 25 31 2.0 2.78 3.36 6.09 4.57 0.00034 0.66 1.59
BLY171D-24V-4000 24 4000 26 27 1.8 1.50 2.10 4.81 2.7 0.00034 0.66 1.59
BLY171D-24V-6000 24 6000 25 27 1.4 1.15 1.47 3.97 4.00 0.00034 0.66 1.59
BLY172D-24V-2000 24 2000 41 54 3.6 1.40 2.25 7.79 5.66 0.00068 0.99 2.37
BLY172D-24V-4000 24 4000 53 54 3.5 0.80 1.20 5.03 3.1 0.00068 0.99 2.37
BLY173D-24V-4000 24 4000 77 79 4.9 0.46 0.70 5.38 4.14 0.00102 1.43 3.19
BLY173D-160V-4000 160 4000 77 79 0.7 26.67 20.00 36.96 18.83 0.00102 1.43 3.19
BLY174D-24V-4000 24 4000 104 106 7.0 0.30 0.50 5.32 3.1 0.001359 1.76 3.95

BLY174D-24V-12000 24 12000 113 38 5.4 0.07 0.76 1.97 1.02 0.001359 1.76 3.95

BLY174S-24V-12000 24 12000 113 38 5.4 0.07 0.09 2.35 1.55 0.001359 1.76 3.95

Notes:
- Custom leadwires, cables, connectors, and windings are available upon request.
- The 7th character “S” denotes a single shaft, use “D” for double shaft.
- Dual Shaft motors have different mounting dimensions; please see drawings on next page.
L010228
910 East Orangefair Ln. Anaheim, CA 92801 Tel. (714) 992-6990 Fax. (714) 992-0471 www.anaheimautomation.com
(Single Shaft)
DIMENSIONS

(Double Shaft)

Note: All units are in Inches


Notes: Dual Shaft motors have different mounting dimensions.

Wire Color Description Hall Sensor Specifications


WIRING INFORMATIONS

Red Hall Supply Supply Voltage: 4.5VDC to 28VDC


Blue Hall A Current, Ioff: 10mA max
Green Hall B Current, Ion: 11.3mA max
White Hall C Rated Sinking Current: 20mA
Black Hall Ground Saturation Voltage: 0.4VDC max @ 25°C
Yellow Phase A Output Leakage Current: 10μA
Red Phase B
Output Switching Time @ 25°C
Black Phase C Rise, 10% to 90% 1.5μs
Fall, 90% to 10% 1.5μs
Output Type: Open Collector
SPECIFICATIONS

Winding Type: Delta, 8 Poles Max. Radial Force: 28N @ 20mm from the Flange
Hall Effect Angle: 120 Degree Electrical Angle Max. Axial Force: 10N
Shaft Run Out: 0.025mm Insulation Class: Class B
Radial Play: 0.02mm@450g Dielectric Strength: 500VDC for one Minute
End Play: 0.08mm@450g Insulation Resistance: 100MOhm, 500VDC

910 East Orangefair Ln. Anaheim, CA 92801 Tel. (714) 992-6990 Fax. (714) 992-0471 www.anaheimautomation.com
TORQUE CURVES

910 East Orangefair Ln. Anaheim, CA 92801 Tel. (714) 992-6990 Fax. (714) 992-0471 www.anaheimautomation.com
Appendix G

Maxon EC32 Flat motor datasheet

75
EC 32 flat ∅32 mm, brushless, 6 Watt

EC motor
maxon flat
M 1:2
Stock program Part Numbers
Standard program
Special program (on request)

A with Hall sensors 339259 200187 339260 339261


B sensorless 339263 200138 339264 339265
Motor Data
Values at nominal voltage
1 Nominal voltage V 6 9 12 24
2 No load speed rpm 9210 8380 7970 9310
3 No load current mA 186 107 75.6 46.2
4 Nominal speed rpm 3860 3640 3210 4480
5 Nominal torque (max. continuous torque) mNm 7.61 8.89 7.98 9.42
6 Nominal current (max. continuous current) A 1.37 0.929 0.614 0.401
7 Stall torque mNm 15.5 19 15.7 22.8
8 Stall current A 2.73 2 1.19 0.995
9 Max. efficiency % 55 60 57 62
Characteristics
10 Terminal resistance phase to phase W 2.2 4.5 10.1 24.1
11 Terminal inductance phase to phase mH 0.378 1.06 2.04 6.19
12 Torque constant mNm/A 5.67 9.5 13.2 23
13 Speed constant rpm/V 1680 1010 724 416
14 Speed/torque gradient rpm/mNm 651 476 551 437
15 Mechanical time constant ms 94.8 69.3 80.3 63.6
16 Rotor inertia gcm2 13.9 13.9 13.9 13.9
Specifications Operating Range Comments
Thermal data n [rpm] Continuous operation
17
 Thermal resistance housing-ambient 8.25 K/W In observation of above listed thermal resistance
18
 Thermal resistance winding-housing 6.21 K/W
19
 Thermal time constant winding 3.48 s (lines 17 and 18) the maximum permissible wind-
20 Thermal time constant motor 22.1 s ing temperature will be reached during continuous
-40…+100°C
21 Ambient temperature operation at 25°C ambient.
+125°C
22 Max. winding temperature = Thermal limit.
Mechanical data (preloaded ball bearings)
23 Max. speed 12 000 rpm Short term operation

24 Axial play at axial
load < 5.0 N 0 mm The motor may be briefly overloaded (recurring).

> 5.0 N typ. 0.6 mm
25 Radial play preloaded
26 Max. axial load (dynamic) 4.8 N Assigned power rating
27 Max. force for press fits (static) 45 N
(static,
 shaft supported)  1000 N
28 Max. radial load, 15 mm from flange 10.5 N

Other specifications maxon Modular System Overview on page 20–27


4
29 Number of pole pairs
3
30 Number of phases Planetary Gearhead
31 Weight of motor 32 g ∅22 mm
0.5 - 1.0 Nm
Values listed in the table are nominal. Page 329
Connection with Hall sensors sensorless Planetary Gearhead Recommended Electronics:
Pin 1 VHall 3.5…24 VDC Motor winding 1 ∅22 mm Notes Page 26
Pin 2 Hall sensor 3 Motor winding 2 0.5 - 2.0 Nm ESCON Module 24/2 416
Pin 3 Hall sensor 1 Motor winding 3 Page 332 ESCON 36/3 EC 417
Pin 4 Hall sensor 2 neutral point ESCON Mod. 50/4 EC-S 417
Pin 5 GND DEC Module 24/2 420
Pin 6 Motor winding 3 EPOS2 24/2 424
Pin 7 Motor winding 2 EPOS2 Module 36/2 424
Pin 8 Motor winding 1 MAXPOS 50/5 435
Adapter Part number Part number
see p. 437 220300 220310
Connector Part number Part number
Tyco 1-84953-1 84953-4
Molex 52207-1133 52207-0433
Molex 52089-1119 52089-0419
Pin for design with Hall sensors:
FPC, 11-pol, Pitch 1.0 mm, top contact style
Wiring diagram for Hall sensors see p. 37

April 2016 edition / subject to change maxon EC motor 295

1607_EC_motor.indd 295 15.04.16 15:08

You might also like