Professional Documents
Culture Documents
Eric Thomas,
Applications Engineer,
C2000™ MCUs
Texas Instruments
Abstract Introduction
The C2000™ Piccolo™ TMS320F2805x In motor control inverter applications, motor line current and/or phase voltage are required by
microcontroller (MCU) is the first C2000 the processor’s motor algorithm. Before these analog signals are sampled by the processor,
MCU to include integrated programmable all signals are processed by an analog circuit. The external analog circuits add component
gain amplifiers (PGAs) and windowed cost and increase board size. The Piccolo F2805x series of C2000 real-time control MCUs
comparators as part of a larger analog addresses this issue by adding internal analog conditioning components for the motor
conditioning subsystem, called the analog feedback signals, called the analog front end (AFE). This document will cover the application
front end (AFE). The AFE can benefit motor- of the AFE to motor control, specifically:
based applications through lowered bill
of materials costs, increased application • The AFE block diagram
performance, reduced design complexity • Circuit layout considerations for the feedback signals
and decreased board area. This paper • Using the programmable gain amplifiers (PGA) for current feedback
will provide a technical introduction to the • Adjusting current protection with the internal comparators and digital-to-analog converters
AFE of the Piccolo TMS320F2805x MCU (DACs)
and provide technical guidance in the
context of motor-based application design. The whole AFE block diagram is shown in Figure 1 on the following page. The AFE contains
blocks of programmable gain amplifiers, fixed gain amplifiers, DACs, analog switches and
comparators. The Piccolo F2805x has been designed to control both trapezoidal and sinusoidal
motors, provide fault detection, and power factor correction control. For more detailed
information about the Piccolo F2805x MCUs, you may refer to the technical reference
manual.
2 Texas Instruments
C2000™ Piccolo™ F2805x MCU Analog Front End for Motor Control May 2013
Texas Instruments 3
of the PGA. When a shunt resistor is used to measure line current, its value must be small to reduce the
amount of power dissipated in the shunt. Because the value is small, so is the resulting voltage drop
across the shunt. There is a significant amount of current flowing through the shunt resistors. Copper
traces that connect
the shunt. the shunts
The parasitic fromthat
resistance the forms
bottomonofthethe power
copper device
trace mustand then to
be taken ground
into becomewhen
consideration a resistor
in series with the shunt. The parasitic resistance that forms on the copper trace must be taken into
measuring motor
consideration whenline currents motor
measuring with a shunt resistor. with a shunt resistor.
line currents
Figure 2: Current signal routing directly to the PGAs with single-ended connections.
Figure 2: Current signal routing directly to the PGAs with single‐ended connections.
The AFE can have up to three different grounds. The Piccolo F2805x MCUs have multiple groups of
The blocks.
amplifier AFE canEach
have up to three
group different grounds.
of amplifiers The Piccolo
has a different F2805x
ground. M1 MCUs
groundhave multiple
is used for groups of of three
the group
PGAs that will feedback three-phase motor currents for this paper. For systems with power factor
amplifier(PFC),
correction blocks.there
Each is
group of amplifiers
another has aand
single PGA different ground.
its ground is M1
PFCground is used
ground. The for thegain
fixed groupamplifier
of three
block uses M2 ground for its reference and is used in this paper for three motor voltage feedbacks.
PGAs that will feedback three-phase motor currents for this paper. For systems with power factor correction
Two options
(PFC), thereforis the feedback
another single of motor
PGA and shunt current
its ground signals
is PFC to The
ground. the M1fixedPGA
gain block of the
amplifier AFE
block areM2
uses
discussed. The first option is to use only the internal op-amps for the current feedback as shown in Figure
2. All threefor
ground op-amps share
its reference theis same
and used inground for the
this paper inverting
for three motorinput, andfeedbacks.
voltage therefore, a differential signal of
the shunt current cannot be created. With single-ended signals, careful layout must be done when
Two options
grounding the shuntsfor thetofeedback
reduce the of motor
amount shunt current signals
of differing to the M1 PGA
trace resistance block of
between the AFEWhat
shunts. are is advised
is to have the shunt grounds to be as close together as possible. A trace must run from the point that the
discussed.
shunts come The first option
together to theisM1gnd
to use only thethe
pin of internal op-amps
integrated for the
circuit. current common
Because feedback mode
as shown in Figure
noise can be
added to the amplifier, the M1gnd pin and PGA inputs must be made as short as possible. The three-
2. All three op-amps share the same ground for the inverting input, and therefore, a differential signal of the
phase current traces must be routed as close to the M1gnd trace as possible to reduce the size of the
Faraday loop. The
shunt current cannotFaraday loop isWith
be created. created around the
single-ended phase
signals, current
careful trace
layout mustthat
be starts from grounding
done when the top of the
shunt to the IC and then back on the M1gnd trace to the bottom of the shunt, through the shunt and back
to the
the top
shuntsof the shunt. the amount of differing trace resistance between shunts. What is advised is to have
to reduce
Thethe shunt grounds
second, to be
and most as close together
noise-immune as possible.
option, is to useAexternal
trace must run frominthe
op-amps point that the
a differential shunts come
amplifier
configuration. A true Kelvin connection can feedback directly to the differential amplifier, and then the
together to the M1gnd pin of the integrated circuit. Because common mode noise can be added to the
amplifier, the M1gnd pin and PGA inputs must be made as short as possible. The three-phase current traces
must be routed as close to the M1gnd trace as possible to reduce the size of the Faraday loop. The Faraday
3
loop is created around the phase current trace that starts from the top of the shunt to the IC and then back
on the M1gnd trace to the bottom of the shunt, through the shunt and back to the top of the shunt.
The second, and most noise-immune option, is to use external op-amps in a differential amplifier
configuration. A true Kelvin connection can feedback directly to the differential amplifier, and then the output
C2000™ Piccolo™ F2805x MCU Analog Front End for Motor Control May 2013
4 Texas Instruments
of the differential amplifier is sent into the PGA input. Figure 3 shows a typical layout when using external
differential op-amps. Since the Kelvin connection has low impedance and is a truly differential signal, it
provides excellent noise immunity. The external op-amp circuit converts the differential circuit into a single-
ended
output output.
of the The single-ended
differential output
amplifier is sent intoisthe
more
PGA susceptible to noise;
input. Figure 3 showstherefore,
a typical itlayout
is best to place
when usingthe output
external differential op-amps. Since the Kelvin connection has low impedance and is a truly differential
of the
signal, op-amp excellent
it provides as close to the immunity.
noise AFE input The
of the processor.
external op-amp circuit converts the differential circuit
into a single-ended output. The single-ended output is more susceptible to noise; therefore, it is best to
place Why use the
the output of PGAs when as
the op-amp external amplifiers
close to the AFE are
inputalready being used? One case would be if many different
of the processor.
Whycurrent rated
use the PGAs motors
whenare powered
external with the
amplifiers aresame inverter.
already being Amplification of the
used? One case current
would signaldifferent
be if many can be adjusted
current rated motors are powered with the same inverter. Amplification of the current signal can be
to besttosuit
adjusted bestthe motor
suit size that
the motor size is controlled.
that The The
is controlled. output of the
output PGAPGA
of the block is the
block input
is the of the
input comparator
of the
comparator windows. The PGA still needs to be connected to enable the use of the fault detection
windows. The PGA still needs to be connected to enable the use of the fault detection circuitry.
circuitry.
2R · (VBIPOLAR – VREF) 2 1
VPGA = + VREF = VBIPOLAR + VREF
(1R + 2R ) 3 3
Equation 1.
C2000™ Piccolo™ F2805x MCU Analog Front End for Motor Control May 2013
Texas Instruments 5
Figure 4: Using the AFE’s built-in voltage reference for measuring a bipolar signal.
Figure 4: Using the AFE’s built in voltage reference for measuring a bipolar signal.
Equation 1 shows how to calculate the voltage at VPGA. As an example, set the PGA gain = 3. VADCIN will
Suppose the same hardware is used and a higher resolution is required. The PGA gain = 6. VADCIN is
be 2VBIPOLAR + VREF. Assume the system’s VREFHI is 3.3V. To allow for maximum voltage swing in both
directions, VREF. is
4VBIPOLAR + 2V set to 1.65V. Now the maximum peak VBIPOLAR voltage that can be measure is +/-
REF VREF must be adjusted to be 0.825V. The maximum peak VBIPOLAR voltage that can be
0.825V.
measured is ± 0.4125V.
2� ∙ ��������� � ���� � 2 1
���� � � ���� � �������� � ���� Equation 1
The voltage reference output is adjusted
�1� � 2�� by3 a 6-bit DAC.3 The VREFOUTCTL register controls the DAC’s
voltage
Supposeoutput
the by Equation
same 2 below.
hardware is used and a higher resolution is required. The PGA gain = 6. VADCIN is
4VBIPOLAR + 2VREF. VREF must be adjusted to be 0.825V. The maximum peak VBIPOLAR voltage that can be
measured is +/- 0.4125V.
V (VREFOUTCTLDACVAL + 1)
VThe = REFHI
REF voltage reference output is adjusted by a 6bit DAC. The VREFOUTCTL register controls the DAC’s
64
voltage output by Equation 2 below.
Equation 2.
������ ∙ ����������������� � 1�
���� � Equation 2
64
Motor-control For the rest of this paper, a sensorless, field-oriented control (FOC) is implemented using the Piccolo F2805x
system using the MCU. The current and voltage signals are brought into the F2805x MCU as below:
Piccolo F2805x MCUs
C2000™ Piccolo™ F2805x MCU Analog Front End for Motor Control May 2013
6 Texas Instruments
Ic A3
Motor Signal PGA/ADC input
Va A6
Ia A1
Ib Vb B6 B1
Ic Vc B4 A3
Va A6
Vb Table 1: Motor signals and PGA connections B6
Vc B4
Figure 5: AFE setup for the motor feedback PGAs and the reference output voltage.
Figure 5: AFE setup for the motor feedback PGAs and the reference output voltage.
PGA and amplifier setup
PGA and The PGAs are divided into groups, and each group contains its own ground. For motor control, up to three
The PGAs are divided into groups, and each group contains its own ground. For motor control, up to
amplifier setup currentfeedbacks
three current feedbacks and three
and voltage
three feedbacks
voltage are needed.
feedbacks Theneeded.
are M1 bank contains
The M1three
bankprogrammable
contains three
programmable
amplifiers,amplifiers,
and the M2 and the M2 three
bank contains bankconstant
contains
gainthree constant
amplifiers. For the gain amplifiers.the
next experiments, For the next
M1 PGAs
experiments, the M1 PGAs will feedback the current waveforms, and the M2 amplifier bank will feedba
will feedback
the voltage signals.the current waveforms, and the M2 amplifier bank will feedback the voltage signals.
Before any of the active components can function in the AFE, they have to be enabled. Registers that
Enable M1 PGAs Before any of the active components can function in the AFE, they have to be enabled. Registers that pertain
pertain to enabling the M1 PGAs and the M2 amplifiers are listed in the table below. Setting the
and M2 amplifiers
appropriate address
to enabling to 1
the M1 PGAsenables
and thethe
M2 corresponding
amplifiers are listedamplifier.
in Table 2 below. Setting the appropriate address
to 1 enables the corresponding amplifier.
C2000™ Piccolo™ F2805x MCU Analog Front End for Motor Control May 2013
Texas Instruments 7
B6 4
B4 5
Adjust the The gains of the M1 PGA are controlled by the register AMPM1_GAIN. The gains can be 3, 6 or 11 and are
gains shown in Table 3 below.
VrefOut The voltage output reference is another circuit that takes cost out of a motor-control board design. The
setup voltage reference circuit consists of a programmable, 64-bit DAC and a follower amplifier. The output of the
amplifier is at pin VrefOut/A0. The ADC input A0 can also be used to monitor the voltage reference if needed.
Enable The voltage reference is enabled in the same fashion as the M1 and M2 amplifier banks. The corresponding
VrefOut enable register for VREFOUT is shown in Table 4 below.
Adjust VrefOut The 64-bit programmable DAC is set by the register shown in Table 5 below.
DAC
Register Address Channels Controlled Bit Values
VREFOUTCTL 0x6405 VREFOUT 5 to 0 0 to 0x3F
C2000™ Piccolo™ F2805x MCU Analog Front End for Motor Control May 2013
8 Texas Instruments
FOC system This paper will now cover FOC motor control in detail but is using it to show examples of how the Piccolo
F2805x MCUs can be used to run a motor-control system. Figure 6 shows a general observer-based
sensorless FOC system that has been programmed in the Flash of the Piccolo F2805x MCU. Table 6 lists the
motor and inverter used during this test. When observing the quality of a FOC system, motor-line currents
explain a lot about the inverter system. The line currents must be sinusoidal with very few harmonics – ideally
no harmonics. Poor current feedback results in a FOC system that has less control at lower speeds. A screen
capture of the current waveform of the motor under full load is shown in Figure 7. The current feedback
Table 6: Electronics used to implement the FOC motor control system.
Inverter Texas Instruments DRV8312
MCU
Motor Texas InstrumentsBLY172S‐24V‐4000
Anaheim Automation TMS320F28055
Inverter Texas Instruments DRV8312
Table 6:MCU
ElectronicsTexas Instruments
used to implement the FOC motor control system.
TMS320F28055
C2000™ Piccolo™ F2805x MCU Analog Front End for Motor Control May 2013
Texas Instruments 9
Figure 7: Phase current of the FOC system with the test motor under full load.
Figure 7: Phase current of the FOC system with the test motor under full load.
Figure 7: Phase current of the FOC system with the test motor under full load.
Figure 7: Phase current of the FOC system with the test motor under full load.
Figure 8: Phase current of the FOC system with the test motor under low load.
Figure 8: Phase current of the FOC system with the test motor under low load.
Figure 8: Phase current of the FOC system with the test motor under low load.
Current protection
Figure 8: Phase current of the FOC system with the test motor under low load.
Current protection
The Piccolo F2805x MCU’s AFE contains comparators with accompanying DACs for current fault
Current protection
protection.
TheThis section
Piccolo F2805xwill cover
MCU’s AFEthe setup
contains and use with
comparators of these comparators
accompanying and
DACs for will show
current
The Piccolo F2805x MCU’s AFE contains comparators with accompanying DACs for current fault
an example of
fault protection.
how faults of both positive and negative current can be protected against.
Current protection protection.
ThisThis section
section willthe
will cover cover
setupthe
andsetup
use of and
theseuse of theseand
comparators comparators and willofshow
will show an example an example
how faults of of
how faults of both positive and negative current can be protected against.
Comparator
The Piccolo F2805x MCU’s AFE setupandcomparators
bothcontains
positive negative currentwith accompanying
can be protected against.DACs for current fault
protection. This section will cover
Comparator the setup
setup and use of these comparators and will show an example of
The comparators
how faults of both positive and negative are included
current cantobedetect over-current
protected conditions in the motor inverter. Since each shunt of
against.
the inverter is being measured, the current can flow in both a positive and negative direction. There are
The comparators are included to detect over-current conditions in the motor inverter. Since each shunt of
two comparators for each current feedback allowing detection of both positive and negative flowing
Comparator setup setup
Comparator the inverter is being measured, the detect
current can flowconditions
in both ainpositive and negative direction. There are
currents.The comparators
In the are included
next sections, thetosetup over-current
and some usage cases theofmotor
the inverter. Since each
comparators andshunt
theirof
two comparators for each current feedback allowing detection of both positive and negative flowing
accompanying DACs will be investigated.
The comparators are currents.
includedthe
toinverter
In detect
the nextisover-current
being
sections, theconditions
measured, the current
setup andcanin flow
the usage
some motor
in inverter.
both acases
positiveofandSince
the each
negative shunt
direction.
comparators oftheir
There
and are two
accompanying
the inverter is being measured, the DACs will
current canbeflow
investigated.
in both a positive and negative direction. There are
comparators for each current feedback allowing detection of both positive and negative flowing currents. In
two comparators for each current feedback allowing detectionFilter Subsystem
Comparator Subsystem
of both positive and negative flowing CTRIP Subsystem
currents. In the next sections, the
thenext sections,
setup andthe setup usage
some and some usage of
cases casestheofcomparators
the comparatorsand
and their
theiraccompanying DACs will be
accompanying DACs will beA1 Compare High
investigated.
Comparator Subsystem
investigated.
Filter Subsystem CTRIP Subsystem
1
0
1
A1 Compare High 1 A1 STS latch
0
0 A3 STS latch
Comparator Subsystem Filter Subsystem 1 CTRIP Subsystem
B1 STS latch
Digital Filter A1 STS latch
0
A3 STS latch
0 B1 STS latch
Digital Filter A1out
A1 Compare High 1 A1 Compare Low 1
1 A3out M1 STS latch 1
0 0
0 B1out
A1out 0
1 1STS latch
0
A1 Compare Low 1 A1 A3out M1 STS latch 1
0 1
A3 STS latch B1out TRIP EPWM 0
0 0
Digital Filter B1 STS latch 1
Figure
0 9: Comparator output logic for the M1 system.
A1out
A1 Compare Low 1
1 A3out
Figure 9: Comparator output logic for theM1 STS latch
M1 system. 1
Enable
0 and setup of the comparator system
B1out 0
0
GPIO
1
Enable and setup of the comparator system
Figure 9: Comparator output logic for the M1 system.
Figure 9: Comparator output logic for the M1 system.
Enable and setup Once the analog comparators make a comparison between the DAC input and the current waveform, the
of the comparator output of the comparator is processed and routed by the comparator output logic as shown in Figure 9 on
Once the analog comparators make a comparison between the DAC input and the current waveform, the
system
output the
of the comparator
previous page. Onlyisthe
processed
M1 system,and routed
which by the
contains comparator
comparators for A/Doutput
inputs logic
of A1,as
B1 shown
and A3, in
is Figure 9.
Only the M1 system, which contains comparators for A/D inputs of A1, B1 and A3, is considered in this
considered
write-up. in this
The setup is write-up.
shown in Thethe
setup is shown
steps of theinfigure
the steps of the figure below.
below.
Figure 10: Comparator system setup steps.
Figure 10: Comparator system setup steps.
For an example, the DACs are setup so that the comparator switches when the motor input is at 2A. The
DAC voltage Forfor
equation an example,
setting up thethe
DACs are setup
DAC so that
voltage the comparators
of the comparator switches
is thewhen
sametheas
motor input is 2,
Equation at except
2A. The that the
setup
reference
equation for setting up the DAC voltage of the comparators is the same as Equation 2, except that theis +/- 8.845A
voltage is VDDA. The limit of the motor current feedbacks, for the kit being used,
and the feedback amplifiers are biased at 1.65V (assume a 3.3V VDDA is used). To be able to trip the
reference
comparator voltage
at 2A, theisDAC
VDDA.voltage
The limitreference
of the motor current
must be feedbacks, for the
set to ���6� � kit being
��� used, isvolts.
� � � ����� ± 8.845A and
Setting
�����
Equation
the 3feedback
equal to 2.023V,
amplifiers areassuming
biased at 1.65V
���� = 3.3Va and
(assume 3.3V solving for � To
VDDA is used). results
be ableinto� trip Using a similar
the comparator
� ���
technique for the lower comparator to trip on -2A results in � � ���
at 2A, the DAC voltage reference must be set to (1.65+3.3/8.845) = 2.023 volts. Setting Equation 3 equal
to 2.023V,���� � �� VDDA
assuming � �� = 3.3V and solving for n results in n=38. Using a similar technique for the lower
� � � ���� Equation 3
64
comparator to trip on -2A results in n=23.
Example positive and negative fault setup
VDDAof· routing
The option (n + 1) the comparator output to a GPIO pin is very helpful when debugging faults that
= VDAC
happen. In the
64 experiments to follow, the “OUT” option of the CTRIP setup is enabled to send the
comparator outputs to a GPIO pin. The block diagram of how the system is setup is shown in Figure 11.
Equation 3.
10
C2000™ Piccolo™ F2805x MCU Analog Front End for Motor Control May 2013
Texas Instruments 11
Example positive and The option of routing the comparator output to a GPIO pin is very helpful when debugging faults that happen.
negative fault setup In the experiments to follow, the “OUT” option of the CTRIP setup is enabled to send the comparator outputs
to a GPIOso
The digital filter has been bypassed pin.that
The block
only diagram of how the system
raw comparator is setup
outputs canis be
shown in Figure on
captured 11. the
The digital filter has been
oscilloscope. bypassed so that only raw comparator outputs can be captured on the oscilloscope.
The digital filter has been bypassed so that only raw comparator outputs can be captured on the
oscilloscope.
Comparator Subsystem Filter Subsystem CTRIP Subsystem
Experiment results Figure 11: Comparator output logic as setup for the experiment.
Experiment results The motor was run under load and the line current, processed current feedback and comparator out from the
The motor was run under load and the results
Experiment line current, processed current feedback, and comparator out from
GPIO signals
the GPIO signals were monitored on anwere monitored on Load
oscilloscope. an oscilloscope. Load towas
to the motor the motor was increased
increased so thatso that
the the peak current
peak
The motor
current of the motor was 3A. The was run under load and the line current, processed current feedback, and comparator ou
of thecurrent
motor wasand comparator
3A. The current andwaveforms are shown
comparator waveforms in Figure
are shown 12.
in Figure 12.When thecurrent
When the
the GPIO signals were monitored on an oscilloscope.
current reaches 2A, the upper comparator switches high. When the current reaches -2A the lower Load to the motor was increased so that the p
current of 2A,
reaches thethe
motor
upper was 3A. The
comparator current
switches and
high. Whencomparator
the current waveforms
reaches –2A are
the shown
lower in Figure 12. When
comparator
comparator switches low, but its output is inverted so the result looks the same as the upper comparator.
current reaches 2A, the upper comparator switches high. When the current reaches -2A the lower
switches low,
comparator but its output
switches low,isbut
inverted so the result
its output looks thesosame
is inverted the as the upper
result looks comparator.
the same as the upper compa
Line
Current Line
Current
Feedback
Current Feedback
Current
Comparator
Output Comparator
Output
Figure 12: Comparator output from the GPIO.
Figure 12: Comparator output from the GPIO.
Figure 12: Comparator output from the GPIO.
C2000™ Piccolo™ F2805x MCU Analog Front End for Motor Control May 2013
12 Texas Instruments
Line
Current
Feedback
Current
Comparator
Output
Conclusion Conclusion
The Piccolo F2805x MCU’s AFE can help eliminate external components that are needed in a motor control
inverter.
The When F2805x
Piccolo using the MCU’s
AFE, it is AFE
very important
can help to use proper board
eliminate layoutcomponents
external especially for the
thatcurrent
are needed in a mo
control inverter. When using the AFE, it is very important to use proper board layout especially fo
feedback signals. The AFE setup is straightforward and after it is setup the Piccolo F2805x MCU’s A/D
current feedback signals. The AFE setup is straightforward and after it is setup the Piccolo F2805
A/D inputs
inputs operate
operate in the
in the same same
manner as manner as a Built-in
a Piccolo MCU. Piccolo MCU. Built-in
comparators comparators
allow hardware trippingallow
of the hardware tr
the MCU PWMs or can be output directly out of a GPIO. Each A/D channel contains both an uppe
MCU PWMs
lower or can befor
comparator output directly
bipolar out of a GPIO.detection.
over-current Each A/D channel contains both an upper and lower
comparator for bipolar over-current detection.
Appendix
The AFE code example below is written in C but follows an object-oriented style. The AFE object
Appendix The AFE code
physical example on
peripheral below
theis MCU.
written in C but
First follows
the AFEanhandle
object-oriented style. The
is declared. AnAFE object isofthethe AFE object
instance
passed
physical peripheral on the MCU. First the AFE handle is declared. An instance of the AFE objectfunction
to the newly declared AFE handle by the AFEinit function. Any AFE is passedthat
to is called
corresponding AFE handle as the first parameter in that function call. Any headers that are used
example code below
the newly declared but are
AFE handle notAFEinit
by the listedfunction.
can beAny found in the TI
AFE function thatMotorWare™
is called uses itssoftware package at
corresponding
www.ti.com/motorware.
AFE handle as the first parameter in that function call. Any headers that are used in the example code below
but are not listed can be found in the TI MotorWare™ software package at www.ti.com/motorware.
AFE instantiation
// **************************************************************************
// the includes
#include "sw/drivers/afe/src/32b/f28x/f2805x/afe.h"
// Declare an AFE handle
AFE_Handle afeHandle;
// Pass the handle of the AFE peripheral to the newly declared AFE handle
afeHandle = AFE_init((void *)AFE_BASE_ADDR,sizeof(AFE_Obj));
// enable the PGA amplifiers
C2000™ Piccolo™ F2805x MCU Analog Front End for Motor Control May 2013
Texas Instruments 13
AFE // **************************************************************************
// the includes
instantiation
#include “sw/drivers/afe/src/32b/f28x/f2805x/afe.h”
// Pass the handle of the AFE peripheral to the newly declared AFE handle
afeHandle = AFE_init((void *)AFE_BASE_ADDR,sizeof(AFE_Obj));
// enable VrefOut
AFE_enableVrefOut(afeHandle);
// Bypass the M1 system digital filter, send both high and low of M1 comparator
// outputs to the digital filter subsystem
AFE_setA1CompSubsystem(afeHandle, (AFE_CTRIPxxICTL_FIELDS_e)(AFE_CTRIPOUTBYP \
| AFE_CTRIPBYP \
| AFE_COMPLINPEN \
| AFE_COMPHINPEN \
| AFE_COMPLPOL));
AFE_setB1CompSubsystem(afeHandle, (AFE_CTRIPxxICTL_FIELDS_e)(AFE_CTRIPOUTBYP \
| AFE_CTRIPBYP \
| AFE_COMPLINPEN \
| AFE_COMPHINPEN \
| AFE_COMPLPOL));
AFE_setA3CompSubsystem(afeHandle, (AFE_CTRIPxxICTL_FIELDS_e)(AFE_CTRIPOUTBYP \
| AFE_CTRIPBYP \
| AFE_COMPLINPEN \
| AFE_COMPHINPEN \
| AFE_COMPLPOL));
#include “sw/drivers/afe/src/32b/f28x/f2805x/afe.h”
// **************************************************************************
// the functions
return(afeHandle);
} // end of AFE_init() function
// **************************************************************************
// the includes
// drivers
//#include “sw/drivers/cpu/src/32b/f28x/f2805x/cpu.h”
// **************************************************************************
// modules
#include “sw/modules/math/src/32b/math.h”
#include “sw/modules/types/src/32b/types.h”
#include “sw/drivers/cpu/src/32b/f28x/f2805x/cpu.h”
//!
//! \defgroup AFE
//!
//! \ingroup AFE
//@{
C2000™ Piccolo™ F2805x MCU Analog Front End for Motor Control May 2013
Texas Instruments 15
#ifdef __cplusplus
extern “C” {
#endif
// **************************************************************************
// the defines
// **************************************************************************
// the typedefs
C2000™ Piccolo™ F2805x MCU Analog Front End for Motor Control May 2013
16 Texas Instruments
//! \brief Enumeration to define the afe Comparator hysteresis enable number
//!
typedef enum
{
AFE_COMPB7_HYST_EN=(1 << 6), //!< Denotes that Comparator Hysteresis B7 is
enabled/disabled
AFE_COMPB6_HYST_EN=(1 << 5), //!< Denotes that Comparator Hysteresis B6 is
enabled/disabled
AFE_COMPB4_HYST_EN=(1 << 4), //!< Denotes that Comparator Hysteresis B4 is
enabled/disabled
AFE_COMPB1_HYST_EN=(1 << 3), //!< Denotes that Comparator Hysteresis B1 is
enabled/disabled
AFE_COMPA6_HYST_EN=(1 << 2), //!< Denotes that Comparator Hysteresis A6 is
enabled/disabled
AFE_COMPA3_HYST_EN=(1 << 1), //!< Denotes that Comparator Hysteresis A3 is
enabled/disabled
AFE_COMPA1_HYST_EN=(1 << 0) //!< Denotes that Comparator Hysteresis A1 is
enabled/disabled
} AFE_COMP_HYST_EN_e;
//! \brief Enumeration to define the afe Comparator CTRIP Filter Input and
//! Function Control Registers (CTRIPxxICTL) Fields
//!
typedef enum
{
AFE_CTRIPOUTBYP=(1 << 12),
AFE_CTRIPBYP=(1 << 11),
AFE_COMPLINPEN=(1 << 3),
AFE_COMPHINPEN=(1 << 2),
AFE_COMPLPOL=(1 << 1),
AFE_COMPHPOL=(1 << 0)
} AFE_CTRIPxxICTL_FIELDS_e;
typedef enum
{
AFE_COMP_A1=(0),
AFE_COMP_A3,
AFE_COMP_B1
} AFE_CTRIP_SEL_e;
//! \brief Enumeration to define the afe Comparator CTRIP Filter Input and
//! Function Control Registers (CTRIPxxICTL) Fields
//!
typedef enum
{
AFE_CTRIPOUTLATEN=(1 << 15),
AFE_CTRIPOUTPOL=(1 << 14),
AFE_CTRIPB1OUTEN=(1 << 10),
AFE_CTRIPA3OUTEN=(1 << 9),
AFE_CTRIPA1OUTEN=(1 << 8),
AFE_CTRIPB1EN=(1 << 2),
AFE_CTRIPA3EN=(1 << 1),
AFE_CTRIPA1EN=(1 << 0)
} AFE_CTRIPMxOCTL_FIELDS_e;
C2000™ Piccolo™ F2805x MCU Analog Front End for Motor Control May 2013
Texas Instruments 17
//! \brief Enumeration to define the afe Comparator CTRIP Filter Input and
//! Function Control Registers (CTRIPxxICTL) Fields
//!
typedef enum
{
AFE_CTRIPOUTM1FLG=(1 << 15),
AFE_CTRIPB1FLG=(1 << 10),
AFE_CTRIPA3FLG=(1 << 9),
AFE_CTRIPA1FLG=(1 << 8),
AFE_CTRIPOUTM1STS=(1 << 7),
AFE_CTRIPB1STS=(1 << 2),
AFE_CTRIPA3STS=(1 << 1),
AFE_CTRIPA1STS=(1 << 0)
} AFE_CTRIPMxSTATUS_FIELDS_e;
//! \brief Enumeration to define the afe Comparator CTRIP Filter Input and
//! Function Control Registers (CTRIPxxICTL) Fields
//!
typedef enum
{
AFE_CTRIPOUTM1FLGCLR=(1 << 15),
AFE_CTRIPB1FLGCLR=(1 << 10),
AFE_CTRIPA3FLGCLR=(1 << 9),
AFE_CTRIPA1FLGCLR=(1 << 8)
} AFE_CTRIPMxFLAG_FIELDS_e;
C2000™ Piccolo™ F2805x MCU Analog Front End for Motor Control May 2013
18 Texas Instruments
// **************************************************************************
// the globals
// **************************************************************************
// the function prototypes
//! \brief Enables programmable gain amps for the analog front end (AFE)
//! \param[in] AFE_Handle A handle to the AFE object
//! \param[in] AFE_PGAEN_e An enumeration selecting the PGA input the enable
inline void AFE_enablePGA(AFE_Handle afeHandle, AFE_PGAEN_e PgaEnable)
{
AFE_Obj *afe = (AFE_Obj *)afeHandle;
C2000™ Piccolo™ F2805x MCU Analog Front End for Motor Control May 2013
Texas Instruments 19
ENABLE_PROTECTED_REGISTER_WRITE_MODE;
DISABLE_PROTECTED_REGISTER_WRITE_MODE;
return;
} // end of AFE_EnablePGA() function
//! \brief Disables programmable gain amps for the analog front end (AFE)
//! \param[in] AFE_Handle A handle to the AFE object
//! \param[in] AFE_PGAEN_e An enumeration selecting the PGA input the disable
inline void AFE_disablePGA(AFE_Handle afeHandle, AFE_PGAEN_e PgaEnable)
{
AFE_Obj *afe = (AFE_Obj *)afeHandle;
ENABLE_PROTECTED_REGISTER_WRITE_MODE;
DISABLE_PROTECTED_REGISTER_WRITE_MODE;
return;
} // end of AFE_DisablePGA() function
//! \brief Enables the VrefOut DAC for the analog front end (AFE)
//! \param[in] AFE_Handle A handle to the AFE object
inline void AFE_enableVrefOut(AFE_Handle afeHandle)
{
AFE_Obj *afe = (AFE_Obj *)afeHandle;
ENABLE_PROTECTED_REGISTER_WRITE_MODE;
DISABLE_PROTECTED_REGISTER_WRITE_MODE;
return;
} // end of AFE_EnablePGA() function
//! \brief Disables the VrefOut DAC for for the analog front end (AFE)
//! \param[in] AFE_Handle A handle to the AFE object
inline void AFE_disableVrefOut(AFE_Handle afeHandle)
{
AFE_Obj *afe = (AFE_Obj *)afeHandle;
ENABLE_PROTECTED_REGISTER_WRITE_MODE;
DISABLE_PROTECTED_REGISTER_WRITE_MODE;
return;
} // end of AFE_DisablePGA() function
//! \brief Controls the VrefOut DAC for the analog front end (AFE). Sets the
//! \brief DAC gain by the fraction VREFHI * [1,64]/64;
C2000™ Piccolo™ F2805x MCU Analog Front End for Motor Control May 2013
20 Texas Instruments
ENABLE_PROTECTED_REGISTER_WRITE_MODE;
DISABLE_PROTECTED_REGISTER_WRITE_MODE;
return;
} // end of AFE_setVrefOut() function
//! \brief Controls the comparator DAC for the analog front end (AFE). Sets
//! \the brief DAC gain by the fraction VDDA * [1,64]/64;
//! \param[in] AFE_Handle A handle to the AFE object
//! \param[in] AFE_DAC_NUMBER_e for selecting which DAC to control
//! \param[in] uint16_t A value from 0 to 63.
inline void AFE_setDacCtl(AFE_Handle afeHandle, AFE_DAC_NUMBER_e DacNumber,
uint16_t DacOutVal)
{
AFE_Obj *afe = (AFE_Obj *)afeHandle;
ENABLE_PROTECTED_REGISTER_WRITE_MODE;
DISABLE_PROTECTED_REGISTER_WRITE_MODE;
return;
} // end of AFE_setDacCtl() function
//! \brief Enables DAC outputs for the analog front end (AFE)
//! \param[in] AFE_Handle A handle to the AFE object
//! \param[in] AFE_DACEN_e An enumeration selecting the DAC output the enable
inline void AFE_enableDAC(AFE_Handle afeHandle, AFE_DACEN_e DacEnable)
{
AFE_Obj *afe = (AFE_Obj *)afeHandle;
ENABLE_PROTECTED_REGISTER_WRITE_MODE;
DISABLE_PROTECTED_REGISTER_WRITE_MODE;
return;
} // end of AFE_enableDAC() function
//! \brief Enables Comparators for the analog front end (AFE)
//! \param[in] AFE_Handle A handle to the AFE object
//! \param[in] AFE_COMPEN_e An enumeration selecting the Comparator to enable
inline void AFE_enableComp(AFE_Handle afeHandle, AFE_COMPEN_e CompEnable)
{
AFE_Obj *afe = (AFE_Obj *)afeHandle;
ENABLE_PROTECTED_REGISTER_WRITE_MODE;
C2000™ Piccolo™ F2805x MCU Analog Front End for Motor Control May 2013
Texas Instruments 21
DISABLE_PROTECTED_REGISTER_WRITE_MODE;
return;
} // end of AFE_enableComp() function
//! \brief Enables Hysteresis for the Comparators for the analog front end
(AFE)
//! \param[in] AFE_Handle A handle to the AFE object
//! \param[in] AFE_COMP_HYST_EN_e An enumeration selecting the Comparator
Hysteresis to enable
inline void AFE_enableCompHyst(AFE_Handle afeHandle, AFE_COMP_HYST_EN_e
CompHystEnable)
{
AFE_Obj *afe = (AFE_Obj *)afeHandle;
ENABLE_PROTECTED_REGISTER_WRITE_MODE;
DISABLE_PROTECTED_REGISTER_WRITE_MODE;
return;
} // end of AFE_enableCompHyst() function
//! \brief Disables Comparators for the analog front end (AFE)
//! \param[in] AFE_Handle A handle to the AFE object
//! \param[in] AFE_COMPEN_e An enumeration selecting the Comparator to enable
inline void AFE_disableComp(AFE_Handle afeHandle, AFE_COMPEN_e CompEnable)
{
AFE_Obj *afe = (AFE_Obj *)afeHandle;
ENABLE_PROTECTED_REGISTER_WRITE_MODE;
DISABLE_PROTECTED_REGISTER_WRITE_MODE;
return;
} // end of AFE_disableComp() function
//! \brief Disables DAC outputs for the analog front end (AFE)
//! \param[in] AFE_Handle A handle to the AFE object
//! \param[in] AFE_DACEN_e An enumeration selecting the DAC output the enable
inline void AFE_disableDAC(AFE_Handle afeHandle, AFE_DACEN_e DacEnable)
{
AFE_Obj *afe = (AFE_Obj *)afeHandle;
ENABLE_PROTECTED_REGISTER_WRITE_MODE;
DISABLE_PROTECTED_REGISTER_WRITE_MODE;
return;
} // end of AFE_disableDAC() function
C2000™ Piccolo™ F2805x MCU Analog Front End for Motor Control May 2013
22 Texas Instruments
//! \brief Disables Hysteresis for the Comparators for the analog front end
(AFE)
//! \param[in] AFE_Handle A handle to the AFE object
//! \param[in] AFE_COMP_HYST_EN_e An enumeration selecting the Comparator Hys-
teresis to disable
inline void AFE_disableCompHyst(AFE_Handle afeHandle, AFE_COMP_HYST_EN_e
CompHystEnable)
{
AFE_Obj *afe = (AFE_Obj *)afeHandle;
ENABLE_PROTECTED_REGISTER_WRITE_MODE;
DISABLE_PROTECTED_REGISTER_WRITE_MODE;
return;
} // end of AFE_disableCompHyst() function
//! \brief Sets the A1 Comparator Subsystem settings for the analog front end
(AFE)
//! \param[in] AFE_Handle A handle to the AFE object
//! \param[in] AFE_CTRIPxxICTL_FIELDS_e A single or or’d list of enumerations
selecting the
//! Comparator input settings
inline void AFE_setA1CompSubsystem(AFE_Handle afeHandle, AFE_CTRIPxxICTL_FIELDS_e
CtripBitFields)
{
AFE_Obj *afe = (AFE_Obj *)afeHandle;
ENABLE_PROTECTED_REGISTER_WRITE_MODE;
DISABLE_PROTECTED_REGISTER_WRITE_MODE;
return;
} // end of AFE_setA1CompSubsystem() function
//! \brief Sets the A3 Comparator Subsystem settings for the analog front end
(AFE)
//! \param[in] AFE_Handle A handle to the AFE object
//! \param[in] AFE_CTRIPxxICTL_FIELDS_e A single or or’d list of enumerations
selecting the Comparator
//! input settings
inline void AFE_setA3CompSubsystem(AFE_Handle afeHandle, AFE_CTRIPxxICTL_FIELDS_e
CtripBitFields)
{
AFE_Obj *afe = (AFE_Obj *)afeHandle;
ENABLE_PROTECTED_REGISTER_WRITE_MODE;
DISABLE_PROTECTED_REGISTER_WRITE_MODE;
return;
} // end of AFE_setA3CompSubsystem() function
C2000™ Piccolo™ F2805x MCU Analog Front End for Motor Control May 2013
Texas Instruments 23
//! \brief Sets the B1 Comparator Subsystem settings for the analog front end
(AFE)
//! \param[in] AFE_Handle A handle to the AFE object
//! \param[in] AFE_CTRIPxxICTL_FIELDS_e A single or or’d list of enumerations se-
lecting the Comparator
//! input settings
inline void AFE_setB1CompSubsystem(AFE_Handle afeHandle, AFE_CTRIPxxICTL_FIELDS_e
CtripBitFields)
{
AFE_Obj *afe = (AFE_Obj *)afeHandle;
ENABLE_PROTECTED_REGISTER_WRITE_MODE;
DISABLE_PROTECTED_REGISTER_WRITE_MODE;
return;
} // end of AFE_setB1CompSubsystem() function
//! \brief Sets the Comparator Trip Out settings for the M1 block for the
analog front end (AFE)
//! \param[in] AFE_Handle A handle to the AFE object
//! \param[in] AFE_CTRIPMxOCTL_FIELDS_e A single or or’d list of enumerations
selecting the Comparator
//! out settings
inline void AFE_setM1CtripOut(AFE_Handle afeHandle, AFE_CTRIPMxOCTL_FIELDS_e
CtripOutBitFields)
{
AFE_Obj *afe = (AFE_Obj *)afeHandle;
ENABLE_PROTECTED_REGISTER_WRITE_MODE;
DISABLE_PROTECTED_REGISTER_WRITE_MODE;
return;
} // end of AFE_setM1CtripOut() function
//! \brief Returns the TRUE/FALSE status of the M1 Comparator Trip flags for
the analog
//! \brief front end (AFE)
//! \param[in] AFE_Handle A handle to the AFE object
//! \param[in] AFE_CTRIPMxSTATUS_FIELDS_e A single enumeration selecting a single
Comparator
//! Status Flag to poll
//! \return bool_t Boolean result of whether the status flag is set or clear
inline bool_t AFE_getM1CtripStatus(AFE_Handle afeHandle, AFE_CTRIPMxSTATUS_FIELDS_e
CtripStatusBitFields)
{
AFE_Obj *afe = (AFE_Obj *)afeHandle;
bool_t status = FALSE;
ENABLE_PROTECTED_REGISTER_WRITE_MODE;
C2000™ Piccolo™ F2805x MCU Analog Front End for Motor Control May 2013
24 Texas Instruments
DISABLE_PROTECTED_REGISTER_WRITE_MODE;
return (status);
} // end of AFE_getM1CtripStatus() function
//! \brief Clears the Comparator Trip Flags for the analog front end (AFE)
//! \param[in] AFE_Handle A handle to the AFE object
//! \param[in] AFE_CTRIPMxFLAG_FIELDS_e A single or or’d list of enumerations
selecting the Comparator
//! flags to reset
inline void AFE_clearM1CtripFlag(AFE_Handle afeHandle, AFE_CTRIPMxFLAG_FIELDS_e
CtripFlagBitFields)
{
AFE_Obj *afe = (AFE_Obj *)afeHandle;
ENABLE_PROTECTED_REGISTER_WRITE_MODE;
DISABLE_PROTECTED_REGISTER_WRITE_MODE;
return;
} // end of AFE_clearM1CtripFlag() function
#ifdef __cplusplus
}
#endif // extern “C”
//@} // ingroup
Important Notice: The products and services of Texas Instruments Incorporated and its subsidiaries described herein are sold subject to TI’s standard terms and
conditions of sale. Customers are advised to obtain the most current and complete information about TI products and services before placing orders. TI assumes no
liability for applications assistance, customer’s applications or product designs, software performance, or infringement of patents. The publication of information
regarding any other company’s products or services does not constitute TI’s approval, warranty or endorsement thereof.
Mailing Address: Texas Instruments, Post Office Box 655303, Dallas, Texas 75265
Copyright © 2013, Texas Instruments Incorporated