You are on page 1of 25

W H I T E PA P E R

Eric Thomas,
Applications Engineer,
C2000™ MCUs
Texas Instruments

C2000™ Piccolo™ F2805x


MCU Analog Front End for
Motor Control

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

Figure 1: Analog Front End (AFE). Figure 1:  Analog Front End (AFE) 


Routing current signals
Routing current Before addressing topics covering the implementation and usage of the PGAs and comparators, it is
Before addressing topics covering the implementation and usage of the PGAs and comparators, it is
signals recommended
recommendedto consider
to considerhow
howcurrent
current feedback signals
feedback signals areare routed
routed fromfrom the shunt
the shunt andtothen
and then the to the input
input
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
2
the shunt. There is a significant amount of current flowing through the shunt resistors. Copper traces that
connect the shunts from the bottom of the power device and then to ground become a resistor in series with

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.

Figure 3: Feedback of phase currents using external differential amplifiers.


Figure 3:  Feedback of phase currents using external differential amplifiers. 

Voltage reference Voltage reference


Current can flowconnection
through the shunt in both positive and negative directions which will create both a positive
­connection Current can flow through the shunt in both positive and negative directions which will create both a
and negative voltage that is fed back to the shunt amplifier circuit. Most cost-effective motor inverters do not
positive and negative voltage that is fed back to the shunt amplifier circuit. Most cost-effective motor
inverters do not have both positive and negative power supplies that can handle this bipolar signal. A
have both positive and negative power supplies that can handle this bipolar signal. A bipolar current signal
bipolar current signal is brought into an amplifier that will only be effective from zero to the positive
voltage supply. To allow the unipolar op-amp circuit to measure a bipolar signal, a voltage reference is
is brought into an amplifier that will only be effective from zero to the positive voltage supply. To allow the
summed into the non-inverting side of the current feedback op-amps. The AFE of the F2805x MCUs
contains a 6-bit DAC with a voltage follower for providing an output reference for this reason. A circuit
unipolar op-amp
configuration that cancircuit
use ato measure
voltage a bipolar
reference signal, athe
to measure voltage reference
bipolar is summed
current signal intointhe
is shown non-inverting
Figure 4.
side of the current feedback op-amps. The AFE of the F2805x MCUs contains a 6-bit DAC with a voltage
follower for providing an output reference for this reason. A circuit configuration that can use a voltage
reference to measure the bipolar current signal is shown in Figure 4 on the following page.
Equation 1 shows how to calculate the voltage at VPGA. As an example, set the PGA gain = 3. VADCIN will be
2VBIPOLAR + VREF. Assume the system’s VREFHI is 3.3V. To allow for maximum voltage swing in both directions,
4
VREF is set to 1.65V. Now the maximum peak VBIPOLAR voltage that can be measure is ± 0.825V.

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

Routing voltage signals


Routing voltage In sinusoidal motor-control drives, the voltage signals vary slowly when compared to current signals.
signals In sinusoidal motor control drives, the voltage signals vary slowly when compared to current signals.
Therefore,
Therefore,larger hardware
larger filters
hardware cancan
filters be applied to the
be applied to voltage feedback
the voltage signalsignal
feedback whichwhich
helps helps
to make it less it
to make
less susceptible to noise. Voltage signals are unipolar, so no special circuit and reference have to be
susceptible
used. Lowerto noise.
voltageVoltage
motorssignals
(underare400V
unipolar, so no special circuit and reference have to be used. Lower
DCBUS) typically only require resistor dividers with a capacitive low
pass filter. For a brushless DC motor control, the voltage needs as little phase shift as possible, and
voltage motors (under 400VDCBUS) typically only require resistor dividers with a capacitive low-pass filter. For
therefore, the low-pass filtering depends on the maximum speed achieved by the motor. The only critical
alayout of voltage
brushless feedback
DC motor control,signals is that
the voltage the low-pass
needs filtershift
as little phase capacitor must be
as possible, andlocated as close
therefore, to the AFE
the low-pass
or A/D input pin as possible.
filtering depends on the maximum speed achieved by the motor. The only critical layout of voltage feedback
signals is that the low-pass filter capacitor must be located as close to the AFE or A/D input pin as possible.

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

Motor control system using the Piccolo F2805x MCUs

For the rest of this paper, a sensorless,


Motorfield-oriented
signal control
PGA/ADC(FOC)
input is implemented using the Piccolo
F2805x MCU. The current and voltage signals are brought into the F2805x as below:
Ia A1
I B1
Table 1:  Motor signals and PGA connections 
b

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

AFE amplifier and reference setup


AFE amplifier and The AFE amplifiers and voltage reference are set up to be able to run a permanent magnet synchronous
The
­reference setup AFE amplifiers and voltage reference are set up to be able to run a permanent magnet synchrono
motor with FOC. The sequence that the registers are setup is shown by the flowchart in Figure 5. After the
motor with FOC. The sequence that the registers are setup is shown by the flowchart in Figure 5. After
the AFEAFE
is enabled
is enabledand setup,
and setup, thethe ADCs
ADCs function
function the samethe
as same as any
any Piccolo MCU.Piccolo
For moreMCU. Forabout
information moretheinformation
about the AFE registers, see the technical document.
AFE registers, see the technical document.

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.

Enable M1 PGAs and M2 amplifiers

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

Register Address Channels Controlled Bit Values


A1 0
B1 1
A3 2 0 – disable
PGAEN 0x6412
A6 3 1 – enable

B6 4
B4 5

Table 2: AFE registers used to enable the M1 and M2 amplifier banks.

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.

Register Address Channels Controlled Bit Values


A1 1 to 0
00 -> Gain = 3
AMPM1_GAIN 0x6414 A3 5 to 4 01 -> Gain = 6
10 -> Gain = 11
B1 9 to 8

Table 3: AFE register used to setup the M1 PGA gains.

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.

Register Address Channels Controlled Bit Values


0 – disable
VREFOUTEN 0x6411 VREFOUT 0 1 – enable

Table 4: AFE registers used to enable the voltage reference.

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

Table 5: AFE register used to setup the DAC output voltages.

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

This contains verynow


paper will littlecover
noise FOC
and the majority
motor of the
control sinusoidal
in detail signal
but is usingis itintothe first examples
show harmonic. of Under
howlow theload,
Piccolo
F2805x
there will be less current signal to measure. The PGAs can be of great use to adjust the feedbackbased
MCUs can be used to run a motor control system. Figure 6 shows a general observer gain if
sensorless FOC system that has been programmed in the FLASH of the Piccolo F2805x MCU. Table 6
listssmaller
the motor andsignals
current inverter
needused during
to be this test.
measured. When
Figure observing
8 shows the quality
the current of a FOC
waveform system,
with low load. motor
More line
currents explain a lot about the inverter system. The line currents must be sinusoidal with very few
harmonics – ideally
noise appears nopresent
to be harmonics.on thePoor current
current feedback
waveform. results
By using thein“center-aligned”
a FOC system samplingthat has less controlthe
technique, at
lower speeds. A screen capture of the current waveform of the motor under full load is shown in Figure 7.
Thenoise is filtered
current out ofcontains
feedback the signal. The
very current
little noisethat
andthe
theMCU is sampling
majority is the average
of the sinusoidal of the
signal upper
is in and lower
the first
harmonic. Under low load, there will be less current signal to measure. The PGAs can be of great use to
bounds
adjust of the signal
the feedback shown
gain in Figure
if smaller 8. Even
current with need
signals the switching noise present
to be measured. Figurein the currentthe
8 shows waveform,
current the
waveform with low load. More noise appears to be present on the current waveform. By using the “center-
generalsampling
aligned” signal is technique,
a very smooth the sinusoid.
noise is filtered out of the signal. The current that the MCU is sampling
is the average of the upper and lower bounds of the signal shown in Figure 8. Even with the switching
noise present in the current waveform, the general signal is a very smooth sinusoid.
Motor Anaheim Automation BLY172S-24V-4000

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

Figure 6: FOC block diagram system.Figure 6:  FOC block diagram system. 

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 of the comparator system


9
C2000™ Piccolo™ F2805x MCU Analog Front End for Motor Control May 2013
9
10 Texas Instruments

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.

DAC voltage setup

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

A1 Compare High 1 Comparator Subsystem Filter Subsystem CTRIP Subsystem


0
1
A1 STS latch
0
A1 Compare High 1 A3 STS latch TRIP EPWM
Digital Filter 0 B1 STS latch
1
A1 STS latch
0 0
A3 STS latch
A1out
A1 Compare Low 1 Digital Filter B1 STS latch
1 A3out M1 STS latch 1
0 B1out 0
0 0 GPIO
A1out 1
A1 Compare Low 1
1 OUT block A3out M1 STS latch 1
0 B1out 0
Figure 11: Comparator output logic as setup for the experiment.
Figure 11: Comparator output logic as setup for the experiment. OUT block

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.

Looking closer at the processedLooking


current feedback
closer (Feedback Current) and comparator and(Comparator
Current)Current)
Looking closer at atthe
theprocessed
processed current
currentfeedback (Feedback
feedback (Feedback comparator
and (Comparator
comparator (Comparat
Output) waveforms in Figure 13
Output) shows that
waveforms only when
inFigure
Figure current
13the
shows is flowing
thatpage
only through
when the
current shunt resistor
is current is the shunt resistor
flowingis through
when the comparator output Output)
is valid. waveforms
When noin current13 on
is following
flowing through shows
the that
shuntonly when
resistor, the flowing
feedback through the
when the comparator output is valid. When no current is flowing through the shunt resistor, the feed
amplifier and comparator see zeroresistor
shunt
amplifier current.
is when the comparator
and comparator see zerooutput
current.is valid. When no current is flowing through the shunt resistor,
the feedback amplifier and comparator see zero current.

C2000™ Piccolo™ F2805x MCU Analog Front End for Motor Control May 2013
12 Texas Instruments

Line
Current

Feedback
Current

Comparator
Output

Figure 13: Zoomed-in viewFigure 13:  Zoomed in view of the comparator output from the GPIO. 


of the comparator output from the GPIO.

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));

AFE setup code

// 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”

// 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));

AFE setup // enable the PGA amplifiers


AFE_enablePGA(afeHandle, (AFE_PGAEN_e)(AFE_AMPA1EN \
code | AFE_AMPB1EN \
| AFE_AMPA3EN \
| AFE_AMPB6EN \
| AFE_AMPA6EN \
| AFE_AMPB4EN));

// enable VrefOut
AFE_enableVrefOut(afeHandle);

// set the VrefOut voltage


AFE_setVrefOut(afeHandle,47);

// enable the DACs for the M1 comparators


AFE_enableDAC(afeHandle, (AFE_DACEN_e)(AFE_DAC1EN \
| AFE_DAC2EN));

// set the DAC output voltage


AFE_setDacCtl(afeHandle, AFE_DAC1, (31 + 7));
AFE_setDacCtl(afeHandle, AFE_DAC2, (31 - 8));

// enable the M1 comparators


AFE_enableComp(afeHandle, (AFE_COMPEN_e)(AFE_COMPA1EN \
| AFE_COMPA3EN \
| AFE_COMPB1EN));

// 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));

// Enable the M1 CTRIP output to the GPIO


AFE_setM1CtripOut(afeHandle, (AFE_CTRIPMxOCTL_FIELDS_e)(AFE_CTRIPA1OUTEN));
14 Texas Instruments

AFE driver afe.c


code // **************************************************************************
// the includes

#include “sw/drivers/afe/src/32b/f28x/f2805x/afe.h”

// **************************************************************************
// the functions

// current sampled last


AFE_Handle AFE_init(void *pMemory,const size_t numBytes)
{
AFE_Handle afeHandle;

if(numBytes < sizeof(AFE_Obj))


return((AFE_Handle)NULL);

// assign the handle


afeHandle = (AFE_Handle)pMemory;

return(afeHandle);
} // end of AFE_init() function

AFE header afe.h


code #ifndef _AFE_H_
#define _AFE_H_

//! \file ~/dmc_dev/sw/drivers/afe/src/32b/f28x/f2803x/afe.h


//! \brief Contains public interface to various functions related
//! to the analog front end (AFE) object
//!
//! (C) Copyright 2011, Texas Instruments, Inc.

// **************************************************************************
// 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

//! \brief Defines the base address of the analog-to-digital converter


//! (ADC) registers
//!
#define AFE_BASE_ADDR (0x006400)

// **************************************************************************
// the typedefs

//! \brief Enumeration to define the afe amplifier enable number


//!
typedef enum
{
AFE_AMPB7EN=(1 << 6), //!< Denotes that the pga amplifier for adc B7 is enabled
AFE_AMPB6EN=(1 << 5), //!< Denotes that the pga amplifier for adc B6 is enabled
AFE_AMPB4EN=(1 << 4), //!< Denotes that the pga amplifier for adc B4 is enabled
AFE_AMPA6EN=(1 << 3), //!< Denotes that the pga amplifier for adc A6 is enabled
AFE_AMPB1EN=(1 << 2), //!< Denotes that the pga amplifier for adc B1 is enabled
AFE_AMPA3EN=(1 << 1), //!< Denotes that the pga amplifier for adc A3 is enabled
AFE_AMPA1EN=(1 << 0) //!< Denotes that the pga amplifier for adc A1 is enabled
} AFE_PGAEN_e;

//! \brief Enumeration to define the afe amplifier enable number


//!
typedef enum
{
AFE_DAC1EN=(1 << 0), //!< Denotes that DAC 1 is enabled/disabled
AFE_DAC2EN=(1 << 1), //!< Denotes that DAC 2 is enabled/disabled
AFE_DAC3EN=(1 << 2), //!< Denotes that DAC 3 is enabled/disabled
AFE_DAC4EN=(1 << 3), //!< Denotes that DAC 4 is enabled/disabled
AFE_DAC5EN=(1 << 4) //!< Denotes that DAC 5 is enabled/disabled
} AFE_DACEN_e;

//! \brief Enumeration to define the afe DAC number


//!
typedef enum
{
AFE_DAC1=0, //!< Selects DAC1
AFE_DAC2, //!< Selects DAC2
AFE_DAC3, //!< Selects DAC3
AFE_DAC4, //!< Selects DAC4
AFE_DAC5 //!< Selects DAC5
} AFE_DAC_NUMBER_e;

//! \brief Enumeration to define the afe Comparator enable number


//!
typedef enum
{
AFE_COMPB7EN=(1 << 0), //!< Denotes that Comparator B7 is enabled/disabled
AFE_COMPA1EN=(1 << 2), //!< Denotes that Comparator A1 is enabled/disabled
AFE_COMPA3EN=(1 << 4), //!< Denotes that Comparator A3 is enabled/disabled
AFE_COMPB1EN=(1 << 6), //!< Denotes that Comparator B1 is enabled/disabled
AFE_COMPA6EN=(1 << 8), //!< Denotes that Comparator A6 is enabled/disabled

C2000™ Piccolo™ F2805x MCU Analog Front End for Motor Control May 2013
16 Texas Instruments

AFE_COMPB4EN=(1 << 10), //!< Denotes that Comparator B4 is enabled/disabled


AFE_COMPB6EN=(1 << 12) //!< Denotes that Comparator B6 is enabled/disabled
} AFE_COMPEN_e;

//! \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;

//! \brief Defines the analog-to-digital converter (ADC) object


//!
typedef struct _AFE_Obj_
{
uint16_t DACxCTL[0x05]; //!< DAC 1-5 control registers
uint16_t VREFOUTCTL; //!< VREFOUT (DAC6) control
uint16_t rsvd1[0x0A]; //!< Reserved
uint16_t DACEN; //!< DAC Enables
uint16_t VREFOUTEN; //!< VREFOUT Enable
uint16_t PGAEN; //!< Programmable Gain Amplifier Enable
uint16_t COMPEN; //!< Comparator Enable
uint16_t AMPM1_GAIN; //!< Motor Unit 1 PGA Gain controls
uint16_t AMPM2_GAIN; //!< Motor Unit 2 PGA Gain controls
uint16_t AMPPFC_GAIN; //!< PFC PGA Gain controls
uint16_t rsvd2[0x0A]; //!< Reserved
uint16_t ADCINSWITCH; //!< ADC input-select switch control
uint16_t rsvd3[0x07]; //!< Reserved
uint16_t COMPHYSTCTL; //!< Comparator High AND Low hysteresis
enable/disable
uint16_t rsvd4[0x06]; //!< Reserved
uint16_t CTRIPA1ICTL; //!< CTRIPA1 Filter Input & function
Control
uint16_t CTRIPA1FILCTL; //!< CTRIPA1 Filter parameters
uint16_t CTRIPA1FILCLKCTL; //!< CTRIPA1 Filter Sample Clock Control
uint16_t rsvd5; //!< Reserved
uint16_t CTRIPA3ICTL; //!< CTRIPA3 Filter Input & function
Control
uint16_t CTRIPA3FILCTL; //!< CTRIPA3 Filter parameters
uint16_t CTRIPA3FILCLKCTL; //!< CTRIPA3 Filter Sample Clock Control
uint16_t rsvd6; //!< Reserved
uint16_t CTRIPB1ICTL; //!< CTRIPB1 Filter Input & function
Control
uint16_t CTRIPB1FILCTL; //!< CTRIPB1 Filter parameters
uint16_t CTRIPB1FILCLKCTL; //!< CTRIPB1 Filter Sample Clock Control
uint16_t rsvd7[0x02]; //!< Reserved
uint16_t CTRIPM1OCTL; //!< CTRIPM1 CTRIP Filter Output Control
uint16_t CTRIPM1STS; //!< CTRIPM1 CTRIPx outputs status

C2000™ Piccolo™ F2805x MCU Analog Front End for Motor Control May 2013
18 Texas Instruments

uint16_t CTRIPM1FLGCLR; //!< CTRIPM1 CTRIPx flag clear


uint16_t rsvd8[0x10]; //!< Reserved
uint16_t CTRIPA6ICTL; //!< CTRIPA6 Filter Input & function
Control
uint16_t CTRIPA6FILCTL; //!< CTRIPA6 Filter parameters
uint16_t CTRIPA6FILCLKCTL; //!< CTRIPA6 Filter Sample Clock Control
uint16_t rsvd9; //!< Reserved
uint16_t CTRIPB4ICTL; //!< CTRIPB4 Filter Input & function
Control
uint16_t CTRIPB4FILCTL; //!< CTRIPB4 Filter parameters
uint16_t CTRIPB4FILCLKCTL; //!< CTRIPB4 Filter Sample Clock Control
uint16_t rsvd10; //!< Reserved
uint16_t CTRIPB6ICTL; //!< CTRIPB6 Filter Input & function
Control
uint16_t CTRIPB6FILCTL; //!< CTRIPB6 Filter parameters
uint16_t CTRIPB6FILCLKCTL; //!< CTRIPB6 Filter Sample Clock Control
uint16_t rsvd11[0x02]; //!< Reserved
uint16_t CTRIPM2OCTL; //!< CTRIPM2 CTRIP Filter Output Control
uint16_t CTRIPM2STS; //!< CTRIPM2 CTRIPx outputs status
uint16_t CTRIPM2FLGCLR; //!< CTRIPM2 CTRIPx flag clear
uint16_t rsvd12[0x10]; //!< Reserved
uint16_t CTRIPB7ICTL; //!< CTRIPB7 Filter Input & function
Control
uint16_t CTRIPB7FILCTL; //!< CTRIPB7 Filter parameters
uint16_t CTRIPB7FILCLKCTL; //!< CTRIPB7 Filter Sample Clock Control
uint16_t rsvd13[0x0A]; //!< Reserved
uint16_t CTRIPPFCOCTL; //!< CTRIPPFC CTRIPx outputs status
uint16_t CTRIPPFCSTS; //!< CTRIPPFC CTRIPx flag clear
uint16_t CTRIPPFCFLGCLR; //!< CTRIPPFC COMP Test Control
uint16_t rsvd14[0x70]; //!< Reserved
uint16_t LOCKCTRIP; //!< Lock Register for CTRIP Filters
uint16_t rsvd15; //!< Reserved
uint16_t LOCKDAC; //!< Lock Register for DACs
uint16_t rsvd16; //!< Reserved
uint16_t LOCKAMPCOMP; //!< Lock Register for Amplifiers & Com-
parators
uint16_t rsvd17; //!< Reserved
uint16_t LOCKSWITCH; //!< Lock Register for Switches
} AFE_Obj;

//! \brief Defines the analog front end (AFE) handle


//!
typedef struct AFE_Obj *AFE_Handle;

// **************************************************************************
// the globals

// **************************************************************************
// the function prototypes

//! \brief Initializes the analog front end (AFE)


//! \param[in] *pMemory The memory address of the object
//! \param[in] size_t The size of the object in bytes
AFE_Handle AFE_init(void *pMemory,const size_t numBytes);

//! \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;

//set the selection bits


afe->PGAEN |= PgaEnable;

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;

//set the selection bits


afe->PGAEN &= ~PgaEnable;

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;

//set the selection bits


afe->VREFOUTEN |= 0x0001;

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;

//set the selection bits


afe->VREFOUTEN &= ~0x0001;

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

//! \param[in] AFE_Handle A handle to the AFE object


//! \param[in] uint16_t A value from 0 to 63.
inline void AFE_setVrefOut(AFE_Handle afeHandle, uint16_t VrefOutVal)
{
AFE_Obj *afe = (AFE_Obj *)afeHandle;

ENABLE_PROTECTED_REGISTER_WRITE_MODE;

//set the last 6 bits of the Register


afe->VREFOUTCTL = (VrefOutVal & 0x003F);

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;

//set the last 6 bits of the Register


afe->DACxCTL[DacNumber] = (DacOutVal & 0x003F);

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;

//set the selection bits


afe->DACEN |= DacEnable;

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;

//set the selection bits


afe->COMPEN |= CompEnable;

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;

//set the selection bits


afe->COMPHYSTCTL &= ~CompHystEnable;

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;

//set the selection bits


afe->COMPEN &= ~CompEnable;

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;

//set the selection bits


afe->DACEN &= ~DacEnable;

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;

//set the selection bits


afe->COMPHYSTCTL |= CompHystEnable;

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;

//set the selection bits


afe->CTRIPA1ICTL |= (uint16_t)CtripBitFields;

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;

//set the selection bits


afe->CTRIPA3ICTL |= CtripBitFields;

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;

//set the selection bits


afe->CTRIPB1ICTL |= CtripBitFields;

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;

//set the selection bits


afe->CTRIPM1OCTL |= CtripOutBitFields;

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;

//set the selection bits


status = (bool_t)(afe->CTRIPM1STS & (uint16_t)CtripStatusBitFields);

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;

//set the selection bits


afe->CTRIPM1STS |= CtripFlagBitFields;

DISABLE_PROTECTED_REGISTER_WRITE_MODE;

return;
} // end of AFE_clearM1CtripFlag() function

#ifdef __cplusplus
}
#endif // extern “C”

//@} // ingroup

#endif // end of _AFE_H_ definition

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.

© 2013 Texas Instruments Incorporated SPRY234


IMPORTANT NOTICE
Texas Instruments Incorporated and its subsidiaries (TI) reserve the right to make corrections, enhancements, improvements and other
changes to its semiconductor products and services per JESD46, latest issue, and to discontinue any product or service per JESD48, latest
issue. Buyers should obtain the latest relevant information before placing orders and should verify that such information is current and
complete. All semiconductor products (also referred to herein as “components”) are sold subject to TI’s terms and conditions of sale
supplied at the time of order acknowledgment.
TI warrants performance of its components to the specifications applicable at the time of sale, in accordance with the warranty in TI’s terms
and conditions of sale of semiconductor products. Testing and other quality control techniques are used to the extent TI deems necessary
to support this warranty. Except where mandated by applicable law, testing of all parameters of each component is not necessarily
performed.
TI assumes no liability for applications assistance or the design of Buyers’ products. Buyers are responsible for their products and
applications using TI components. To minimize the risks associated with Buyers’ products and applications, Buyers should provide
adequate design and operating safeguards.
TI does not warrant or represent that any license, either express or implied, is granted under any patent right, copyright, mask work right, or
other intellectual property right relating to any combination, machine, or process in which TI components or services are used. Information
published by TI regarding third-party products or services does not constitute a license to use such products or services or a warranty or
endorsement thereof. Use of such information may require a license from a third party under the patents or other intellectual property of the
third party, or a license from TI under the patents or other intellectual property of TI.
Reproduction of significant portions of TI information in TI data books or data sheets is permissible only if reproduction is without alteration
and is accompanied by all associated warranties, conditions, limitations, and notices. TI is not responsible or liable for such altered
documentation. Information of third parties may be subject to additional restrictions.
Resale of TI components or services with statements different from or beyond the parameters stated by TI for that component or service
voids all express and any implied warranties for the associated TI component or service and is an unfair and deceptive business practice.
TI is not responsible or liable for any such statements.
Buyer acknowledges and agrees that it is solely responsible for compliance with all legal, regulatory and safety-related requirements
concerning its products, and any use of TI components in its applications, notwithstanding any applications-related information or support
that may be provided by TI. Buyer represents and agrees that it has all the necessary expertise to create and implement safeguards which
anticipate dangerous consequences of failures, monitor failures and their consequences, lessen the likelihood of failures that might cause
harm and take appropriate remedial actions. Buyer will fully indemnify TI and its representatives against any damages arising out of the use
of any TI components in safety-critical applications.
In some cases, TI components may be promoted specifically to facilitate safety-related applications. With such components, TI’s goal is to
help enable customers to design and create their own end-product solutions that meet applicable functional safety standards and
requirements. Nonetheless, such components are subject to these terms.
No TI components are authorized for use in FDA Class III (or similar life-critical medical equipment) unless authorized officers of the parties
have executed a special agreement specifically governing such use.
Only those TI components which TI has specifically designated as military grade or “enhanced plastic” are designed and intended for use in
military/aerospace applications or environments. Buyer acknowledges and agrees that any military or aerospace use of TI components
which have not been so designated is solely at the Buyer's risk, and that Buyer is solely responsible for compliance with all legal and
regulatory requirements in connection with such use.
TI has specifically designated certain components as meeting ISO/TS16949 requirements, mainly for automotive use. In any case of use of
non-designated products, TI will not be responsible for any failure to meet ISO/TS16949.
Products Applications
Audio www.ti.com/audio Automotive and Transportation www.ti.com/automotive
Amplifiers amplifier.ti.com Communications and Telecom www.ti.com/communications
Data Converters dataconverter.ti.com Computers and Peripherals www.ti.com/computers
DLP® Products www.dlp.com Consumer Electronics www.ti.com/consumer-apps
DSP dsp.ti.com Energy and Lighting www.ti.com/energy
Clocks and Timers www.ti.com/clocks Industrial www.ti.com/industrial
Interface interface.ti.com Medical www.ti.com/medical
Logic logic.ti.com Security www.ti.com/security
Power Mgmt power.ti.com Space, Avionics and Defense www.ti.com/space-avionics-defense
Microcontrollers microcontroller.ti.com Video and Imaging www.ti.com/video
RFID www.ti-rfid.com
OMAP Applications Processors www.ti.com/omap TI E2E Community e2e.ti.com
Wireless Connectivity www.ti.com/wirelessconnectivity

Mailing Address: Texas Instruments, Post Office Box 655303, Dallas, Texas 75265
Copyright © 2013, Texas Instruments Incorporated

You might also like