AVR480: Anti-Pinch System For Electrical Window: Microcontrollers Application Note
AVR480: Anti-Pinch System For Electrical Window: Microcontrollers Application Note
7559B–AVR–12/06
Powered Today, electronic components and systems account for over 20% of the cost of a high end pas-
Equipments in senger car. The ability of dense electronics to better control sensors and actuators is utilized to
Modern Cars enhance comfort and safety in cars and it is very predictable that most of the middle and upper
class vehicles will be systematically equipped with motorized window or door systems.
The majority of these equipments come with full automation, means that they must be accompa-
nied by safety systems to prevent people injury or mechanical degradations.
The legislation offers set of rules to which powered systems must comply. This is particularly
true for window lifts or sliding doors. This application note describes how to implement an anti-
pinch algorithm which was initially developed for a powered window but which can be easily
adapted to any other moving part.
The Standards The automotive power-operated windows are governed by international standards, like
MVSS118 in USA or 74/60/EEC in Europe. For those relatives to the elimination of danger to
children, the requirements expressed in these documents can be summarized as follows (see
Figure 1):
• Detection area: 4 mm to 200 mm,
• Maximum pinch force = 100N,
• Reverse direction on a pinch.
• Tests with determined deflection ratio objects: 5N/mm to 20N/mm
4mm
200mm
2 AVR480
7559B–AVR–12/06
AVR480
Hardware Different detection strategies are possible to determine whether an obstacle is entering the criti-
Consideration cal pinching area:
• Without mechanical contact. It reacts before the pinch effort is exerted on the object. This is
the optimal protection since no force is applied to the obstacle. It is also independent to
vibration, aerodynamic variations, deformations. But, it requires integrated sensors (infrared,
ultrasonic, ...) with their electronic modules and wires leading to additional costs.
• With mechanical contact. The pressure measurement will tell the system an object is being
pinched. Also there, designers have two fundamental technologies available:
– Direct measurements: Force sensors or contactors are integrated on the door seal.
These solutions are inherently high cost and reduce the styling for window/door
designs
– Indirect measurements via physical monitoring. This is a globally cost optimized
solution.
Anti-Pinch The pinch detection algorithm shall, at first, respect the standards (FMVSS118 & 74/60/EEC)
Algorithm requirements:
Specification • Detection area from 4 to 200mm
• Maximum exerted force of 100N
• Reverse direction on Pinch detection
• Normalized tests for validation
Solution Using The force applied to the glass can be extrapolated from the current through the motor. The posi-
Motor’s Physical tion of the moving elements permanently provides information on speed. Both parameters can
Parameters then be used to determine whether an obstacle has been encountered and whether:
• It is in the detection area
• The force applied gets higher than the limit
This document describes one anti-pinch algorithm developed to work with motor current mea-
surements and hall-effect speed indications. With very little changes, it can adapat to other
systems like slidding doors or roof panels.
Modeling, To better design the pinch-detection algorithm, the physical parameters involved in the lift sys-
Simulation tem have been extracted. Starting from a generic description of an opening/closing aparatus,
one more precise model has been developed for the powered window. It is broken down into
several main components as illustrated in Figure 2.
3
7559B–AVR–12/06
Figure 2. Powered Window Mechanical Components
Motor
Endless screw
« Flexible »
coupling
Non-linearity
Motor Model The DC universal motor used can be modeled using a very classical scheme as illustrated in
Figure 3.
i(t)
U J
f
i(t) e(t)
L
U
R
4 AVR480
7559B–AVR–12/06
AVR480
Differential (t) and Laplace domain (p) equations are extracted for Electrical and Mechanical
elements:
di
U(t ) = e (t ) + Ri (t ) + L U ( p) = E ( p) + RI ( p) + LpI ( p)
dt
e (t ) = k Ω(t ) E ( p ) = k Ω( p )
m (t ) = k i (t ) , motor torque M ( p) = k I ( p)
dΩ
J = m (t ) − fΩ(t ) JpΩ( p) = M ( p) − fΩ( p)
dt
The model chosen is a second order process. This allows the simulation of the motor, with its
power supply (Voltage), including speed and current measurements. It also authorizes to inject
disturbances or connect load (Co). It is detailed in Figure 4.
U 1 I Cem M 1 Ω
+
-- R + Lp K +
-- f + Jp
E Co
K K*U(p) + Co(R+Lp)
Ω (p)=
(f + Jp)(R + Lp) + K²
5
7559B–AVR–12/06
Window-lift Model In addition to the DC motor model, the components from the window-lift system must be
inserted. They are introduced to estimate the torque provided by the motor, and to access to
position, speed and acceleration. The mechanical elements are described in Figure 5.
F1
r
T1 ≈ (M&z&2 + Fv z&2 + Fs + Mg ) Z1
n Z2
F2
n : Gear ratio F Weight
r : Radius
T1, T2 : Torque
Mg
Fv : Viscous Friction
Fs : Static Friction
This model is executed to obtain system behavior and to verify the pinch-detection algorithm.
Described parameters and others (static and viscous frictions, weight,...) are tuned and intro-
duced in the model to verify their influence.
Mechanical
components
motor
Pinch &
Disturbances
sensors Anti-pinch
Algorithm
6 AVR480
7559B–AVR–12/06
AVR480
Pinch Detection Usual pinch-detection algorithm operation is using indirect measurements out of the window-lift
Algorithm system:
• Current (torque)
• Position (speed)
The algorithm detailed in this document agregates two techniques based on
• Calibrated torque stored in non-volatile memory: Preliminary learning sequence is executed
and torque values are stored in memory. This is quite memory consuming and requires
regular calibration sequences
• Speed derivate calculation: Interesting method since it requires less memory but needs
more computing power
and takes benefit from the two methodologies.
Pinching Condition A pinch is detected by comparing the current measurement with a reference (see Figure 7).
M(t) ) kϕ x i(t) = K x i(t)
The threshold can be determined out of the Motor Torque constant (K) combined with the
response time of the system (Motor and the load).
i measured Pinch
iref Threshold
Current Reference One solution to elimnate need for calibration is to calculate expected current all along the mov-
Synthesis ment. One pinch condition makes the speed decreasing and the current growing upassociated
with increasing torque. Those two conditions are used to determinate the occurence of a pinch.
In this document, speed derivate is preferred for its higher robustness to noise or fast
disturbances.
An example is given in Figure 8. The Current Reference (Iref) is permanently calculated until the
speed increases or remains unchanged. As soon as the speed decreases rapidly (Derivate
becomes negative), Iref is frozen. Current through the motor (Imot) continues to be measured
and compared with Current Reference + Margin. In case Imot gets higher than the limit, then a
Pinch is declared and several actions are taken by the application (First is to stop the motor and
reverse its rotation to release the obstacle).
7
7559B–AVR–12/06
Figure 8. Example of a Pinch detection
Rotation speed
Current Imot
t
Derivate speed
t
Algorithm Robustness The permanent calculation of the Iref allows for highly adaptative algorithm. To even increase
Current Filtering the robustness of the alogrithm, the Current Reference is averaged over 8 consecutive mea-
surements (see Figure 9).
Derivative speed
Imeas
Measured Average (8 Low pass (2
current Imot samples) Exploited current samples)
Current
Reference Iref
Algorithm Robustness As Iref permanent calculation allows a highly adaptative algorithm, local great frictions variations
Blocking points called blocking points could involve bad pinch detection. Indeed, a local friction increase, even-
tually in addition to other disturbances (bumpy road, wind...) could result in a pinch condition, as
Iref would be frozen.
Those blocking points are detected the same way as pinches. The difference between current
and reference is monitored. When it is greater than a threshold, it is detected and blocking point
charateristics are stored into EEPROM.
A blocking point is described only by a position interval and an event counter (number of detec-
tions) to minimize memory requirements. It could be more precise by storing magnitude in the
interval or by using several threshold. But it would use more memory.
A table containing all hard point informations is stored in non volatile memory
When a blocking point is known (stored in table) and its event counter allows to consider it as a
blocking point, the threshold is added to pinch margin, in the correspondig interval, to increase
robustness.
8 AVR480
7559B–AVR–12/06
AVR480
Figure 10. Blocking point example
Deformation:
Transition period
State Machine The main finite state machine (FSM) manages motor commands and pinch detection (Figure 11
presents states for upward movements. Downward operation is presented in Figure 12).
Stop motor
Upward Cmd Move up
Stop Start up
Timeout High position backlash
Or Timeout
stop motor
Go up
Stopping Cmd Timeout
Out of area Pinch condition
High position
Ou Timeout Obstruct
Pinch area
Stop motor
Pinch
9
7559B–AVR–12/06
Figure 12. Downwward Movement Finite State Machine
Timeout
Stop motor
Stop Cmd
request
Timeout
Adaptation function, FSM requires parameters (backlash, top and bottom ends, hall sensors resolution...) to work
portability properly. Those parameters could be constant parameters or measured at initialisation. Some of
them could change from one window lift to another. Thereby, optional adaptation function
acquire those parameters at first initialisation by operating the window lift. It also monitors bloc-
king points to initialize the memorization table.
This optionnal adaptation routine disables anti-pinch while running. It then operates window lift
downward and upward to detect bottom and top positions. Simultaneously, it monitors the block-
ing points. To acquire backlash, It operates downward and upward into the pinch detection area
(by comparing current reference to acquired current).
Other Interesting Not described here are secondary functions necessary for Window-lift operation:
Functions • Measuring current, filtering
• Hall-Effect interrupt generation, counting, speed calculation, direction
• Push-button management
• Memorization of critical parameters (position, last operation direction, ...) in case of power-
fail
10 AVR480
7559B–AVR–12/06
AVR480
Simulation Results Numerous simulations have be ran to assess and tune the different parameters for the detection
threshold loop. Figure 13 visualizes how the speed and motor torque behave at the first and sec-
ond ‘go-upward’ commands. Also, a pinch condition is injected at t=10s with a compression
spring of 10N/mm.
Figure 14 shows the same curves but disturbances in motor torque are injected (frequency of
10Hz, 50N), after a second ‘go-upward’ command.
Figure 13. Simulation of the Algorithm with two Consecutive ‘Go-Upward’ Commands
1* 2* t
Pinching t
1* 2*
Current – Reference
> Threshold
1. The non-linearity of the transmission causes a speed overvalue at motor start. The torque
looks like un-coupled for a few moment.
2. There, the elasticity of the transmission system is no more involved and the torque and speed
images are different.
11
7559B–AVR–12/06
Figure 14. Algorithm Simulation Injecting 10Hz, 50N Disturbance
AVR The algorithm detailed in the previous paragraphs has been implemented and tested using an
Implementation AVR ATMEGA88 based board.
Hardware The hardware used for the implementation of the algorithm is described in Figure 15. It imple-
Specification ments one standard ATmega88 as well as analog chain to measure motor current. It has two
hall effects sensors. The motor direction is controlled via one two-poles relay while the ON-OFF
of the motor is activated by a Mosfet.
Hall Sensor
x2
V Battery
M
INT
out
AVR
out
ADC
+
Shunt
-
12 AVR480
7559B–AVR–12/06
AVR480
Task Scheduling By considering, the algorithm described previously, as well as the allocation of hardware and
software resources, we obtain the following scheduling of the program
Normal Operations This schedule is valid when the algorithm is running in standard operating condition, i.e. when
the motor is operating (rotating) or is stopped. Indeed, position, speed and reference calcula-
tions are refreshed when events occurs from the position sensors (hall effect sensors) or don't
have to be done (when the motor is stopped in a stable and normal state).
Timer 0 overflow
Idle
13
7559B–AVR–12/06
Other Operations When the motor is brutally stopped, rotates abnormally slow or doesn't start for several reasons
(motor blocked, hall sensor disconnected…), timer1 is used to generate a timeout and to shut
down the power (or to reverse direction).
Figure 17. Task Sceduling When Timeout or Parameter Save Request has been Set
Interruption PCINT9
Idle
Algorithm porting Such an algorithm should be portable from one opening aparatus to another. So, it uses like a
database stored into eeprom, which contains algorithm parameter set (extracted from model).
This allows algorithm to be portable. Refer to algorithm adaptation procedure (AVR191) for more
details.
Software All code is implemented in C language using IAR EWAVR 4.20. Implementation of basic func-
Description tions (position management, initializations, current measurements, window operations and anti-
pinch monitoring) requires 2Kb of flash memory. Adding extended functions like eeprom stor-
age, calibration, adaptation, blocking points detection increases code size up to 5.7Kb.
void init_window_size_position()
Allows to automatically operate window down, then up to detect top and bottom positions, iden-
tify blocking points and backlash : It's an adaptation routine.
void save_window_parameters(void)
This function saves window lift parameters to EEPROM.
14 AVR480
7559B–AVR–12/06
AVR480
U8 window_ctrl (signed char *up_cmde, signed char *down_cmde ,U8
no_anti_pinch)
This contains the window-lift state machine. It controls window operations, with given events
parameters. It monitors the position, up and down end limits, and the anti-pinching condition. It
returns the state of the window-lift (same value as the get_window_state function).
U8 update_point (void)
This function shall be called by blocking_point routine to sort, create or refresh blocking points
data table when a blocking point has just been completly detected. When this blocking point was
existing, it updates its event counter and its position interval. If it wasn’t existing, routine insert it
in the blocking points table.
void clean_point(void)
This routine shall be called by blocking_point routine and the end of each upward operation.
It’s in charge of decreasing blocking point event counter in the parsed area. It cleans blocking
points which event counter has decreased to zero (means they no more exists or it was a distur-
bance or a pinch and have no more been detected)
15
7559B–AVR–12/06
U8 get_block_point(U16 position)
This function returns the corresponding threshold value to add to pinch margin value if a block-
ing point has been confirmed at the provided position in parameter. Otherwise, when there are
no blocking point at this postion, it returns zero.
ADC end
conversion
yes
current filtering
Window-lift control
save parameters
16 AVR480
7559B–AVR–12/06
AVR480
Hall effect Position Figure 19. Hall effect Position Sensor Interrupt Sub-routine
Sensor Interrupt Sub-
routine Hall sensor ISR
Direction ? downward
upward
Default ? yes
stop request
dv > 0 or
ref < current
yes
end ISR
17
7559B–AVR–12/06
Window Control State Figure 20. Window Control State Machine Implementation (part 1)
Machine
Implementation state
stop state
motor off
go up cmd? no
start_up state
backlash end no
state = go up
current>0 no cmd?
no
state = pinch error : motor state = stopping
disconnected
go_up state
go up or down cmd no
motor off
state = stop
null current &
Timeout pinch area
motor off
error : motor off after
update position a step
state = stop
obstruct state
go down cmd? no
18 AVR480
7559B–AVR–12/06
Atmel Corporation Atmel Operations
2325 Orchard Parkway Memory RF/Automotive
San Jose, CA 95131, USA 2325 Orchard Parkway Theresienstrasse 2
Tel: 1(408) 441-0311 San Jose, CA 95131, USA Postfach 3535
Fax: 1(408) 487-2600 Tel: 1(408) 441-0311 74025 Heilbronn, Germany
Fax: 1(408) 436-4314 Tel: (49) 71-31-67-0
Fax: (49) 71-31-67-2340
Regional Headquarters Microcontrollers
Europe 2325 Orchard Parkway 1150 East Cheyenne Mtn. Blvd.
Atmel Sarl San Jose, CA 95131, USA Colorado Springs, CO 80906, USA
Route des Arsenaux 41 Tel: 1(408) 441-0311 Tel: 1(719) 576-3300
Case Postale 80 Fax: 1(408) 436-4314 Fax: 1(719) 540-1759
CH-1705 Fribourg
Switzerland La Chantrerie Biometrics/Imaging/Hi-Rel MPU/
Tel: (41) 26-426-5555 BP 70602 High Speed Converters/RF Datacom
Fax: (41) 26-426-5500 44306 Nantes Cedex 3, France Avenue de Rochepleine
Tel: (33) 2-40-18-18-18 BP 123
Asia Fax: (33) 2-40-18-19-60 38521 Saint-Egreve Cedex, France
Room 1219 Tel: (33) 4-76-58-30-00
Chinachem Golden Plaza ASIC/ASSP/Smart Cards Fax: (33) 4-76-58-34-80
77 Mody Road Tsimshatsui Zone Industrielle
East Kowloon 13106 Rousset Cedex, France
Hong Kong Tel: (33) 4-42-53-60-00
Tel: (852) 2721-9778 Fax: (33) 4-42-53-60-01
Fax: (852) 2722-1369
1150 East Cheyenne Mtn. Blvd.
Japan Colorado Springs, CO 80906, USA
9F, Tonetsu Shinkawa Bldg. Tel: 1(719) 576-3300
1-24-8 Shinkawa Fax: 1(719) 540-1759
Chuo-ku, Tokyo 104-0033
Japan Scottish Enterprise Technology Park
Tel: (81) 3-3523-3551 Maxwell Building
Fax: (81) 3-3523-7581 East Kilbride G75 0QR, Scotland
Tel: (44) 1355-803-000
Fax: (44) 1355-242-743
Literature Requests
www.atmel.com/literature
Disclaimer: The information in this document is provided in connection with Atmel products. No license, express or implied, by estoppel or otherwise, to any
intellectual property right is granted by this document or in connection with the sale of Atmel products. EXCEPT AS SET FORTH IN ATMEL’S TERMS AND CONDI-
TIONS OF SALE LOCATED ON ATMEL’S WEB SITE, ATMEL ASSUMES NO LIABILITY WHATSOEVER AND DISCLAIMS ANY EXPRESS, IMPLIED OR STATUTORY
WARRANTY RELATING TO ITS PRODUCTS INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, CONSEQUENTIAL, PUNITIVE, SPECIAL OR INCIDEN-
TAL DAMAGES (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF PROFITS, BUSINESS INTERRUPTION, OR LOSS OF INFORMATION) ARISING OUT
OF THE USE OR INABILITY TO USE THIS DOCUMENT, EVEN IF ATMEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. Atmel makes no
representations or warranties with respect to the accuracy or completeness of the contents of this document and reserves the right to make changes to specifications
and product descriptions at any time without notice. Atmel does not make any commitment to update the information contained herein. Unless specifically providedot-
herwise, Atmel products are not suitable for, and shall not be used in, automotive applications. Atmel’sAtmel’s products are not intended, authorized, or warranted for use as
components in applications intended to support or sustain life.
© Atmel Corporation 2006. All rights reserved. Atmel ®, logo and combinations thereof, are registered trademarks, and Everywhere You Are ®
are the trademarks of Atmel Corporation or its subsidiaries. Other terms and product names may be trademarks of others.
7559B–AVR–12/06