- Spansion

The following document contains information on Cypress products.
Colophon
The products described in this document are designed, developed and manufactured as contemplated for general use,
including without limitation, ordinary industrial use, general office use, personal use, and household use, but are not
designed, developed and manufactured as contemplated (1) for any use that includes fatal risks or dangers that, unless
extremely high safety is secured, could have a serious effect to the public, and could lead directly to death, personal injury,
severe physical damage or other loss (i.e., nuclear reaction control in nuclear facility, aircraft flight control, air traffic control,
mass transport control, medical life support system, missile launch control in weapon system), or (2) for any use where
chance of failure is intolerable (i.e., submersible repeater and artificial satellite). Please note that Spansion will not be liable
to you and/or any third party for any claims or damages arising in connection with above-mentioned uses of the products.
Any semiconductor devices have an inherent chance of failure. You must protect against injury, damage or loss from such
failures by incorporating safety design measures into your facility and equipment such as redundancy, fire protection, and
prevention of over-current levels and other abnormal operating conditions. If any products described in this document
represent goods or technologies subject to certain restrictions on export under the Foreign Exchange and Foreign Trade Law
of Japan, the US Export Administration Regulations or the applicable laws of any other country, the prior authorization by the
respective government entity will be required for export of those products.
Trademarks and Notice
The contents of this document are subject to change without notice. This document may contain information on a Spansion
product under development by Spansion. Spansion reserves the right to change or discontinue work on any product without
notice. The information in this document is provided as is without warranty or guarantee of any kind as to its accuracy,
completeness, operability, fitness for particular purpose, merchantability, non-infringement of third-party rights, or any other
warranty, express, implied, or statutory. Spansion assumes no liability for any damages of any kind arising out of the use of
the information in this document.
®
®
®
TM
Copyright © 2013 Spansion Inc. All rights reserved. Spansion , the Spansion logo, MirrorBit , MirrorBit Eclipse ,
TM
ORNAND and combinations thereof, are trademarks and registered trademarks of Spansion LLC in the United States and
other countries. Other names used are for informational purposes only and may be trademarks of their respective owners.
Fujitsu Microelectronics Europe
Application Note
MCU-AN-300037-E-V11
F²MC-8L/16LX/FR FAMILY
8/16/32-BIT MICROCONTROLLER
ALL SERIES WITH LIN-USART
LIN STEPPER MOTOR DRIVER
APPLICATION NOTE
LIN STEPPER MOTOR DRIVER
Revision History
Revision History
Date
2007-01-15
2007-07-13
Issue
V1.0 CSc/HWe, Initial Version
V1.1 DGo/HWe, corrected reference file names
This document contains 23 pages.
This application note was kindly supported and released by courtesy of
AMI Semiconductor Belgium BVBA, Belgium, http://www.amis.com
MCU-AN-300037-E-V11
-2-
© Fujitsu Microelectronics Europe GmbH
LIN STEPPER MOTOR DRIVER
Warranty and Disclaimer
Warranty and Disclaimer
To the maximum extent permitted by applicable law, Fujitsu Microelectronics Europe GmbH restricts
its warranties and its liability for all products delivered free of charge (eg. software include or
header files, application examples, target boards, evaluation boards, engineering samples of IC’s
etc.), its performance and any consequential damages, on the use of the Product in accordance with
(i) the terms of the License Agreement and the Sale and Purchase Agreement under which
agreements the Product has been delivered, (ii) the technical descriptions and (iii) all accompanying
written materials. In addition, to the maximum extent permitted by applicable law, Fujitsu
Microelectronics Europe GmbH disclaims all warranties and liabilities for the performance of the
Product and any consequential damages in cases of unauthorised decompiling and/or reverse
engineering and/or disassembling. Note, all these products are intended and must only be used
in an evaluation laboratory environment.
1.
Fujitsu Microelectronics Europe GmbH warrants that the Product will perform substantially in
accordance with the accompanying written materials for a period of 90 days form the date of
receipt by the customer. Concerning the hardware components of the Product, Fujitsu
Microelectronics Europe GmbH warrants that the Product will be free from defects in material
and workmanship under use and service as specified in the accompanying written materials
for a duration of 1 year from the date of receipt by the customer.
2.
Should a Product turn out to be defect, Fujitsu Microelectronics Europe GmbH´s entire liability
and the customer´s exclusive remedy shall be, at Fujitsu Microelectronics Europe GmbH´s
sole discretion, either return of the purchase price and the license fee, or replacement of the
Product or parts thereof, if the Product is returned to Fujitsu Microelectronics Europe GmbH in
original packing and without further defects resulting from the customer´s use or the transport.
However, this warranty is excluded if the defect has resulted from an accident not attributable
to Fujitsu Microelectronics Europe GmbH, or abuse or misapplication attributable to the
customer or any other third party not relating to Fujitsu Microelectronics Europe GmbH.
3.
To the maximum extent permitted by applicable law Fujitsu Microelectronics Europe GmbH
disclaims all other warranties, whether expressed or implied, in particular, but not limited to,
warranties of merchantability and fitness for a particular purpose for which the Product is not
designated.
4.
To the maximum extent permitted by applicable law, Fujitsu Microelectronics Europe GmbH´s
and its suppliers´ liability is restricted to intention and gross negligence.
NO LIABILITY FOR CONSEQUENTIAL DAMAGES
To the maximum extent permitted by applicable law, in no event shall Fujitsu
Microelectronics Europe GmbH and its suppliers be liable for any damages whatsoever
(including but without limitation, consequential and/or indirect damages for personal
injury, assets of substantial value, loss of profits, interruption of business operation,
loss of information, or any other monetary or pecuniary loss) arising from the use of
the Product.
Should one of the above stipulations be or become invalid and/or unenforceable, the remaining
stipulations shall stay in full effect
© Fujitsu Microelectronics Europe GmbH
-3-
MCU-AN-300037-E-V11
LIN STEPPER MOTOR DRIVER
Contents
Contents
REVISION HISTORY ............................................................................................................ 2
WARRANTY AND DISCLAIMER ......................................................................................... 3
CONTENTS .......................................................................................................................... 4
1 INTRODUCTION.............................................................................................................. 6
2 LIN-BUS........................................................................................................................... 7
2.1
Short LIN Specification ............................................................................................ 7
2.1.1
Identifier Field ............................................................................................ 8
2.1.2
Checksum.................................................................................................. 8
3 HARDWARE SETUP ....................................................................................................... 9
3.1
Block diagram ......................................................................................................... 9
3.2
Schematics............................................................................................................ 10
3.3
Short Description AMIS – 30621 ........................................................................... 11
3.4
Fujitsu’s MCU........................................................................................................ 11
4 CONTROLLING THE AMIS 30621 ................................................................................ 12
4.1
LIN Frames ........................................................................................................... 12
4.1.1
Dynamically assigned identifier................................................................ 12
4.2
Dummy Frame ...................................................................................................... 13
4.3
GetFullStatus ........................................................................................................ 14
4.4
SetMotorParam ..................................................................................................... 14
4.5
SetPosition ............................................................................................................ 15
4.6
Summary............................................................................................................... 15
5 SOFTWARE................................................................................................................... 16
5.1
5.2
5.3
5.4
LIN Protocol Handling ........................................................................................... 16
5.1.1
Interrupts during LIN frame ...................................................................... 16
5.1.2
State chart of the Interrupt Service Routine ............................................. 17
Generating LIN frames .......................................................................................... 19
5.2.1
Master sends LIN frame........................................................................... 19
5.2.2
Master requests LIN frame from Slave..................................................... 19
Implemented Features........................................................................................... 20
5.3.1
DoGetFullStatus ...................................................................................... 20
5.3.2
SetMotorParameter ................................................................................. 21
5.3.3
Set Dynamic Identifier.............................................................................. 21
User Menu............................................................................................................. 22
MCU-AN-300037-E-V11
-4-
© Fujitsu Microelectronics Europe GmbH
LIN STEPPER MOTOR DRIVER
Contents
5.5
Example Project Structure..................................................................................... 22
5.6
Source Code ......................................................................................................... 22
6 APPENDIX ..................................................................................................................... 23
6.1
Figures .................................................................................................................. 23
6.2
Information in the WWW........................................................................................ 23
© Fujitsu Microelectronics Europe GmbH
-5-
MCU-AN-300037-E-V11
LIN STEPPER MOTOR DRIVER
Chapter 1 Introduction
1 Introduction
This application note describes how to use the Fujitsu’s LIN USART to control LIN devices.
The software example is based on a 16-bit microcontroller of the MB90350 Series1, acting
as a LIN master that will be connected to a Stepper Motor Driver IC from the company
AMI Semiconductor. The AMIS-30621 is a bipolar 2-Phase stepper motor driver with position
controller and LIN control/diagnostics interface integrated in a single chip. The AMIS-30621
acts as a slave on the bus and the master can fetch specific status information like actual
position, error flags, etc. from each individual slave node.
The basics of the LIN bus protocol will be explained within this application note.
1
The software example can easily be adapted to all 8-, 16- and 32-bit MCUs with LIN-USART.
MCU-AN-300037-E-V11
-6-
© Fujitsu Microelectronics Europe GmbH
LIN STEPPER MOTOR DRIVER
Chapter 2 LIN-Bus
2 LIN-Bus
SHORT SPECIFICATION
2.1
Short LIN Specification
LIN uses NRZ-8N1L data format in a baud rate range from 9600 Bit/s to 19200 Bit/s. A LIN
bus is a 1 master to n slaves bus.
A LIN message frame consists of a header and a response like in the graphic below:
LIN Message Frame
Message Frame
Header
Synch Break
Response
Synch Field
Ident Field
Data Field(s)
In-frame response space
Data Field
Checksum Field
Interbyte space
Except for the Synchronization Break all Fields are simple 8N1L data, this means 1 start bit,
8 data bits (LSB first), no parity, 1 stop bit
The Synchronization Field is a simple 0x55 byte (LSB first). Thus it consists of alternately 5
dominant and 5 recessive bits:
SYNCH FIELD
8 Tbit
START
BIT
0
1
2
© Fujitsu Microelectronics Europe GmbH
3
4
-7-
5
6
7
STOP
BIT
MCU-AN-300037-E-V11
LIN STEPPER MOTOR DRIVER
Chapter 2 LIN-Bus
2.1.1 Identifier Field
The Identifier filed consists of 6 ID bits and 2 parity bits:
The Parity bits are calculated by:
P 0 = ID 0
ID1
ID 2
ID 4
P1 = ID1
ID3
ID 4
ID5
The identifiers 0x3C, 0x3D, 0x3E, and 0x3F with their respective IDENTIFIER FIELDS
0x3C, 0x7D, 0xFE, and 0xBF (all 8-byte messages) are reserved for command frames (e.g.
sleep mode) and extended frames
The identifier 0x3C is a Master Request-frame to send commands and data from the master
to the slave node.
The identifier 0x3D is an Slave Response frame that triggers one slave node (being
addressed by a prior download-frame) to send data to the master node.
2.1.2 Checksum
The checksum is calculated over all data bytes (LIN 1.3) or over all data bytes and the
identifier byte (LIN 2.0). The calculation is the inverted sum with carry. This means, if the
new sum over the last sum is greater than 255 an additional “1” is added. After the last
addition, the result is inverted.
The formula for this calculation is:
n
Checksum = 0 xFF
n
i =1
datai mod 0 x100 +
i =1
datai
0 x100
Note, that in LIN 2.0 datai also contain the identifier field.
For more Information about Using the LIN-Bus check our Application Note mcu-an-390088e-uart_lin.pdf or see the LIN Specification on the Internet: www.lin-subbus.org
MCU-AN-300037-E-V11
-8-
© Fujitsu Microelectronics Europe GmbH
LIN STEPPER MOTOR DRIVER
Chapter 3 Hardware Setup
3 Hardware Setup
This Chapter describes a minimal Hardware Setup
3.1
Block diagram
This diagram shows a simple configuration of the functional blocks
Optional
UART
MCU
LIN-MASTER
LIN-BUS
LIN-SLAVES
AMIS
AMIS
AMIS
SM
SM
SM
Figure 3-1 Block diagram
© Fujitsu Microelectronics Europe GmbH
-9-
MCU-AN-300037-E-V11
LIN STEPPER MOTOR DRIVER
Chapter 3 Hardware Setup
3.2
Schematics
The Schematic shows the MCU Part including UART- and LIN-Transceivers and the Part of
the AMIS Motor Driver. In each case a basic setup is presented.
C2+
V-
C2 -
GND
35
LIN
VS
6
8
220p
BUS
TXD
INH
GND
64
2
MD0
MD1
1
44
4
44
SIN2
MD2
2k
2k
23
22
21
SOT2
GND
5
GND
TLE7259
18
22:/25V100n
RXD
RST
R30
4k7
2k
45
GND
AVss
7
2k
JP61
LIN enable
Default open
100n
GND
U11
3
2
WAKE
EN
D25
1N4148
Default open
VCC
MB90F350
VCC
Master
48
1
D26
1N4002
X1
Vss
1k
Q1
4MHZ
22 pF
GND
VCC
C67
C69
1n
R28
22 pF
SOT3
15
GND
JP57
VBAT
47
SIN3
GND
6
MAX3232CSE
VBat
X0
34
C61
100n
100n
5
G
12
9
11
10
R1 IN R1 OUT
R2 IN R2 OUT
T1 OUT
T1 IN
T2 OUT
T2 IN
4
GND
3
C1 -
MCU
AVRH
V+
13
8
14
7
Vcc
C109
100n
Vss
GND
1
C1+
48
5
9
4
8
3
7
2
6
1
UART
VCC
49
16
C57
100n
2
100n
GND
G
GND
VCC
UART
U8
AVcc
VCC
C52
LIN
GND
G
GND
X6
Optional to connect more devices
G
GND
LIN B (female)
1
6
2
7
3
8
4
9
5
LIN
GND
U2
LIN
6
LIN-Bus[0..1]
AMIS-30621
Motor Driver
LIN
J1
GND
GND
TST
C2
100 nF
C3
GND
HW0
R2
HW1
1k
GND
GND
GND
HW2
C8
2.7 nF
GND
C6
1k
C7
2.7 nF
GND
220 nF
X2
D1
VBB
Vbat
C10 Diode
100 uF
GND
MOTOR COIL Y
R1
20
CPP
VCP
CPN
C5
100 nF 220 nF
1
2
DCIN
3
1
C4
100 nF
GND
4
JP_HW2
default 2-3
VBB
15
13
2
JP_HW1
default 2-3
VDD
MOTOR COIL X
10
19
GND
JP_HW0
default 2-3 VDD
SWI
11
9
100 nF
MOTYP
MOTYN
VBB
C9
7
4
5
1
2
J2
VDD
12
C1
3
MOTXP
MOTXN
18
16
AMIS 30621
GND
GND
1 uF tantal
HW0
HW1
HW2
17
14
HW0 1
HW1 2
HW2 8
VBB
GND
GND
Figure 3-2 Schematic
MCU-AN-300037-E-V11
- 10 -
© Fujitsu Microelectronics Europe GmbH
LIN STEPPER MOTOR DRIVER
Chapter 3 Hardware Setup
3.3
Short Description AMIS – 30621
The AMIS – 30621 LIN Microstepping Motordriver is able to drive a bipolar stepper motor
with up to 800 mA. The used motors need to have low impedance. A minimal current of 59
mA have to be drawn by the motor, otherwise the AMIS driver detects an open loop and
switches off the output.
The motor is current controlled by a 20 kHz PWM and it can be chosen between several
stepping modes. (Half Stepping to 1/16 micro stepping)
It supports LIN rev. 1.3 with 19.2 kbaud and acts as a slave on the bus. 128 node addresses
can be used. The address is set by programming 5 bits of the address internal and setting 3
hardwired bits external (HW0 to HW2).
It features protection functions and several positioning and driving configurations.
The AMIS - 30621 needs an 8V to 29V supply voltage. An internal 5V regulator produces the
voltage for the control logic. No further power supply is needed.
3.4
Fujitsu’s MCU
The MCU controls the Stepper motor driver over the LIN-Bus. It acts as Master. In this
example a 16bit MCU the MB90F352 is used, but you can use any controller that has at
least one LIN_UART Interface.
To connect the MCU physically to the Bus Line, you need a LIN Transceiver. Here a
TLE7259 is used.
The PC Communication is realized via UART.
© Fujitsu Microelectronics Europe GmbH
- 11 -
MCU-AN-300037-E-V11
LIN STEPPER MOTOR DRIVER
Chapter 4 Controlling the AMIS 30621
4 Controlling the AMIS 30621
This Chapter describes some basic commands of the AMIS 30621
4.1
LIN Frames
The AMIS 30621 uses 8 Types of LIN frames that are subdivided into Writing-, Reading-,
and Preparing-Frames.
•
A writing frame is sent by the LIN Master to send commands and/or information to
the Slave nodes.
In the example type 4 is used for writing frames. It starts with 0x3C Identifier followed by a
Command Indicator, the Command itself, the physical address and parameters.
Figure 4-1 Writing frame type 4
AppCMD : 0x80 indicates that Data2 contains an application command byte
CMD[6:0]: Command byte AD[6:0] : Slave node’s physical address
•
•
A preparing frame is a writing frame that warns a particular slave node that it will
have to answer in the next frame (hence a reading frame).
A reading frame uses an in-frame response mechanism. That is: the master initiates
the frame (synchronization field + identifier field), and one slave sends back the data
field together with the check field.
Figure 4-2 Preparing frame type 8
4.1.1 Dynamically assigned identifier
The above mentioned frames use the identifiers 0x3C (writing) and 0x3F (reading). Apart
from these identifiers the LIN specification does not indicate how identifier can be allocated.
To keep slave nodes adaptable to a given LIN Network, the idea is to implement a dynamic
assignment of the identifier by the LIN Master. This is done at start-up by writing identifier
and the desired corresponding command in the slave’s RAM.
Figure 4-3 Dynamic ID assignment
MCU-AN-300037-E-V11
- 12 -
© Fujitsu Microelectronics Europe GmbH
LIN STEPPER MOTOR DRIVER
Chapter 4 Controlling the AMIS 30621
The LIN frame shown above uses the 0x3C identifier and links four dynamic IDs to four
ROM pointers that represent the actual command. The AMIS 30621 has nine ROM pointers,
so nine commands can be used via dynamic IDs.
So for example if you want to perform a GetStatus Command you have to set ID1[5:0] =
000000 and ROMp1[3:0] = 0011. Same commands are only available via dynamic IDs. Most
of them use General purpose 2 Data bytes. So again you have to link the ID with the ROM
pointer (e.g. ID4[5:0] = 011000 and ROMp4[3:0] = 0000) and then the command is sent as
part of the LIN frame.
A HardStop command then looks like this:
The bits 6 and 7 are set to one according to parity computation.
4.2
Dummy Frame
According to LIN Spec Rev 1.3 the Slave assumes a bus sleep state if there is no activity on
the bus for 25000 Tbit (1.3 s @19.2 kbaud). In sleep mode the AMIS 30621 drives the motor
to the secure position and goes to Shutdown Mode. To leave the Shutdown mode you have
to send a “GetFullStatus” – Command. To prevent this you have to send a dummy frame
that keeps the driver awake.
In the example a reload timer is used to trigger a LIN message every 400 ms.
To use this needed traffic, the periodic message is used for a GetStatus Command. The
Slave (AMIS device) answers with some status flags, like the state of the external Switch
Input (ESW).
© Fujitsu Microelectronics Europe GmbH
- 13 -
MCU-AN-300037-E-V11
LIN STEPPER MOTOR DRIVER
Chapter 4 Controlling the AMIS 30621
4.3
GetFullStatus
This command is provided to the circuit by the LIN Master to get a complete status of the
circuit and of the Stepper motor. It corresponds to one preparing frame and two successive
LIN in-frame responses with 0x3D indirect ID.
The response frames contain the actual status and parameters of the motor driver according
to the following figure:
Figure 4-4 Status Response Frames
The parameters and flags are explained in the AMIS-30621 Datasheet
4.4
SetMotorParam
This command is used to set the values for the Stepper motor parameters. It corresponds to
a LIN writing frame type 4.
The most important parameters are:
•
•
•
•
•
•
Irun [3:0]
Peak operating current
Ihold [3:0]
Hold current
Vmax [3:0]
Maximum velocity
Vmin [3:0]
Minimum velocity
Shaft
Direction of movement for positive velocity
StepMode [1:0] Stepping mode (Half stepping, ¼ micro step, 1/8 micro step, 1/16
micro step)
The Irun and Ihold parameter have to be set according to the used stepper motor. By
Irun the highest current is defined, that is allowed to drive the motor in case of maximum
load. The Ihold parameter defines the motor current in stop mode. Note that if this value
can not be reached, because the impedance of the motor is too high, or the voltage too low,
the AMIS 30621 interprets this as an open loop and switches off the output.
The current values can be set to 16 different levels that go from 59 mA to 800 mA.
To set the parameters to the LIN frame format required by the motor driver, the
SetMotorParameter() function is used. See section 5.3.2
MCU-AN-300037-E-V11
- 14 -
© Fujitsu Microelectronics Europe GmbH
LIN STEPPER MOTOR DRIVER
Chapter 4 Controlling the AMIS 30621
4.5
SetPosition
This command is provided to the circuit by the LIN Master to drive one or two motors to a
given absolute position. The used frame type is of type 4 and contains the address and the
new position of one or two motors.
Figure 4-5 SetPosition LIN frame
For example and according to figure 4-5 a message containing the following bytes:
( 0x3C | 0x80 | 0x8B | 0x80 | 0x01 | 0x00 | 0x81 | 0x00 | 0x00)
drives the Motor at address 0 to Position 0x0100 and if connected a motor at address 1 to
position 0x0000.
4.6
Summary
This chapter showed the principles of controlling the AMIS 30621. The format of the LIN
frames depends on the task and the used command.
To get a first movement of the stepper motor you have to follow three steps:
1. Wake up the device via GetFullStatus
2. Set the appropriate motor values with SetMotorParam
3. Set a new Position different from zero with SetPosition
4. (Keep the device awake with periodic frames)
For further ways of programming the AMIS 30621 and a complete command list check the
AMIS Datasheet.
© Fujitsu Microelectronics Europe GmbH
- 15 -
MCU-AN-300037-E-V11
LIN STEPPER MOTOR DRIVER
Chapter 5 Software
5 Software
This Chapter describes the Software Principles and its Implementation
The complete software source code can be found in the zip file mcu-an-300037-e-v11lin_stepper_amis.zip. This chapter describes only the most important parts.
5.1
LIN Protocol Handling
The communication according to the LIN Protocol is realized by one Interrupt Service
Routine. This Routine is called when a LIN Break is detected via Master Read back. The
same Routine is used for sending and receiving LIN messages. It is subdivided into 6 states:
0. Bus is idle. Ready to send synch break.
1. After a LIN break is detected, the flag is cleared, the Synch field is sent and the
Reception is enabled.
2. With the next interrupt the Synch field is read back and checked. Then the LIN
Header (Identifier Field) is sent.
3. Again the LIN Header is read back and checked. If the master wants to send, the first
data Byte is sent and added to the Checksum Calculation.
4. In State 4 the Master sends the 2nd to last data byte or receives data bytes from the
slave. If the last byte is sent or received, the checksum is sent or checked.
5. Read back of the Checksum.
All interrupts handled by the LIN ISR are reception Interrupts.
5.1.1 Interrupts during LIN frame
The following illustration gives an overview about the interrupt effort when LIN-UART is bus
master:
LIN State:
0
1
2
3
4
Master Frame
5
Slave Respond
LIN-Bus
Set LBR
TDR=0x55
IRQ: RDRF
IRQ: RDRF
RDR=”synch”
RDR=”header”
Reception-IRQ: RDRF
Reception-IRQ: LBD
Reception-IRQ: RDRF
RXE = 1
RDR=”data”
MCU-AN-300037-E-V11
- 16 -
RDR=”checksum”
RXE = 0
© Fujitsu Microelectronics Europe GmbH
LIN STEPPER MOTOR DRIVER
Chapter 5 Software
5.1.2 State chart of the Interrupt Service Routine
Reception Interrupt
State 0
User Activation
Checksum is read back
State 1
State 5
Reception Interrupt
and last Data sent
IRQ LIN Break
Error
Last Data is read back
Send Checksum
Enable Reception
Send Synch Field
Checksum = 0;
Reception Interrupt
Data is read back
Send LIN Data
Add Data to Checksum
Calculation
State 4
State 2
Reception Interrupt
Synch Field is read back
Send Header Field
Reception Interrupt
State 3
Header Field is read back
Send LIN Data
Add Data to Checksum
Calculation
Every unexpected IRQ or
wrong data read on bus
leads to the Error State
Figure 5-1 ISR State chart
/*--------------------- INTERRUPT SERVICE ROUTINE ---------------------------*/
__interrupt void RxIRQHandler(void) {
if (ESCR2_LBD) {
ESCR2_LBD = 0;
// LIN Break Detection (Read back)?
// Clear flag
if (LIN_State == 1) {
SCR2_RXE = 1;
TDR2 = 0x55;
LIN_State = 2;
LIN_Checksum = 0;
}
else
Rx_Error = 1;
// Enable reception
// Send Synchfield
// Unexpected reception of break
}
else if (SSR2_RDRF) {
Rx_Data = RDR2;
// Reception?
// Get reception data
if (SSR2_ORE || SSR2_FRE) Rx_Error = 2;
© Fujitsu Microelectronics Europe GmbH
- 17 -
// Reception errors?
MCU-AN-300037-E-V11
LIN STEPPER MOTOR DRIVER
Chapter 5 Software
else if (LIN_State == 2) {
if (Rx_Data != 0x55) Rx_Error = 3;
else {
TDR2 = LIN_Header;
LIN_State = 3;
}
}
// Synch field read back?
// Send LIN_Header
else if (LIN_State == 3) {
// Header read back?
if (Rx_Data != LIN_Header) Rx_Error = 4;
else {
if (Master_Send) {
// Master wants to send?
TDR2 = LIN_Data[LIN_Count];
// Send LIN Data
LIN_Checksum = LIN_Data[LIN_Count];
}
LIN_State = 4;
}
}
else if (LIN_State == 4) {
// LIN Data read back / Slave Data
if (Master_Send) {
// Master sent data?
if (Rx_Data != LIN_Data[LIN_Count]) Rx_Error = 5;
LIN_Count++;
if (LIN_Count == DATALENGTH) {
// End of message reached?
LIN_Count = 0;
LIN_State = 5;
LIN_Checksum = LIN_Checksum ^ 0xFF;
TDR2 = LIN_Checksum;
}
else {
TDR2 = LIN_Data[LIN_Count];
// Send next LIN Data
LIN_Checksum = LIN_Checksum + LIN_Data[LIN_Count];
if (LIN_Checksum > 0xFF) LIN_Checksum -=0xFF;
}
}
else {
// Receive Data from Slave
LIN_Data[LIN_Count] = Rx_Data;
LIN_Checksum = LIN_Checksum + Rx_Data;
if (LIN_Checksum > 0xFF) LIN_Checksum -=0xFF;
LIN_Count++;
if (LIN_Count == (reply_count+1)*DATALENGTH)
{
// End of message reached?
LIN_Count = reply_count*DATALENGTH;
LIN_State = 5;
LIN_Checksum = LIN_Checksum ^ 0xFF;
}
}
}
else if (LIN_State == 5)
{
if (Rx_Data != LIN_Checksum)
}
// LIN Checksum read back / Slave Checksum
Rx_Error = 6;
SCR2_RXE = 0;
LIN_State = 0;
reply_count = 0;
}
else
{
// Not recognized interrupt cause
Rx_Error = 7;
SSR2_RIE = 0;
// disable reception interrupt
}
} //end of ISR
The static char array LIN_Data[] is used to store incoming and outgoing data. After the
LIN Header is sent, the variable Master_Send decides if the ISR will send data
(Master_Send == 1) or if the ISR will store the incoming data from a slave
(Master_Send == 0).
MCU-AN-300037-E-V11
- 18 -
© Fujitsu Microelectronics Europe GmbH
LIN STEPPER MOTOR DRIVER
Chapter 5 Software
5.2
Generating LIN frames
5.2.1 Master sends LIN frame
According to the software example you have to follow these steps to send a LIN frame from
master to slave:
0. Set LIN Header
1. Set Master_Send = 1
2. Set Number of data bytes. (Note that the Identifier field contains the maximum
number of data bytes)
3. Write the data bytes in LIN_Data[].
In Start_LIN_Message()
LIN Break is generated.
4. Call Start_LIN_Message()
the
After the LIN Break is generated, the ISR controls the Handling of the LIN message.
void Start_LIN_Message(void)
{
while (LIN_State >0); //waits until all messages are handled without error
Rx_Error = 0;
LIN_State = 1;
LIN_Count = DATALENGTH;
ESCR2_LBD = 0;
ESCR2_LBIE = 1;
// clear possible LIN-Break detection
// enable LIN Break detection (for read back)
ECCR2 = 0x40;
// Set LIN-Break via byte access
}
The Send_frame() function is not
used in the software example. It just
shows the structure of all Functions
that are used to send LIN frames.
void Send_frame() {
LIN_Header
Master_Send
DATALENGTH
= 0x3C;
= 1;
= 8;
Set_LIN_Data_Bytes(0x80, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0xFF);
Start_LIN_Message();
}
5.2.2 Master requests LIN frame from Slave
To get a desired response from the Slave, you have to initiate a Slave Response frame. This
is done by the reserved Identifier 0x3D (according to the Parity bits, the ID Field is 0x7D).
The Slave is addressed by a prior Master Request frame.
Like in the example above, you have to set LIN Header, reset Master_Send and generate a
LIN Break:
0.
1.
2.
3.
Set LIN Header (0x7D)
Set Master_Send = 0
Set Number of data bytes
Call Start_LIN_Message()
4. The incoming data bytes will be stored in LIN_Data[].
© Fujitsu Microelectronics Europe GmbH
- 19 -
MCU-AN-300037-E-V11
LIN STEPPER MOTOR DRIVER
Chapter 5 Software
5.3
Implemented Features
The Example Software provides the following features:
•
Periodical sending of Dummy Frame (GetStatus)
•
Stall Detection with automatic stop
•
Setting Motor Parameters individually:
<
Changing Speed
<
Changing max Operation Current (Irun)
<
Changing Hold Current (Ihold)
<
Toggle Direction
<
Setting Step Mode
•
Reading the Full Status
•
Setting a new Position
5.3.1 DoGetFullStatus
This function uses a master request frame to get two response frames from the AMIS
Device. The Data is stored in LIN_Data[0 to 7] and LIN_Data[8 to 15].
#define MASTERSEND = 0x3C
#define SLAVESEND = 0x7D
void DoGetFullStatus () {
DATALENGTH = 8;
reply_count = 0;
Set_LIN_Data_Bytes(AppCMD,GetFullStatus,AD,0xFF,0xFF,0xFF,0xFF,0xFF);
LIN_Header = MASTERSEND; // Master sends data to slave
Master_Send = 1;
Start_LIN_Message();
if (!Rx_Error)
{
wait(10000);
reply_count = 0;
LIN_Header = SLAVESEND;
Master_Send = 0;
Start_LIN_Message();
}
if (!Rx_Error)
{
wait(10000);
reply_count = 1;
LIN_Header = SLAVESEND;
Master_Send = 0;
Start_LIN_Message();
}
// Master wants data from slave
// Master wants data from slave
while (LIN_State > 0);
// all information stored in LIN_Data[] now
MCU-AN-300037-E-V11
- 20 -
© Fujitsu Microelectronics Europe GmbH
LIN STEPPER MOTOR DRIVER
Chapter 5 Software
5.3.2 SetMotorParameter
This function is used to set the motor parameters. According to the AMIS Datasheet some
data bytes contain more than one parameter. These are placed to the appropriate Bit
positions. At the end all parameter are send via one LIN frame.
BYTE SetMotorParameter(BYTE adress, BYTE Irun, BYTE Ihold, BYTE Vmax, BYTE Vmin,
unsigned short SecPos, BYTE Shaft, BYTE Acc,
BYTE AccShape, BYTE StepMode) {
BYTE data4, data5, data6, data7, data8;
if ((Motion & 0x03) > 0) return 0; // if motor is in motion break
else {
data4 = (Irun << 4) + Ihold;
data5 = (Vmax << 4) + Vmin;
data6 = (BYTE)((SecPos & 0x0700) >> 3) + (Shaft << 4)
+ (Acc & 0x0F);
data7 = (BYTE)(SecPos & 0x00FF);
data8 = 0xE3 + (AccShape<<4) + (StepMode << 2);
Set_LIN_Data_Bytes(AppCMD,SetMotorParam,adress,data4,
data5,data6,data7,data8);
reply_count = 0;
DATALENGTH = 8;
LIN_Header = MASTERSEND; // Master sends data to slave
Master_Send = 1;
}
Start_LIN_Message();
while (LIN_State > 0);
return 1;
}
// process complete
5.3.3 Set Dynamic Identifier
In the example four dynamic Identifiers are used: GetStatus, SetPosition (16-bit), General
Purpose 2 Data bytes and General Purpose 4 Data bytes. The following source code shows
how these IDs are linked to the appropriate ROM pointers
void Set_Dynamic_ID() {
LIN_Header = MASTERSEND;
Master_Send = 1;
DATALENGTH = 8;
LIN_Data[0] = AppCMD;
LIN_Data[1] = DynamicIDassignment;
LIN_Data[2] = 0x80;
//AD = 0, non broad
LIN_Data[3] = 0x81;
//ID1 = 101000 ROMp1
LIN_Data[4] = 0x0E;
//ID2 = 000000 ROMp2
LIN_Data[5] = 0x40;
//ID3 = 010000 ROMp3
LIN_Data[6] = 0x10;
//ID4 = 011000 ROMp4
LIN_Data[7] = 0x60;
reply_count = 0;
=
=
=
=
0001
0011
0100
0000
Start_LIN_Message();
}
while ((LIN_State>0) && (timeout < 10000)) timeout++;
if (timeout < 10000) timeout = 0;
else Rx_Error = 8;
To understand the values of LIN_Data[2..7] see Figure 4-3 Dynamic ID assignment and how
the IDs and ROM pointer are inserted in the LIN frame.
© Fujitsu Microelectronics Europe GmbH
- 21 -
MCU-AN-300037-E-V11
LIN STEPPER MOTOR DRIVER
Chapter 5 Software
5.4
User Menu
The program is controlled via UART Interface. Connect your PCs COM Port to UART 3 and
connect with 19200 baud. The following window should appear:
To get a movement you have first to press ‘i’ to run MotorInit. By this the AMIS device is
switched to normal operating mode and some basic motor parameters are set. Then press
‘+’ to drive the motor to a new position. The new position is the actual position + 0x100.
The implemented features are listed in the menu and explained by itself. The Speed-,
Irun- and Ihold-Functions increase and decrease the value by one respectively. The
value range from 0 to 15. If you call the “New Position”-Function you have to set the new
position value by 4 digits in hex.
5.5
Example Project Structure
The Example software is subdivided into several files:
AMIS30621.c +.h
LIN_ISR.c
uart.c
main.c
5.6
Functions to control the AMIS Device
The LIN Interrupt Service Routine
The LIN and UART concerning functions
The main program and menu
Source Code
Please find the source codes of this application note adapted for MB90350 series in the zip
file: mcu-an-300037-e-v11-lin_stepper_amis.zip
MCU-AN-300037-E-V11
- 22 -
© Fujitsu Microelectronics Europe GmbH
LIN STEPPER MOTOR DRIVER
Chapter 6 Appendix
6 Appendix
6.1
Figures
Figure 3-1 Block diagram ....................................................................................................... 9
Figure 3-2 Schematic ........................................................................................................... 10
Figure 4-1 Writing frame type 4............................................................................................ 12
Figure 4-2 Preparing frame type 8........................................................................................ 12
Figure 4-3 Dynamic ID assignment ...................................................................................... 12
Figure 4-4 Status Response Frames.................................................................................... 14
Figure 4-5 SetPosition LIN frame ......................................................................................... 15
Figure 5-1 ISR State chart ................................................................................................... 17
All figures of chapter 3 are derived from the AMIS 30621 datasheet.
6.2
Information in the WWW
Information about FUJITSU MICROELECTRONICS products can be found here:
http://emea.fujitsu.com/microelectronics
Dedicated information on FUJITSU Microcontroller products including datasheets and
manuals, software examples, application notes and tools can be found here:
http://mcu.emea.fujitsu.com/
Information about AMI Semiconductor can be found here:
www.amis.com
Specific information about the LIN Motor driver (AMIS-30621) can be found here:
http://www.amis.com/products/motor_controllers/amis_30621.html
© Fujitsu Microelectronics Europe GmbH
- 23 -
MCU-AN-300037-E-V11