AN2577
Application note
Using the eTPU angle clock
Introduction
This document describes the angle clock feature of the enhanced time processor unit and
offers practical advise on the application and use of this feature. The note assumes a
familiarity with the eTPU and the eTPU_C language used in the byte craft compiler.
The eTPU is particularly suited to applications where input and output actions are
synchronized to the position of a rotating wheel. The eTPU angle clock provides hardware
which, when combined with the proper software, can track the wheel angle through
accelerations, decelerations, and a wide range of speeds.
If a wheel is tracked by the eTPU angle clock, many output matches and input captures can
operate on an angle count as well as a time count, and even on combinations of the two.
Compensation for speed changes are made in the angle clock only. An angle triggered
event will occur on the best estimate of the match angle.
The angle clock is complex to set up, but when running it offers an excellent integration of
fast operating hardware with the complex control of a software program. A reference design
has been built to demonstrate the operation of a periodic angle clock with other engine
control functions. See your STMicroelectronics representative for details.
September 2013
Rev 2
1/34
www.st.com
Contents
AN2577
Contents
1
2
Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
eTPU angle clock hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.1
2.2
2.3
2.4
2.5
Tooth wheel input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Tick counter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Missing teeth . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Zero count synchronization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Error recovery . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
3
System design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
3.1
Steady state system design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
3.1.1
3.1.2
3.1.3
3.1.4
3.1.5
3.1.6
Periodic angle clock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Free running angle clock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Angle resolution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Reference point . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Missing teeth . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Tick rate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
3.2
Acceleration and deceleration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
3.2.1
3.2.2
Acceleration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Deceleration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3.3
Startup system design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.3.1
3.3.2
3.3.3
Initial parameter values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Acquisition and synchronization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Starting the angle clock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
3.4
Anomalies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
3.4.1
3.4.2
Error prevention . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Error recovery . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Inserting a tooth . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .20
Deleting a tooth . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .20
3.5
Tooth circuit failure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
4
eTPU software design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
4.1
Host setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
2/34
AN2577
Contents
4.2
State machine description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
4.2.1
4.2.2
4.2.3
4.2.4
4.2.5
4.2.6
4.2.7
4.2.8
4.2.9
4.2.10
4.2.11
4.2.12
Initialize crank . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
First edge . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
First period . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Testing for a possible gap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Apparent gap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Possible gap verifying . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Gap verified . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
Counting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
Gapping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
New revolution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
Adjust angle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
Stall . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
5
Angle clock application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
5.1
5.2
5.3
Free running angle counter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Periodic angle clock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Angle math . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
6
Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
3/34
Overview
AN2577
1
Overview
The enhanced time processor unit (eTPU) is an autonomous slave processor offered on
several STMicroelectronics microcontrollers designed for real time automotive
applications.The processor is tightly coupled to up to 32 channels, each associated with an
input and an output signal. The input/output channels each have a pair of Match and
Capture units interfaced to one of two timer/counter (TCR) registers. Logic in the channel
enabled the hardware to detect or drive pin transitions with a high degree of timing
precision.
In a typical application, at least one of the TCRs is driven by a real time clock derived from
the MCU clock frequency. The second TCR can be driven by an asynchronous external
signal, by a real time clock with a different time base, or by special angle clock circuitry on
the eTPU. The purpose of the angle clock is to synchronize with the angle of a spinning
shaft and provide a counter representation of the instantaneous position of the shaft. If the
shaft provides an input signal related to teeth spaced along the circumference, the angle
clock extrapolates the number of ticks between the adjacent pairs of teeth, thereby providing
a finer resolution of angle than the shaft signal alone can provide. The angle clock was
designed for automotive engine control, but finds application in a variety of rotational
devices.
An angle clock can be implemented in hardware or in software, but either implementation
has limitations. A software angle clock cannot divide an input tooth signal into very fine ticks
without overwhelming the processor. Even before the tick rate reaches its limit, latency on
the processor will begin to distort the ideal count pattern. A hardware angle clock can
provide very fine resolution of the ticks, but the hardware becomes complex and large when
the logic is required to handle errors and exceptional input signals.
The eTPU angle clock has been implemented as a software supported hardware
subsystem, effectively eliminating both of these significant limitations. The hardware
subsystem has provisions for fast tick counting plus compensation for missing teeth, which
are often used to provide an angle key for the shaft. The hardware also provides automatic
compensation for acceleration and deceleration, and assists in error recovery. The software
handles synchronization and exception handling.
4/34
AN2577
Figure 1.
Toothed wheel
Overview
Sensor
Toothed Wheel ‘36 - 1’
35 Teeth Spaced 10º
5/34