GTM Ip An011 DPLL v04
GTM Ip An011 DPLL v04
Date: 03.07.2012
(Released)
03.07.2012
Automotive Electronics
LEGAL NOTICE
© Copyright 2012 by Robert Bosch GmbH and its licensors. All rights reserved.
Revision History
Issue Date Remark
0.1 26.08.2011 Initial version
0.2 16.09.2011 Fixes
0.3 06.12.2011 Update for GTM-IP Specification v1.5.0
0.4 03.07.2012 Update for GTM-IP Specification v1.5.4
Conventions
The following conventions are used within this document.
ARIAL BOLD CAPITALS Names of signals
Arial bold Names of files and directories
Courier bold Command line entries
Courier Extracts of files
References
This document refers to the following documents.
Ref Authors(s) Title
1 AE/EIN2 GTM-IP Specification v1.5.4
Table of Contents
1 Overview ....................................................................................................... 1
1.1 System architecture ......................................................................................... 1
2 GTM Infrastructure setup ............................................................................ 3
2.1 Overview .......................................................................................................... 3
2.2 Clock Management Unit (CMU) Setup ............................................................ 3
2.3 Time Base Unit (TBU) Setup ........................................................................... 4
2.4 Timer Input Module (TIM0) Setup.................................................................... 4
2.4.1 TIM0 Filter configurations ............................................................................. 5
2.4.2 TIM0 Signal sampling configuration.............................................................. 7
2.5 MAP Setup....................................................................................................... 7
3 DPLL Configuration ..................................................................................... 8
3.1 Overview .......................................................................................................... 8
3.2 Micro tick generation........................................................................................ 9
3.3 DPLL RAM Organization ............................................................................... 10
3.3.1 Overview ..................................................................................................... 10
3.3.2 Calculation of the RAM2 pointers ............................................................... 12
3.3.3 TRIGGER and STATE Input signal profiles................................................ 12
3.4 Action calculations ......................................................................................... 13
4 Sample implementation............................................................................. 14
4.1 Use case ........................................................................................................ 14
4.1.1 Application parameters ............................................................................... 14
4.1.2 Testbench setup.......................................................................................... 14
4.2 Infrastructural submodules configuration ...................................................... 16
4.2.1 CMU Configuration...................................................................................... 16
4.2.2 TBU Configuration....................................................................................... 17
4.2.3 TIM0 Configuration...................................................................................... 18
4.2.4 MAP Configuration ...................................................................................... 18
4.3 DPLL Configuration ....................................................................................... 18
4.3.1 DPLL Control 0 register configuration......................................................... 20
4.3.2 DPLL Control 1 register configuration......................................................... 21
4.4 Application implementation............................................................................ 22
4.4.1 Main thread implementation........................................................................ 22
4.4.2 Application note hookup.............................................................................. 23
4.4.3 DPLL Profile synchronization...................................................................... 24
4.4.4 DPLL Lock detection ................................................................................... 26
1 Overview
This application note describes the basic principles and usage of the GTM-IP
submodule DPLL. Due to the complexity of the DPLL and its various configuration
possibilities this application note can only be a starting point for further notes.
This application note starts with an introduction to the principles and explains the
various submodules which are involved in the Micro Tick generation for an external
input signal.
TBU_TS1
sub_inc1c
sub_inc1
dir
DPLL_WRADDR0
DPLL_WRADDR1
RAM1BC RAM2
DPLL_WRADDR23
The DPLL is able to generate a high frequency micro tick signal on behalf of one or
more input signals with a lower frequency. These input signals have to be connected
to the TIM0 submodule. In principle, there are two possibilities to provide input
signals to the DPLL.
The first possibility, also shown in the figure above, is to connect the TIM0 channel 0
via the MAP submodule with the TRIGGER input signal of the DPLL and as an option
one of the five TIM0 inputs TIM0 channel 1 to channel 5 via a multiplexer implement
in the MAP to the STATE input of the DPLL.
To generate the micro ticks the DPLL needs information about the timing behaviour
of the input signals. This is done with time stamps that are provided by the Time
Base Unit (TBU). The TBU generates these time stamps with a clock signal that is
generated inside of the Clock Management Unit (CMU).
The DPLL generates the micro ticks at output signals which are connected to the
TBU and the CMU. Figure 1.1 shows the two micro tick signals sub_inc1 and
sub_inc1c, where the sub_inc1c is connected to the TBU and the sub_inc1 is
connected to the CMU. The difference between sub_inc1c and sub_inc is that the
signal sub_inc1c may stop on specific conditions of the associated input signal while
the signal sub_inc provides continues micro ticks. In general, the DPLL can generate
a second group of micro tick signals sub_inc2c and sub_inc2 which are not shown in
the figure.
For the micro tick generation and other calculations, the DPLL uses internal ALUs
and external RAMs, holding data for the calculations. RAM1a is used for action
calculations. Action calculation means that there can be requests coming from the
ARU where time points and angle points in the future have to be predicted by the
DPLL on behalf of the input signals.
RAM1bc holds calculation parameters for the DPLL, to do calculations for the
TRIGGER and STATE inputs and it holds STATE input characteristic values. RAM2
is used to store TRIGGER input signal characteristics.
In the subsequent chapters the configuration of the GTM-IP infrastructural
components for the DPLL and the DPLL configuration itself are explained.
2.1 Overview
For the micro tick generation application the DPLL needs several other GTM-IP
submodules that produce useable infrastructure and input signals. Setup of these
submodules is described in more detail in the next upcoming sections.
CMU
EGU
3 CMU_ECLKx
CMU_CLK6
sub_inc2
sub_inc1 CMU_CLK7
FXU
5 CMU_FXCLKx
The user has to choose several CMU prescalers and configure these prescalers in a
certain manner. First, the TBU needs a clock for the time stamp generation with
which the TIM0 input signals are characterized and send to the DPLL. Therefore, the
prescaler setup determines the granularity of the time stamps and since the chosen
time stamp clock is also feed to the DPLL this prescaler determines the micro tick
generation resolution.
A second important clock prescaler is the one connected to the clock signal
CMU_CLK0. The CMU_CLK0 frequency is always used by the DPLL to generate
missing micro ticks or to correct micro ticks if configured and necessary.
Last, please note, that the two clock signal lines CMU_CLK6 and CMU_CLK7 can be
used to distribute the micro ticks sub_inc2 and sub_inc1 generated by the DPLL to
the other submodules of the GTM-IP. Since these two clock signals are not
stopped on specific input signal conditions by the DPLL, these two signal lines
should not be provided to the TBU as a clock signal. For this purpose a second
input path to the TBU exists.
Please note, that for the channel 1 time base the sub_inc1c input clock should be
chosen by bit CH_MODE of the TBU channels control register. This is done by
selecting the Forward/Backward Counter Mode. Although the sub_inc1 clock can be
selected via CMU_CLK7, it is not recommended to use this clock as input since it
does not exactly reflect the input behavior of the engine.
TBU_TS0
The 49 bit wide signal TIM0_CH is connected via the MAP submodule to the DPLL.
To work properly, the DPLL needs specific settings inside the corresponding TIM
channel. This is on one hand the filtering and on the other hand the time stamp
format sampled inside of the TIM channel.
The figure shows a time input filter for the rising edge which is configured in Up/Down
Counter Mode. The filter threshold is given by value FLT_RE. At the bottom of the
picture, the running time base TBU_TS0 is shown. As it can be observed, depending
on the input signal characteristic, the real edge of the input signal F_IN_SYNC can
be at TBU_TS01. Since the filter delays the input signal until the filter threshold is
reached, the DPLL will see the time stamp TBU_TS03. This introduces an error on
the input signal.
The DPLL can correct this error to a certain amount by subtracting the filter threshold
from the time stamp TBU_TS03. This will result in a new corrected time stamp
TBU_TS02 for the rising edge which is closer to the real time stamp TBU_TS01. The
TIM channel sends the filter threshold value together with each edge time stamp to
the DPLL (in the case of Figure 2.4 the values FLT_RE and TBU_TS03 are send to
the DPLL).
The filter correction can be enabled in the DPLL with the IDT and IDS bits in the
DPLL_CTRL_0 register. There, with the IFP bit it can also be defined if the TIM filter
counts on behalf of CMU_CLK ticks or in behalf of sub_inc ticks.
When the filter correction is done on a CMU_CLK tick base, it is important to
configure the filter input clock to be the same as the TBU_TS0 time stamp clock.
Otherwise, the two frequencies would not fit together and the time stamp correction
within the DPLL would deliver wrong results.
The same holds if the TIM channel time stamp sampling is done with the low
resolution, while the filter runs with a high resolution.
Another important issue is, that when the TIM filter is configured in Immediate Edge
Propagation Mode, the filter correction inside of the DPLL has to be disabled.
Otherwise, the DPLL will use the filter disable windows, programmed also as filter
threshold value, to correct the time stamp. This will result in a new time stamp which
will be located before the immediate propagated edge.
ISL Ignore signal level: This bit has to be set, to force the TIM0 channel to
(Bit 14) react on each incoming edge.
GPR0_SEL Selection for GPR0 register: These two bits have to be set to “00” to
(Bit 9:8) sample the TBU_TS0 in the register. This value is transmitted to the
DPLL when a valid edge occurs.
TBU0_SEL TBU_TS0 bits input select: This bit has to be set according to the
requested time stamp resolution.
For a more detailed description of the TIM input channel, please refer to the GTM-IP
specification.
3 DPLL Configuration
3.1 Overview
The DPLL is a highly configurable dedicated submodule of the GTM-IP that can
transform an input signal frequency in a higher frequent signal called micro tick
further on. The DPLL can generate one micro tick signal that is dependent on
TRIGGER and STATE input, where TRIGGER and STATE have some kind of
relationship to each other. The other possibility is to generate two independent micro
tick signals from two independent TRIGGER and STATE input signals.
Since there are several different signal combinations and characteristics possible,
there are a lot of configuration parameters which can be configured by the CPU.
Besides the high configurability, there are also a lot of calculations done inside of the
PWM which need a high amount of local variables. Since the implementation of
registers for these local variables would have introduced high costs, local variables
are located inside of a RAM whenever possible. Therefore, the DPLL needs to have
access to the RAM during calculation.
The DPLL can be divided in several functional blocks which are depicted in Figure
3.1 and are described further on in a little bit more detail. For a more detailed
description of the DPLL and to use all the features of the DPLL please refer to the
GTM-IP specification.
STATE
TRIGGER
There are several subunits inside of the DPLL. The micro tick generation can be
done with two independent micro tick generation units mt_gen1, 2. Since the two
input signals TRIGGER and STATE can arrive at the DPLL input totally independent,
there are two independent data paths and ALU subunits implemented which calculate
parameters for the micro tick generators and action values for the rest of the GTM-IP
system.
Local variables, action parameters and system characterization data are located in
three independent RAM modules RAM1a, RAM1bc and RAM2. RAM1a holds data
which is needed for the action calculation. RAM1bc holds data for local variables and
for the STATE input signal characterization and RAM2 holds data for the TRIGGER
input signal characterization.
ALU1
DLM1
RMO
ALU2
There are two input path for the adder. One path can be controlled via CPU by
loading the adder values into the ADD_IN_LD1 register. This path can be enabled via
the DLM1 bit inside of the DPLL_CTRL_1 register. The other path is controlled by the
DPLL internal logic, where the two ALUs calculate the two adder values
independently on behalf of their input signals. ALU1 calculates ADD_IN_CALN and
ALU2 calculates ADD_IN_CALE. Which one of the two adder values is used can be
controlled by the CPU by setting RMO bit in the DPLL_CTRL_1 register.
For the adder value calculation it is important, that the adder is clocked with the time
stamp clock TBU_TS which comes from the TBU channel 0. The other input clock
CMU_CLK0 is used to generate fast pulses, if there are some missing micro ticks or
a direction change is detected. Therefore, the TBU channel 0 input clock as well as
the CMU_CLK0 clock have to be chosen carefully.
There is also a difference, between the output micro ticks generated. This should be
demonstrated with Figure 3.3.
TRIGGER
sub_inc1c
1 2 3 4 1 2 3 4 1 2 3 4 1 2 341 2 3 41 2 3 4
sub_inc1
a b c d e f
The DPLL is configured to generate 4 micro ticks per input tick (one tick from rising to
rising edge) on the TRIGGER input signal. The four micro ticks are generated for the
intervals a, and b correctly. The DPLL predicts for interval c the same adder value.
Unfortunately, the input signal frequency for interval c decreases.
When the DPLL is programmed in Automatic End Mode, which can be controlled by
DMO bit in the DPLL_CTRL_1 register, the sub_inc1c output ticks will stop after four
ticks were generated. For the next interval d another adder value is calculated which
results in a smaller frequency of the sub_inc signal. Now, since the input signal
accelerates, there are not enough micro ticks generated.
To compensate this, the DPLL offers two possibilities. One possibility is to distribute
for the next interval e evenly six micro ticks or to generate two micro ticks fast and
the regular 4 micro ticks evenly in the next interval. This behaviour can be configured
with the COA bit in the DPLL_CTRL_1 register. If the micro ticks should be generated
fast, the CMU_CLK0 is used as tick frequency.
The aforementioned micro tick generation holds for signal sub_inc1c. As can be seen
from the figure, sub_inc1 is always generated with the frequency calculated from the
last increment duration. Therefore, the sub_inc1 ticks do not reflect the physical
position of the TRIGGER input signal.
3.3.1 Overview
As mentioned above the DPLL has three associated RAM blocks which can be
accessed independently by the DPLL. The RAM1a is used for action calculation and
can only be accessed by CPU when the DPLL is disabled. RAM1bc is used for local
variable storage during DPLL calculations and for the storage of the STATE input
signal profile. RAM2 is used to store TRIGGER input signal related data.
The DPLL locates data inside of the RAMs with internal pointers. Besides the three
different physical RAMs, each RAM is divided into several regions, each region with
its own RAM pointer. The knowledge of the pointers is important for the usage of the
DPLL. The following table describes the pointers for RAM1bc regions and associated
pointers:
It is important to know that the DPLL manipulates these pointers automatically after
enable and when a valid STATE is detected. Nevertheless, the CPU has to observe
the STATE input signal and set the APT_1c3 pointer according to the actual profile
position which corresponds to the input. The DPLL will set than the LOCK1 bit in the
DPLL_STATUS register to signal that the DPLL now can judge on the input signal on
behalf of the profile information given by the user in RAM region RAM1c3.
The following table describes the pointers for RAM2 regions and associated pointers:
It is important to know that the DPLL manipulates these pointers automatically after
enable and when a valid TRIGGER is detected. Nevertheless, the CPU has to
observe the TRIGGER input signal and set the APT_2c pointer according to the
actual profile position which corresponds to the input. The DPLL will set than the
LOCK1 bit in the DPLL_STATUS register to signal that the DPLL now can judge on
the input signal on behalf of the profile information given by the user in RAM region
RAM2c.
OSS DPLL_AOSV_2
0x0 0x06040200
0x1 0x0C080400
0x2 0x18100800
0x3 0x30201000
This register map is important, when the TRIGGER profile has to be stored inside of
the RAM region 2c.
The pointer value has always to be calculated starting from the offset of RAM region
2c, and the pointer always uses word aligned addresses. This means that the first
entry in RAM region 2c has a pointer address APT_2c = 0x0, the second entry has
APT_2c = 0x4 and so forth.
One revolution
a b c d e
The figure shows two revolutions of a tooth wheel, where there two tooth are missing.
The falling edges are defined as the active trigger slopes which define a valid tooth.
The active edge has to be defined inside of the DPLL_CTRL_1 register. These active
edges define the true virtual increments. Nevertheless, for the profile to work, the
revolution has to be divided into equidistant nominal increments.
The user now has to define the profile in the RAM region RAM1c3 and/or RAM2c on
behalf of the true nominal increments and their duration. For the example in Figure
3.4 this results in the RAM entries (shown as RAM2 entries):
ADT_T[0] = 0x10000 // a
ADT_T[1] = 0x12000 // b
ADT_T[2] = 0x10000 // c
ADT_T[3] = 0x10000 // d
ADT_T[4] = 0x30000 // e
The so called adapt values ADT_T[x] represent the profile of the tooth wheel. For
each true nominal increment, the number of nominal increments is stored in the NT
bit field. For ADT_T 0 to 3 there is one nominal increment. For ADT_T[4] three
nominal increments are present. In addition for the true nominal increment ADT_T[1]
there is a user defined interrupt specified which will cause an interrupt when this
tooth is detected and the interrupt is enabled. In total there can be five user specific
interrupts defined.
In addition, physical deviations of a tooth can be specified in the lower 13 bits of the
RAM locations.
4 Sample implementation
CMU_CLK0
TBU CMU
TBU_TS0
sub_inc1c
TRIGGER
There are two possibilities to generate input stimuli for the GTM-IP. One is to use the
CHKSIG-IFS module and specify the input signal characteristic with CHKSIG
commands. The other is to generate the input stimuli with a GTM-IP output, in this
case with ATOM channel 7 and to connect the GTM output port with the input port via
a simple CHKSIG loop. The command sequence to do this is:
Code 4.1: DPLL signal routing from ATOM Channel 7 TIM Channel 7.
The PSM channel holds the TRIGGER signal input characteristic as a sequence of
PWM values. This sequence is feed to the ARU, while the PSM channel is configured
in Ring Buffer Mode. The ATOM channel is configured in SOMP mode with a duty
cycle level of ‘0’.
For the TRIGGER input signal to work, the TIM0 input channel 7 has to be routed to
the TIM0 input channel 0 via the TIM0 internal multiplexers at the input ports.
For the DPLL to work, one has to configure the TIM0 channel 0, the MAP, the CMU,
TBU and the DPLL itself.
void tb_setup(void)
{
int i = 0;
// setup PSM channel 0
FIFO0_CH0_CTRL = 0x1; // PSM operates in Ring Buffer Mode
F2A0_CH0_STR_CFG = 0x60000; // transfer both words to ARU
for (i=0; i<57; i++) {
AFD0_CH0_BUFFACC = 3200; // 57 times normal tooth
AFD0_CH0_BUFFACC = 1600; // 50% duty cycle
}
AFD0_CH0_BUFFACC = 9600; // 58 th tooth + 2 tooth gap
AFD0_CH0_BUFFACC = 1600;
The CMU is needed for the ATOM channel to work. But the CMU is set up in the
main application code.
CMU_GCLK_DEN = cParam.gclk_den;
Please note that to enable the CMU channels the GTM-IP double bit enable/disable
mechanism has to be applied on the CMU_CLK_EN register. For a detailed
description please refer to the corresponding submodule specification.
void init_tbu(void)
{
// setup TBU channel 0
TBU_CH0_CTRL = 0x0; // no LOW_RES, choose CMU_CLK0
// setup TBU channel 1
TBU_CH1_CTRL = 0x1; // Up/Down counter mode; sub_inc1c is chosen
Please note that to enable the TBU channels the GTM-IP double bit enable/disable
mechanism has to be applied on the TBU_CHEN register. For a detailed description
please refer to the corresponding submodule specification.
void init_tim0_ch0(void)
{
// setup and enable TIM0 channel 0
TIM0_CH0_CTRL = 0x00000040; // set CICTRL MUX first
TIM0_CH0_CTRL = 0x00004045; // CH_EN, TIEM, CICCTRL=1 (ch7 in),
// GPR0_SEL=TBU_TS0, ISL=1 (Both edge)
}
Since there is no STATE signal input for this application note, the RAM region
RAM1c3 has not to be configured at all.
The DPLL configuration is shown in code sample 4.6:
void init_dpll(void)
{
unsigned int ram_ini_v = 0;
unsigned int i = 0;
gtm_ptr p;
p = &DPLL_RR2;
p = p + (0x00000400/4);
for (i=0; i<57; i++){ // file profile for regular tooth
p[i] = 0x10000; // first HALF SCALE
}
p[57] = 0x30000; // 58th is special one!
p[58] = 0x12000; // gen TINT0 IRQ at the 59th tooth in FULL_SCALE
application note.
SYN_NT This bit field summarizes the total number of virtual 2
increments in a HALF_SCALE for the TRIGGER
input signal. In this application note, there are two
missing tooth per revolution.
TSL The active TRIGGER slope has to be defined by 2
these two bits. For this application note, the falling
edges are the relevant ones.
//-------------------------------------------------
// main thread:
int dpll_an011()
{
// required declaration for HAL
gtm_ptr p;
// CMU configuration structure
theCmu_param theCmuConfig;
int error = 0;
// testbench setup
tb_setup();
// configure CMU
init_cmu(theCmuConfig, 0x2); // configure and enable CMU_CLK0
// configure TBU
init_tbu();
// configure DPLL
init_dpll();
}
Code 4.7: Main thread for DPLL micro tick generation application.
int dpll_an011();
int dpll_an011_isr(int);
…
DEFINE_TEST_FCT(dpll_an011);
…
}
DEFINE_ISR_FCT(dpll_an011_isr);
…
}
For this application note, there is one major entry point for interrupts, which is defined
by void dpll_an011_isr(int).
This ISR is called from the interrupt system with the GTM-IP interrupt number. This
interrupt numbers can be obtained from the GTM-IP Testbench guide. The relevant
interrupt numbers for this application note are shown in the following table:
void isr_toothdet(void)
{
// disable NOTIFY bit
TIM0_CH0_IRQ_NOTIFY = 0x1;
// save actual time stamp
actTS = TIM0_CH0_GPR0;
// tooth starts with falling edge
if (!(actTS & 0x01000000)) { // falling edge detected
// save old time stamp and tooth charateristic
oldTS = newTS;
oldDiff = diffTS;
// determine new time stamp
newTS = actTS & 0xFFFFFF;
Gap detection is done on behalf of the last two tooth periods. If the tooth period
before the last tooth period is twice the size, this preceding tooth period was the gap.
This is because there are two tooth missing for the tooth wheel.
The APT_2c value has to be set accordingly to a position after this gap. Due to the
fact, that the GTM-RM and the GTM-IP use a different timing for the APT_2c
pointer updates, when a new edge occurs, the pointer has to be initialized
different for GTM-RM and GTM-IP.
The GTM-IP updates the RAM region 2c pointer after a new tooth is detected, while
the GTM-RM omits this pointer update at a new tooth. Therefore, the APT_2c pointer
has to be set to the next tooth that will be detected by the DPLL in case of the GTM-
RM. For the GTM-IP the pointer has to be set to the actual tooth. This pointer setting
is shown in Figure 4.2.
Reserved
TINT
PD
NT
Figure 4.2: Gap detection for a tooth wheel with a gap of two tooth.
After the gap is detected, the sub_inc1 and sub_inc1c generation is enabled and the
micro ticks are send to the TBU channel 1 time base.
void isr_lockdet(void)
{
unsigned int actTS;
Code 4.10: Interrupt service routine to check DPLL locking after second gap.