Renesas V850 Series, V850E/IA1, V850E/IA2, V850E/IA3, V850E/IA4 Note

...
To our customers,
Old Company Name in Catalogs and Other Documents
On April 1st, 2010, NEC Electronics Corporation merged with Renesas Technology Corporation, and Renesas Electronics Corporation took over all the business of both companies. Therefore, although the old company name remains in this document, it is a valid Renesas Electronics document. We appreciate your understanding.
Renesas Electronics website: http://www.renesas.com
April 1 Renesas Electronics Corporation
Issued by: Renesas Electronics Corporation (http://www.renesas.com)
st
, 2010
Send any inquiries to http://www.renesas.com/inquiry.
Notice
1. All information included in this document is current as of the date this document is issued. Such information, however, is
subject to change without any prior notice. Before purchasing or using any Renesas Electronics products listed herein, please confirm the latest product information with a Renesas Electronics sales office. Also, please pay regular and careful attention to additional and different information to be disclosed by Renesas Electronics such as that disclosed through our website.
2. Renesas Electronics does not assume any liability for infringement of patents, copyrights, or other intellectual property rights
of third parties by or arising from the use of Renesas Electronics products or technical information described in this document. No license, express, implied or otherwise, is granted hereby under any patents, copyrights or other intellectual property rights of Renesas Electronics or others.
3. You should not alter, modify, copy, or otherwise misappropriate any Renesas Electronics product, whether in whole or in part.
4. Descriptions of circuits, software and other related information in this document are provided only to illustrate the operation of
semiconductor products and application examples. You are fully responsible for the incorporation of these circuits, software, and information in the design of your equipment. Renesas Electronics assumes no responsibility for any losses incurred by you or third parties arising from the use of these circuits, software, or information.
5. When exporting the products or technology described in this document, you should comply with the applicable export control
laws and regulations and follow the procedures required by such laws and regulations. You should not use Renesas Electronics products or the technology described in this document for any purpose relating to military applications or use by the military, including but not limited to the development of weapons of mass destruction. Renesas Electronics products and technology may not be used for or incorporated into any products or systems whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations.
6. Renesas Electronics has used reasonable care in preparing the information included in this document, but Renesas Electronics
does not warrant that such information is error free. Renesas Electronics assumes no liability whatsoever for any damages incurred by you resulting from errors in or omissions from the information included herein.
7. Renesas Electronics products are classified according to the following three quality grades: “Standard”, “High Quality”, and
“Specific”. The recommended applications for each Renesas Electronics product depends on the product’s quality grade, as indicated below. You must check the quality grade of each Renesas Electronics product before using it in a particular application. You may not use any Renesas Electronics product for any application categorized as “Specific” without the prior written consent of Renesas Electronics. Further, you may not use any Renesas Electronics product for any application for which it is not intended without the prior written consent of Renesas Electronics. Renesas Electronics shall not be in any way liable for any damages or losses incurred by you or third parties arising from the use of any Renesas Electronics product for an application categorized as “Specific” or for which the product is not intended where you have failed to obtain the prior written consent of Renesas Electronics. The quality grade of each Renesas Electronics product is “Standard” unless otherwise expressly specified in a Renesas Electronics data sheets or data books, etc.
“Standard”: Computers; office equipment; communications equipment; test and measurement equipment; audio and visual
equipment; home electronic appliances; machine tools; personal electronic equipment; and industrial robots.
“High Quality”: Transportation equipment (automobiles, trains, ships, etc.); traffic control systems; anti-disaster systems; anti-
crime systems; safety equipment; and medical equipment not specifically designed for life support.
“Specific”: Aircraft; aerospace equipment; submersible repeaters; nuclear reactor control systems; medical equipment or
systems for life support (e.g. artificial life support devices or systems), surgical implantations, or healthcare intervention (e.g. excision, etc.), and any other applications or purposes that pose a direct threat to human life.
8. You should use the Renesas Electronics products described in this document within the range specified by Renesas Electronics,
especially with respect to the maximum rating, operating supply voltage range, movement power voltage range, heat radiation characteristics, installation and other product characteristics. Renesas Electronics shall have no liability for malfunctions or damages arising out of the use of Renesas Electronics products beyond such specified ranges.
9. Although Renesas Electronics endeavors to improve the quality and reliability of its products, semiconductor products have
specific characteristics such as the occurrence of failure at a certain rate and malfunctions under certain use conditions. Further, Renesas Electronics products are not subject to radiation resistance design. Please be sure to implement safety measures to guard them against the possibility of physical injury, and injury or damage caused by fire in the event of the failure of a Renesas Electronics product, such as safety design for hardware and software including but not limited to redundancy, fire control and malfunction prevention, appropriate treatment for aging degradation or any other appropriate measures. Because the evaluation of microcomputer software alone is very difficult, please evaluate the safety of the final products or system manufactured by you.
10. Please contact a Renesas Electronics sales office for details as to environmental matters such as the environmental
compatibility of each Renesas Electronics product. Please use Renesas Electronics products in compliance with all applicable laws and regulations that regulate the inclusion or use of controlled substances, including without limitation, the EU RoHS Directive. Renesas Electronics assumes no liability for damages or losses occurring as a result of your noncompliance with applicable laws and regulations.
11. This document may not be reproduced or duplicated, in any form, in whole or in part, without prior written consent of Renesas
Electronics.
12. Please contact a Renesas Electronics sales office if you have any questions regarding the information contained in this
document or Renesas Electronics products, or if you have any other inquiries.
(Note 1) “Renesas Electronics” as used in this document means Renesas Electronics Corporation and also includes its majority-
owned subsidiaries.
(Note 2) “Renesas Electronics product(s)” means any product developed or manufactured by or for Renesas Electronics.
Application Note
Inverter Control by V850 Series
120° Excitation Method Control by Zero-Cross Detection
V850E/IA1 V850E/IA2 V850E/IA3 V850E/IA4 V850E/MA3
Document No. U17209EJ1V0AN00 (1st edition) Date Published September 2004 N CP(K)
2004
Printed in Japan
[MEMO]
2
Application Note U17209EJ1V0AN
NOTES FOR CMOS DEVICES
1
VOLTAGE APPLICATION WAVEFORM AT INPUT PIN
Waveform distortion due to input noise or a reflected wave may cause malfunction. If the input of the
IL
CMOS device stays in the area between V malfunction. Take care to prevent chattering noise from entering the device when the input level is fixed, and also in the transition period when the input level passes through the area between V
IH
(MIN).
V
HANDLING OF UNUSED INPUT PINS
2
Unconnected CMOS device inputs can be cause of malfunction. If an input pin is unconnected, it is possible that an internal input level may be generated due to noise, etc., causing malfunction. CMOS devices behave differently than Bipolar or NMOS devices. Input levels of CMOS devices must be fixed high or low by using pull-up or pull-down circuitry. Each unused pin should be connected to V via a resistor if there is a possibility that it will be an output pin. All handling related to unused pins must be judged separately for each device and according to related specifications governing the device.
3
PRECAUTION AGAINST ESD
A strong electric field, when exposed to a MOS device, can cause destruction of the gate oxide and ultimately degrade the device operation. Steps must be taken to stop generation of static electricity as much as possible, and quickly dissipate it when it has occurred. Environmental control must be adequate. When it is dry, a humidifier should be used. It is recommended to avoid using insulators that easily build up static electricity. Semiconductor devices must be stored and transported in an anti-static container, static shielding bag or conductive material. All test and measurement tools including work benches and floors should be grounded. The operator should be grounded using a wrist strap. Semiconductor devices must not be touched with bare hands. Similar precautions need to be taken for PW boards with mounted semiconductor devices.
(MAX) and VIH (MIN) due to noise, etc., the device may
IL
(MAX) and
DD
or GND
4
STATUS BEFORE INITIALIZATION
Power-on does not necessarily define the initial status of a MOS device. Immediately after the power source is turned ON, devices with reset functions have not yet been initialized. Hence, power-on does not guarantee output pin levels, I/O settings or contents of registers. A device is not initialized until the reset signal is received. A reset operation must be executed immediately after power-on for devices with reset functions.
5
POWER ON/OFF SEQUENCE
In the case of a device that uses different power supplies for the internal operation and external interface, as a rule, switch on the external power supply after switching on the internal power supply. When switching the power supply off, as a rule, switch off the external power supply and then the internal power supply. Use of the reverse power on/off sequences may result in the application of an overvoltage to the internal elements of the device, causing malfunction and degradation of internal elements due to the passage of an abnormal current. The correct power on/off sequence must be judged separately for each device and according to related specifications governing the device.
6
INPUT OF SIGNAL DURING POWER OFF STATE
Do not input signals or an I/O pull-up power supply while the device is not powered. The current injection that results from input of such a signal or I/O pull-up power supply may cause malfunction and the abnormal current that passes in the device at this time may cause degradation of internal elements. Input of signals during the power off state must be judged separately for each device and according to related specifications governing the device.
Application Note U17209EJ1V0AN
3
These commodities, technology or software, must be exported in accordance with the export administration regulations of the exporting country. Diversion contrary to the law of that country is prohibited.
The information in this document is current as of July, 2004. The information is subject to change without notice. For actual design-in, refer to the latest publications of NEC Electronics data sheets or data books, etc., for the most up-to-date specifications of NEC Electronics products. Not all products and/or types are available in every country. Please check with an NEC Electronics sales representative for availability and additional information.
No part of this document may be copied or reproduced in any form or by any means without the prior
written consent of NEC Electronics. NEC Electronics assumes no responsibility for any errors that may appear in this document.
NEC Electronics does not assume any liability for infringement of patents, copyrights or other intellectual property rights of third parties by or arising from the use of NEC Electronics products listed in this document or any other liability arising from the use of such products. No license, express, implied or otherwise, is granted under any patents, copyrights or other intellectual property rights of NEC Electronics or others. Descriptions of circuits, software and other related information in this document are provided for illustrative
purposes in semiconductor product operation and application examples. The incorporation of these circuits, software and information in the design of a customer's equipment shall be done under the full responsibility of the customer. NEC Electronics assumes no responsibility for any losses incurred by customers or third parties arising from the use of these circuits, software and information.
While NEC Electronics endeavors to enhance the quality, reliability and safety of NEC Electronics products, customers agree and acknowledge that the possibility of defects thereof cannot be eliminated entirely. To minimize risks of damage to property or injury (including death) to persons arising from defects in NEC Electronics products, customers must incorporate sufficient safety measures in their design, such as redundancy, fire-containment and anti-failure features.
NEC Electronics products are classified into the following three quality grades: "Standard", "Special" and "Specific". The "Specific" quality grade applies only to NEC Electronics products developed based on a customer­designated "quality assurance program" for a specific application. The recommended applications of an NEC Electronics product depend on its quality grade, as indicated below. Customers must check the quality grade of each NEC Electronics product before using it in a particular application. "Standard": Computers, office equipment, communications equipment, test and measurement equipment, audio
and visual equipment, home electronic appliances, machine tools, personal electronic equipment and industrial robots.
"Special": Transportation equipment (automobiles, trains, ships, etc.), traffic control systems, anti-disaster
systems, anti-crime systems, safety equipment and medical equipment (not specifically designed for life support).
"Specific": Aircraft, aerospace equipment, submersible repeaters, nuclear reactor control systems, life
support systems and medical equipment for life support, etc.
The quality grade of NEC Electronics products is "Standard" unless otherwise expressly specified in NEC Electronics data sheets or data books, etc. If customers wish to use NEC Electronics products in applications not intended by NEC Electronics, they must contact an NEC Electronics sales representative in advance to determine NEC Electronics' willingness to support a given application.
(Note) (1) "NEC Electronics" as used in this statement means NEC Electronics Corporation and also includes its
majority-owned subsidiaries.
(2) "NEC Electronics products" means any product developed or manufactured by or for NEC Electronics (as
defined above).
M8E 0 2. 11-1
4
Application Note U17209EJ1V0AN
Regional Information
Some information contained in this document may vary from country to country. Before using any NEC Electronics product in your application, pIease contact the NEC Electronics office in your country to obtain a list of authorized representatives and distributors. They will verify:
Device availability
Ordering information
Product release schedule
Availability of related technical literature
Development environment specifications (for example, specifications for third-party tools and
components, host computers, power plugs, AC supply voltages, and so forth)
Network requirements
In addition, trademarks, registered trademarks, export restrictions, and other legal issues may also vary from country to country.
[GLOBAL SUPPORT] http://www.necel.com/en/support/support.html
NEC Electronics America, Inc. (U.S.)
Santa Clara, California Tel: 408-588-6000 800-366-9782
N
EC Electronics (Europe) GmbH
Duesseldorf, Germany Tel: 0211-65030
Sucursal en España
Madrid, Spain Tel: 091-504 27 87
Succursale Française
Vélizy-Villacoublay, France Tel: 01-30-67 58 00
Filiale Italiana
Milano, Italy Tel: 02-66 75 41
Branch The Netherlands
Eindhoven, The Netherlands Tel: 040-244 58 45
Tyskland Filial
Taeby, Sweden Tel: 08-63 80 820
United Kingdom Branch
Milton Keynes, UK Tel: 01908-691-133
NEC Electronics Hong Kong Ltd.
Hong Kong Tel: 2886-9318
NEC Electronics Hong Kong Ltd.
Seoul Branch Seoul, Korea Tel: 02-558-3737
NEC Electronics Shanghai Ltd.
Shanghai, P.R. China Tel: 021-5888-5400
NEC Electronics Taiwan Ltd.
Taipei, Taiwan Tel: 02-2719-2377
NEC Electronics Singapore Pte. Ltd.
Novena Square, Singapore Tel: 6253-8311
J04.1
Application Note U17209EJ1V0AN
5

INTRODUCTION

Target Readers This application note is intended for users who understand the functions of the
V850E/IA1, V850E/IA2, V850E/IA3, V850E/IA4, and V850E/MA3, and who design application systems that use these microcontrollers. The applicable products are shown below.
V850E/IA1 Standard products: Special products:
V850E/IA2: Standard products: Special products:
V850E/IA3 Standard products:
V850E/IA4 Standard products:
V850E/MA3 Standard products: 703132Y, 703132AY, 703133, 703133A, 703133Y, 703133AY, 703134, 703134A, 703134Y, 703134AY, 70F3134, 70F3134A, 70F3134Y, 70F3134AY
Purpose The purpose of this application note is to help the user understand how a brushless DC
motor is controlled via the 120° sensorless drive excitation method that uses PWM output and A/D converter input as a system example of the timer/counter function of the V850E/IA1, V850E/IA2, V850E/IA3, V850E/IA4, and V850E/MA3.
Organization This application note is divided into the following sections.
Control method Software configuration
Hardware configuration Program list
How to Use This Manual It is assumed that the reader of this application note has general knowledge in the fields
of electrical engineering, logic circuits, and microcontrollers.
Cautions 1. Application examples in this manual are intended for the “standard”
quality models for general-purpose electronic systems. When using an example in this manual for an application that requires the “special” quality grade, evaluate each component and circuit to be actually used to see if they satisfy the required quality standard.
2. To use this manual for special-grade products, read the part
numbers as follows:
µ
PD703114 µPD703114(A)
µ
PD70F3114 µPD70F3114(A)
µ
PD703116 µPD703116(A), 703116(A1)
µ
PD70F3116 µPD70F3116(A), 70F3116(A1)
µ
PD703116, 70F3116
µ
PD703116(A), 703116(A1), 70F3116(A), 70F3116(A1)
µ
PD703114, 70F3114
µ
PD703114(A), 70F3114(A)
µ
PD703183, 70F3184
µ
PD703185, 703186, 70F3186
µ
PD703131, 703131A, 703131Y, 703131AY, 703132, 703132A,
6
Application Note U17209EJ1V0AN
For details of hardware functions (especially register functions, setting methods, etc.) and electrical specifications
See the V850E/IA1 Hardware User’s Manual, V850E/IA2 Hardware User’s
Manual, V850E/IA3, V850E/IA4 Hardware User’s Manual, and V850E/MA3 Hardware User’s Manual.
For details of instruction functions
See the V850E1 Architecture User’s Manual.
Conventions Data significance: Higher digits on the left and lower digits on the right
Active low representation: xxx (overscore over pin or signal name) Memory map address: Higher addresses on the top and lower addresses on
the bottom
Note: Footnote for item marked with Note in the text Caution: Information requiring particular attention Remark: Supplementary information
Numeric representation: Binary ... xxxx or xxxxB Decimal ... xxxx Hexadecimal ... xxxxH Prefix indicating the power of 2 (address space, memory capacity): K (kilo): 2 M (mega): 2 G (giga): 2
10
= 1,024
20
= 1,0242
30
= 1,0243 Data type: Word: 32 bits Halfword: 16 bits Byte: 8 bits
Related documents The related documents indicated in this publication may include preliminary versions.
However, preliminary versions are not marked as such.
Documents related to V850E/IA1, V850E/IA2, V850E/IA3, V850E/IA4, V850E/MA3
Document Name Document No. V850E1 Architecture User’s Manual U14559E V850E/IA1 Hardware User’s Manual U14492E V850E/IA2 Hardware User’s Manual U15195E V850E/IA3, V850E/IA4 Hardware User’s Manual U16543E V850E/MA3 Hardware User’s Manual U16397E V850E/IA1, V850E/IA2 AC Motor Inverter Control Using Vector
Operation Application Note Inverter Control by V850 Series 120° Excitation Method Control by Zero-
Cross Detection Application Note
U14868E
This manual
Application Note U17209EJ1V0AN
7
Documents related to development tools (user’s manuals)
Document Name Document No.
IE-V850E-MC, IE-V850E-MC-A (In-Circuit Emulator for V850E/IA1, V850E/IA2)
IE-V850E1-CD-NW (PCMCIA Card Type On-Chip Debug Emulator for V850E/IA3, V850E/IA4, V850E/MA3)
IE-703116-MC-EM1 (In-Circuit Emulator Option Board for V850E/IA1) U14700E IE-703114-MC-EM1 (In-Circuit Emulator Option Board for V850E/IA2) U16533E CA850 Ver. 2.70 C Compiler Package
PM plus Ver. 5.20 U16934E ID850 Ver. 2.50 Integrated Debugger Operation U16217E ID850NW Ver. 2.51 Integrated Debugger
(for V850E/MA3) ID850NWC Ver. 2.51 Integrated Debugger
(for V850E/IA3, V850E/IA4, V850E/MA3) SM850 Ver. 2.50 System Simulator
(for V850E/IA1, V850E/IA2) SM850 Ver. 2.00 or Later System
Simulator (for V850E/IA1, V850E/IA2) RX850 Ver. 3.13 or Later Real-Time OS
RX850 Pro Ver. 3.15 Real-Time OS
RD850 Ver. 3.01 Task Debugger U13737E RD850 Pro Ver. 3.01 Task Debugger U13916E AZ850 Ver. 3.10 System Performance Analyzer U14410E PG-FP4 Flash Memory Programmer U15260E
Operation U16932E C Language U16930E Assembly Language U16931E Link Directive U16933E
Operation U16454E
Operation U16525E
Operation U16218E
External Part User Open Interface Specifications
Basics U13430E Installation U13410E Technical U13431E Basics U13773E Installation U13774E Technical U13772E
U14487E
U16647E
U14873E
8
Application Note U17209EJ1V0AN
CONTENTS
CHAPTER 1 CONTROL METHOD..........................................................................................................12
1.1 Outline of Brushless DC Motor Control.................................................................................. 12
CHAPTER 2 HARDWARE CONFIGURATION.......................................................................................17
2.1 Configuration ............................................................................................................................ 17
2.2 Circuit Diagram ......................................................................................................................... 19
CHAPTER 3 SOFTWARE CONFIGURATION........................................................................................31
3.1 Control Block ............................................................................................................................ 31
3.2 Peripheral I/O............................................................................................................................. 32
3.3 Software Processing Structure ............................................................................................... 34
3.4 Flowchart................................................................................................................................... 36
3.4.1 Main processing...........................................................................................................................36
3.4.2 Motor control processing..............................................................................................................45
3.4.3 U zero-cross point interrupt processing........................................................................................50
3.4.4 V zero-cross point interrupt processing........................................................................................51
3.4.5 W zero-cross point interrupt processing.......................................................................................52
3.4.6 10 mSEC interval interrupt processing.........................................................................................53
3.4.7 A/D converter channel 0 interrupt processing ..............................................................................54
3.4.8 A/D converter channel 1 interrupt processing ..............................................................................55
3.4.9 Hardware initialization ..................................................................................................................56
3.4.10 Common area initialization...........................................................................................................57
3.4.11 Revolution start initialization.........................................................................................................57
3.4.12 LED display..................................................................................................................................58
3.5 Common Areas ......................................................................................................................... 59
3.6 Tables......................................................................................................................................... 60
3.7 Constant Definitions................................................................................................................. 62
CHAPTER 4 PROGRAM LIST ................................................................................................................63
4.1 Program List (V850E/IA1)......................................................................................................... 63
4.1.1 Symbol definition..........................................................................................................................63
4.1.2 Constant definition........................................................................................................................64
4.1.3 Interrupt handler setting ...............................................................................................................67
4.1.4 Startup routine setting ..................................................................................................................69
4.1.5 Main processing function..............................................................................................................72
4.1.6 LED display function.....................................................................................................................76
4.1.7 Motor control interrupt processing function ..................................................................................77
4.1.8 Zero-cross interrupt processing function ......................................................................................81
4.1.9 10 mSEC interval interrupt processing function ...........................................................................83
4.1.10 A/D converter interrupt processing function .................................................................................84
4.1.11 Hardware initialization processing function ..................................................................................84
4.1.12 Common area initialization processing function...........................................................................86
4.1.13 Revolution start initialization processing function.........................................................................86
4.1.14 Link directive file for V850E/IA1....................................................................................................87
4.2 Program List (V850E/IA2)......................................................................................................... 89
Application Note U17209EJ1V0AN
9
4.2.1 Symbol definition......................................................................................................................... 89
4.2.2 Constant definition....................................................................................................................... 90
4.2.3 Interrupt handler setting............................................................................................................... 93
4.2.4 Startup routine setting ................................................................................................................. 95
4.2.5 Main processing function............................................................................................................. 98
4.2.6 LED display function...................................................................................................................102
4.2.7 Motor control interrupt processing function.................................................................................103
4.2.8 Zero-cross interrupt processing function ....................................................................................107
4.2.9 10 mSEC interval interrupt processing function..........................................................................109
4.2.10 A/D converter interrupt processing function................................................................................110
4.2.11 Hardware initialization processing function.................................................................................110
4.2.12 Common area initialization processing function..........................................................................112
4.2.13 Revolution start initialization processing function.......................................................................112
4.2.14 Link directive file for V850E/IA2..................................................................................................113
4.3 Program List (V850E/IA3) ....................................................................................................... 115
4.3.1 Symbol definition........................................................................................................................115
4.3.2 Constant definition......................................................................................................................116
4.3.3 Interrupt handler setting..............................................................................................................119
4.3.4 Startup routine setting ................................................................................................................121
4.3.5 Main processing function............................................................................................................124
4.3.6 LED display function...................................................................................................................128
4.3.7 Motor control interrupt processing function.................................................................................129
4.3.8 Zero-cross interrupt processing function ....................................................................................132
4.3.9 10 mSEC interval interrupt processing function..........................................................................135
4.3.10 A/D converter interrupt processing function................................................................................135
4.3.11 Hardware initialization processing function.................................................................................136
4.3.12 Common area initialization processing function..........................................................................138
4.3.13 Revolution start initialization processing function.......................................................................138
4.3.14 Link directive file for V850E/IA3..................................................................................................138
4.4 Program List (V850E/IA4) ....................................................................................................... 140
4.4.1 Symbol definition........................................................................................................................140
4.4.2 Constant definition......................................................................................................................141
4.4.3 Interrupt handler setting..............................................................................................................144
4.4.4 Startup routine setting ................................................................................................................146
4.4.5 Main processing function............................................................................................................149
4.4.6 LED display function...................................................................................................................153
4.4.7 Motor control interrupt processing function.................................................................................154
4.4.8 Zero-cross interrupt processing function ....................................................................................157
4.4.9 10 mSEC interval interrupt processing function..........................................................................160
4.4.10 A/D converter interrupt processing function................................................................................160
4.4.11 Hardware initialization processing function.................................................................................161
4.4.12 Common area initialization processing function..........................................................................163
4.4.13 Revolution start initialization processing function.......................................................................163
4.4.14 Link directive file for V850E/IA4..................................................................................................163
4.5 Program List (V850E/MA3)..................................................................................................... 165
4.5.1 Symbol definition........................................................................................................................165
4.5.2 Constant definition......................................................................................................................166
4.5.3 Interrupt handler setting..............................................................................................................169
10
Application Note U17209EJ1V0AN
4.5.4 Startup routine setting ................................................................................................................171
4.5.5 Main processing function............................................................................................................174
4.5.6 LED display function...................................................................................................................178
4.5.7 Motor control interrupt processing function ................................................................................179
4.5.8 Zero-cross interrupt processing function ....................................................................................182
4.5.9 10 mSEC interval interrupt processing function .........................................................................184
4.5.10 A/D converter interrupt processing function ...............................................................................185
4.5.11 Hardware initialization processing function ................................................................................185
4.5.12 Common area initialization processing function.........................................................................187
4.5.13 Revolution start initialization processing function.......................................................................187
4.5.14 Link directive file for V850E/MA3................................................................................................188
Application Note U17209EJ1V0AN
11

CHAPTER 1 CONTROL METHOD

1.1 Outline of Brushless DC Motor Control

A brushless DC (BLDC) motor consists of a stator, coil, and rotor. The rotor, which includes a permanent magnet,
is rotated by the action of the magnetic field generated by the coil of the stator.
The magnetic field is generated by exciting the coil wound around the stator in a specific sequence. By controlling the intensity and cycle of the magnetic field with a microcontroller, the torque response and the number of revolutions of the motor can be controlled.
This section explains how to control a BLDC motor without a sensor by using the V850E/IA1, V850E/IA2, V850E/IA3, V850E/IA4, or V850E/MA3.
Figure 1-3 shows an example of the circuit of a three-phase brushless DC motor. The internal PWM output function of the microcontroller is used to control the current that flows through the motor, by using a transistor array consisting of six transistors.
The magnetic field is generated by controlling the excitation pattern of the six transistors as shown in Table 1-1.
Table 1-1. Excitation Pattern
Upper Arm Lower Arm Excitation
Pattern
<1> Active Inactive Inactive Inactive Active Inactive U → V <2> Active Inactive Inactive Inactive Inactive Active U → W <3> Inactive Active Inactive Inactive Inactive Active V → W <4> Inactive Active Inactive Active Inactive Inactive V → U <5> Inactive Inactive Active Active Inactive Inactive W → U <6> Inactive Inactive Active Inactive Active Inactive W → V
U V W U V W
Excitation
Direction
12
Application Note U17209EJ1V0AN
CHAPTER 1 CONTROL METHOD
Figure 1-1. Three-Phase DC Motor Voltage Waveform
<1> <2> <3> <4> <5> <6>
U phase
U phase
Driving voltage waveform
V phase
V phase
W phase
W phase
U phase
Induced voltage waveform
V phase
W phase
Application Note U17209EJ1V0AN
13
Magnetic
flux
CHAPTER 1 CONTROL METHOD
Figure 1-2. Rotor Position Detection Principle
CC
V
N
U
A
W-phase stator is located in the
center of the N pole
and S pole of a
S
magnet rotor
S
V
CC
N
U
A
S
V
W
V
WC
N
(a) Rotor position <1> … U-phase stator: S pole
V-phase stator: N pole W-phase stator: Center point
S
U
N
N
V
W
V
WC
A
V
CC
S
= 0
= 0
S
V
VC
= 0
V
W
N
(b) Rotor position <2> … U-phase stator: S pole
V-phase stator: Center point W-phase stator: N pole
S
U
V
N
CC
V
N
W
S
V
UC
= 0
A
(d) Rotor position <4> … U-phase stator: N pole
V-phase stator: S pole W-phase stator: Center point
S
U
N
V
VC
= 0
V
W
S
A
(e) Rotor position <5> … U-phase stator: N pole
V-phase stator: Center point W-phase stator: S pole
14
(c) Rotor position <3> … U-phase stator: Center point
V-phase stator: S pole W-phase stator: N pole
N
U
S
V
UC
= 0
Return to (a)
N
V
S
V
CC
A
W
N
V
CC
(f) Rotor position <6> … U-phase stator: Center point
V-phase stator: N pole W-phase stator: S pole
Application Note U17209EJ1V0AN
CHAPTER 1 CONTROL METHOD
Figure 1-3. Configuration of Three-Phase Brushless DC Motor
TrU
TrU
1
TrV
1
On Off Off
U
V
2
TrV
2
Off On Off
PWM control
TrW
TrW
1
U
W
V
W
2
U
Zero-cross point detection
V W
Application Note U17209EJ1V0AN
15
CHAPTER 1 CONTROL METHOD
The 120° control method for a BLDC motor without a sensor is described below.
To control a BLDC motor, the rotor position must be known.
To control a BLDC motor without a senso r, the rotor position is estimated using induced voltage.
The induced voltage is in phase with the driving voltage waveform and its waveform is close to a sine wave, as shown in Figure 1-1. Figure 1-2 illustrates how the polarity of the stator of the motor is switched and how the magnet rotor revolves.
As shown in Figures 1-1 and 1-2, a three-phase DC motor rotates its rotor by switching the three driving current patterns on the three coil phases.
During period <1> in Figure 1-1, for example, transistor Tr U
1 in Figure 1-3 is turned on by the U-phase dr iving pin,
and TrV2 is turned on by the V-phase driving pin, causing the current to flow from the U-phase driving pin toward the V­phase driving pin. At this time, the W-phase coil seems to be disconnected from the driver circuit and induced voltage is generated.
This induced voltage is used to detect the rotor position.
To control the number of revolutions of the motor, the voltage applied to the motor is controlled to change the current flowing through the coil. To change the voltage, a waveform that is controlled by PWM is applied to the transistor.
The voltage is changed by applying a waveform (PWM waveform) in proportion to the voltage to be applied, to the transistors on the lower arm side (TrU
2, TrV2, and TrW2) while the transistors on the upper arm side (TrU1, TrV1, and
TrW1) are on.
16
Application Note U17209EJ1V0AN

CHAPTER 2 HARDWARE CONFIGURATI ON

This chapter describes the hardware configuration.

2.1 Configuration

The reference system’s main functions are described below. In this reference system, when the revolution
specification switch is pressed after power application, the motor starts revolving in the direction specified.
Figure 2-1. Overall System Configuration
Volume for
speed control
Driver IC
Reset circuit
Revolution
specification SW
LED display
3
13
A/D converter
RESET
Port
Timer
Microcontroller
WDT
6
V-U V-V V-W
Interrupt
Position
detection
Position
detection
Position
detection
M
Current voltage
conversion
Current voltage
conversion
V-U
V-V
V-W
Application Note U17209EJ1V0AN
17
CHAPTER 2 HARDWARE CONFIGURATION
(1) Volume for speed control
Volume for increasing and decreasing the number of revolutions of the motor
(2) Revolution specification SW
CW, CCW, and STOP switches
(3) LED display
LED displaying the number of revolutions, operation time, etc.
(4) WDT
Watchdog timer
(5) Driver IC
Driver for driving motor
(6) Current voltage converter
Converting the motor driving current to voltage, used for detecting overcurrent
(7) Position detector
Rotor position estimation signal output from the induced voltage
18
Application Note U17209EJ1V0AN
CHAPTER 2 HARDWARE CONFIGURATION

2.2 Circuit Diagram

Figures 2-2 to 2-6 show diagrams of the sample reference system circuit.
This sample reference system circuit diagram includes the V850E/IA1, V850E/IA2, V850E/IA3, V850E/IA4, or V850E/MA3, a reset circuit, oscillator, a pin handling microcontroller peripheral block, operation mode switch block, LED output block, watchdog timer circuit block, drive circuit block, motor controller, and motor revolution indicator.
(1) Microcontroller and microcontroller peripheral block
The V850E/IA1, V850E/IA2, V850E/IA3, V850E/IA4, or V850E/MA3 includes a reset circuit, an oscillator that uses a resonator, and a block for handling the MODE pin and unused pins.
(2) Operation mode switch block
This includes switches that set the operation mode as CW or CCW operation.
(3) LED output block
This block includes 16 LEDs, which are used to indicate the revolution speed (rpm), errors, etc.
(4) Watchdog timer circuit block
This block uses the V850E/IA3, V850E/IA4, or V850E/MA3 stops for one ms or longer.
(5) Drive circuit block
The 6-phase outputs from the inverter timer are converted to U-, V-, and W-phase output for the motor driver. This drive circuit is not shown in detail in this example, since it varies depending on the motor’s specifications.
(6) Motor controller
This block includes the HPS-3-AS, LM324, and other devices that are used to measure the motor’s U and V drive currents via A/D conversion.
(7) Motor rotation indicator
This block includes a volume adjuster and the LM324 for setting the motor’s revolution speed (rpm).
µ
PD74HC123A to output stop signals when pulse output from the V 850E/IA1, V850E/IA2,
Application Note U17209EJ1V0AN
19
[MEMO]
CHAPTER 2 HARDWARE CONFIGURATION
20
Application Note U17209EJ1V0AN
CHAPTER 2 HARDWARE CONFIGURATION
Figure 2-2. Circuit Diagram of V850E/IA1
41
Speed Cont.
+5V
D1
21
RESE
T
SW
SW1
+5V
47
R55
SW_CW SW_CCW SW_STOP
7SEGLED1
SW2 SW3 SW4
3
VR1A 10K
3 2
R17 10K
U3A
12
74ACT14
C2 47uF
C4 33pF
C5 33pF
10K
KHz
uSEC
uSEC
+7V+5V
+
-
R77
4
U1A LM324
11
RESET
5MHz
CLOCK 5MHz
+5V
R78
10K
7SEG_LEDx8
1
R1
2.2K
U3B
34
74ACT14
CKSEL
R51
R53
47
47 R57 47
MODE
R79
10K
A
B
C
rpm
D
E
F
G
DP
DG1 DG2 DG3 DG4 DG5 DG6 DG7
WE
Velocity
141
142
143
144
ANI04
ANI05
ANI06
1
ANI07
2
AVDD
3
AVSS
4
AVREF1
5
ANI10
6
ANI11
7
ANI12
8
ANI13
9
ANI14
10
ANI15
11
ANI16
12
ANI17
13 R36 10K R38 10K R40 10K R42 10K R44 10K R47 10K
R65 10K R67 10K R70 10K R74 10K
1 2 3 4 5 6 7 8
10 11 12 13 14 15 16
18
LED_Seg1 LED_Seg2 LED_Seg3 LED_Seg4 LED_Seg5 LED_Seg6 LED_Seg7 LED_Seg8
LED_Dig1 LED_Dig2 LED_Dig3 LED_Dig4
LED_WE
TRIG_DBG
14
AD3_DBG
15
AD2_DBG
16
AD1_DBG
17
AD0_DBG
18
SYNC
19
CLK_DBG
20
RESET
21
CVDD
22
CVSS
23
X1
24
X2
25
CKSEL
26
MODE0
27
MODE1
28
MODE2
29
SI0/P40
30
SO0/P41
31
SCK0/P42
32
SI1/P43
33
SO1/P44
34
SCK1/P45
35
CRXD/P46
36
CTXD/P47
uPD70F3116GJ
V_U V_V V_W
RXD0/P3037TXD0/P3138RXD1/P3239TXD1/P33
40
R88 10K
R89 10K
R90 10K
R87 10K
135
136
137
138
139
140
AVSS
ANI00
ANI01
ANI02
ANI03
AVREF0
ASCK1/P34
RXD2/P3542TXD2/P3643ASCK2/P3744TI2/INTP20/P20
41
45
46
R92 10K
R93 10K
R91 10K
R94 10K
R10 10K
R11 10K
R12 10K
R2 10K
R3 10K
129
130
131
132
133
134
AVDD
TO011
TO012
TO013
TO014
TO015
TCLR2/INTP25/P25
TI3/INTP30/TCLR3/P26
TO21/INTP21/P21
TO22/INTP22/P22
TO23/INTP23/P23
TO24/INTP24/P24
47
48
49
50
51
52
R95 10K
R96 10K
R97 10K
R98 10K
R99 10K
R4 10K
126
127
128
VSS5
VSS3
VDD3
TO010
TO3/INTP31/P27
VDD353VSS354VSS555VDD5
P53
P54
P55
R5 10K
R6 10K
R13 10K
116
117
118
119
120
121
122
123
124
125
VDD5
TO000
TO001
TO002
TO003
TO004
TO005
AD0/PDL057AD1/PDL158AD2/PDL259AD3/PDL360AD4/PDL461AD5/PDL562AD6/PDL663AD7/PDL764AD8/PDL865AD9/PDL966AD10/PDL1067AD11/PDL1168AD12/PDL1269AD13/PDL1370AD14/PDL1471AD15/PDL15 56
P56
INTP4/P05
INTP5/P06
INTP6/P07
R7 10K
R14 10K
R15 10K
R8 10K
R16 47
110
111
112
113
114
115
NMI/P00
ESO0/INTP0/P01
ESO1/INTP1/P02
ADTRG0/INTP2/P03
ADTRG1/INTP3/P04
TCLR11/INTP111/P15
R100 10K
R101 10K
R102 10K
R9 10K
109
TCUD11/INTP110/P14
TIUD11/TO11/P13 TCLR10/INTP101/P12 TCUD10/INTP100/P11
TIUD10/TO10/P10
HLDRQ/PCM3
HLDAK/PCM2
CLKOUT/PCM1
WAIT/PCM0 ASTB/PCT6
UWR/PCT1 LWR/PCT0
CS7/PCS7 CS6/PCS6 CS5/PCS5 CS4/PCS4 CS3/PCS3 CS2/PCS2 CS1/PCS1 CS0/PCS0 A23/PDH7 A22/PDH6 A21/PDH5 A20/PDH4 A19/PDH3 A18/PDH2 A17/PDH1 A16/PDH0
72
PCM4
PCT7 PCT5
RD/PCT4
PCT3 PCT2
VDD5 VSS5 VPP
1
100K
R80
10K
100K
R86
10K
100K
R108
10K
+12V
TP2 LC-2-G
1
6
5
+12V
6
5
R45
[W]
HPS-3-AS
CT1
IN-
IN+
R20
HPS-3-AS CT2
IN-
IN+
C9
0.1uF
C20
0.1uF
C21
0.1uF
TP3 LC-2-G
1
10K
R106
R107
+12V
GND
+12V
GND
R73 R76
R84 R85
[MOT OUT]
J1 1
2 3
100K
LM324
8
R103
4.7K
C6
100K
4.7K
4.7K
0.1uF
CN 3P
I_V
C7
I_U
V_U
V_V
V_W
C1
0.01uF film
LM339
LM339
LM339
22K
0.1uF
C8
R104
6 5
C3
0.1uF
1M
1M
0.1uF
­+
+12V
C22
R18
LM324
U1B
7
411
R28
-
9
+
10
4 11
+5V
1M
0.01uF film
U1C
R69
R82
+12V
1 2
NC
3
OUT
4
VR2
10K
1K
+12V
1 2
NC
3
OUT
4
AGND
VR3
R46
1K
10K 10K
10K 10K
10K 10K
C23
1uF
22K
R19
R21
2.2K
R35
2.2K
R64
U6A
312
7
+
1
6
-
R81
U6B
312
5
+
2
4
-
+12V
U6C
312
9
+
14
8
-
TP1 LC-2-G
[U] [V]
U2
1
HU
2
LU
3
HV
4
LV
5
HW
6
LW
7
ERR
OU OV
OW
MOT_DRV
U
8
V
9
W
10
R72
R83
R105
C14
0.1uF
WDO
C15
0.1uF
13
C16
0.1uF
Mot_Stop Mot_UH Mot_UL
Mot_VH Mot_VL
Mot_WH Mot_WL
+3.3V
+5V
C10
0.1uF
C17
0.1uF
C11
0.1uF
R22 10K R23 10K R24 10K R25 10K R26 10K R27 10K R29
R30 R31 10K R32 10K R33 10K R34 10K R37 10K R39 10K R41 10K R43 10K
R48 10K R49 10K R50 10K R52 10K R54 10K R56 10K R58 10K R59 10K R60 10K R61 10K R62 10K R63 10K R66 10K R68 10K R71 10K R75 10K
C18
0.1uF
C12
0.1uF
10K 10K
C19
0.1uF
C13
0.1uF
U7A
1
CLK
2
W_CLR
3
ERR
WDT
108
P108 107 106 105 104
P104 103
P103 102
P102 101
P101 100
P100 99
P99 98
P98 97
P97 96
P96 95
P95 94
P94 93
P93 92
P92 91
P91 90
P90 89
P89 88
P88 87
P87 86
P86 85
P85 84
P84 83
P83 82
P82 81
P81 80
P80 79
P79 78
P78 77
P77 76
P76 75
P75 74
P74 73
P73
WD_CLR
Watch Dog & Error
+12V +7V
J2
CON6
1 2 3 4 5 6
+5V +3.3V
-7V
POWER
Application Note U17209EJ1V0AN
21
Speed Cont.
D1
RESET SW
SW1
21
7SEGLED1
+5V
VR1A
41
10K
SW2SW_CW SW3SW_CCW SW4SW_STOP
3
R12 10K
C2 47uF
KHz
uSEC
uSEC
+7V+5V
411
U1A LM324
3
+
2
-
U3A
12
74ACT14
RESET
+5V
+5V
R47
R48
10K
10K
1
R1
2.2K
34
R28
MODE0
CKSEL
R38
R49 10K
rpm
7SEG_LEDx8
U3B
74ACT14
47
47
A B
C D
E
F
G
DP
DG1 DG2 DG3 DG4 DG5 DG6 DG7
WE
CHAPTER 2 HARDWARE CONFIGURATION
Figure 2-3. Circuit Diagram of V850E/IA2
Velocity
R2 10K
R3 10K
R4 10K
R5 10K
R6 10K
R7 10K
100
96
95
94
88
U4
ANI04
ANI0399ANI0298ANI0197ANI00
SI1/RXD1/P3227SO1/TXD1/P33
TXD0/P31
26
28
29
R53 10K
R54 10K
R55 10K
R42 10K
AVSS0
SCK1/ASCK1/P34
TI2/INTP20/P20
TO21/INTP21/P21
30
31
C4 33pF
C5 33pF
1 2 3 4 5 6 7 8
10 11 12 13 14 15 16
18
4MHz
CLOCK 4MHz
LED_Seg1 LED_Seg2 LED_Seg3 LED_Seg4 LED_Seg5 LED_Seg6 LED_Seg7 LED_Seg8
LED_Dig1 LED_Dig2 LED_Dig3 LED_Dig4
LED_WE
1
ANI05
2
AVDD1
3
AVSS1
4
ANI10
5
ANI11
6
ANI12
7
ANI13
8
ANI14
9
ANI15
10
ANI16
11
ANI17
12
MODE0
13
VSS3
14
RVDD
15
REGOUT
16
REGIN
17
X1
18
X2
19
RESET
20
CVSS
21
CKSEL
22
SI0/P40
23
SO0/P41
24
SCK0/P42
25
RXD0/P30
uPD70F3114GC
V_U V_V V_W
87
TO01593TO01492TO01391TO01290TO01189TO010
AVDD0
TO23/INTP23/P23
TCLR2/INTP25/P25
TI3/INTP30/TCLR3/P26
TO3/INTP31/P27
VSS38VDD39PDL0/AD040PDL1/AD141PDL2/AD242PDL3/AD343PDL4/AD444PDL5/AD545PDL6/AD646PDL7/AD747PDL8/AD848PDL9/AD949PDL10/AD10
TO22/INTP22/P22
TO24/INTP24/P24
32
33
34
35
36
37
R56 10K
R57 10K
R58 10K
R59 10K
R60 10K
86
VSS
VDD
TO00585TO00484TO00383TO00282TO00181TO000
R8 10K
R9 10K
R10 10K
R11 10K
80
79
78
77
76
ESO1/INTP1/P02
INTP4/TO3OFF/P05
ADTRG1/INTP3/P04
ADTRG0/INTP2/P03
TCLR10/INTP101/P12 TCUD10/INTP100/P11
50
ESO0/INTP0/P01
NMI/P00
TIUD10/TO10/P10
PCM1/CLKOUT
PCM0/WAIT
PCT6/ASTB
PCT4/RD PCT1/UWR PCT0/LWR
VSS3
MODE1/VPP
PDH5/A21 PDH4/A20 PDH3/A19 PDH2/A18 PDH1/A17
PDH0/A16 PDL15/AD15 PDL14/AD14 PDL13/AD13 PDL12/AD12 PDL11/AD11
TP1 LC-2-G
[U] [V]
Mot_UH Mot_UL
Mot_VH Mot_VL
Mot_WH Mot_WL
+3.3V
+5V
C11
0.1uF
Mot_Stop
C12
C13
C14
0.1uF
0.1uF
0.1uF
C16
0.1uF
U6A
1
CLK
2
W_CLR
3
ERR
WDT
WDO
13
75 74 73 72 71 70 69 68 67 66 65 64
VDD
63 62 61 60 59 58 57 56 55 54 53 52 51
R18 10K R19 10K R20 10K R21 10K
R22 10K R23 10K R25 10K R26 10K R27 10K
MODE1
R31 10K R32 10K R33 10K R34 10K R35 10K R36 10K R37 10K
R39 10K R40 10K R41 10K
WD_CLR
C9
0.1uF
C10
0.1uF
U2
1
HU
2
LU
3
HV
4
LV
5
HW
6
LW
7
ERR
OU
OV
OW
MOT_DRV
U
8
V
9
W
10
R45
R62
R68
TP3
TP2
LC-2-G
LC-2-G
[W]
+12V
100K
10K
100K
10K
100K
10K
+12V
R29
R51
R65
R71
1
HPS-3-AS
CT1
6
5
R15
HPS-3-AS CT2
6
5
1
C1
0.01uF film
R43
R52
22K
0.1uF
1
LM339
2
LM339
14
LM339
R13
11
-
U1B
6
+
5
4
C3
0.1uF
9
10
C8
+12V
1M
1M
R67
C19
0.1uF
+12V
1
+12V
IN-
2
NC
3
OUT
4
GND
IN+
VR2
10K
1K
+12V
1
+12V
IN-
2
NC
3
OUT
4
GND
IN+
AGND
VR3
10K
C15
0.1uF
C17
0.1uF
C18
0.1uF
R30
1K
10K
R46
10K
R50
10K
R63 R64
10K
R69
10K
R70
10K
22K
R14
2.2K
R16
R24
2.2K
U5A
312
7
+
6
-
U5B
312
5
+
4
-
+12V
U5C
312
9
+
8
-
C20 1uF
LM324
7
R17
0.01uF film
-
U1C
+
4 11
+5V
1M
100K
LM324
8
R44
R61
[MOT OUT]
J1 1
2 3
CN 3P
I_V
100K
C6
C7
0.1uF I_U
4.7K V_U
4.7K V_V
R66
4.7K V_W
1
Watch Dog & Error
V
+12V +7V
J2
CON6
1 2 3 4 5 6
+5 +3.3V
-7V
Application Note U17209EJ1V0AN
POWER
23
D1
RESET SW
SW1
Speed Cont.
Comp. Ref.
SW_CW SW_CCW SW_STOP
CHAPTER 2 HARDWARE CONFIGURATION
Figure 2-4. Circuit Diagram of V850E/IA3
PDL9 PDL8 PDL7 PDL6
PDL4 PDL3 PDL2
VSS VDD PDL1 PDL0
1
100K
R40
10K
+12V
TP2 LC-2-G
1
6
5
+12V
6
5
R18
[W]
HPS-3-AS
CT1
IN-
IN+
R9
HPS-3-AS CT2
IN-
IN+
C10
0.1uF
TP3 LC-2-G
1
10K
R39
+12V
OUT
GND
+12V
OUT
GND
R38
NC
10K
NC
[MOT OUT]
J1 1
2 3
100K
LM324
14
C3
100K
4.7K
0.1uF
CN 3P
I_V
C5
I_U
V_U
C1
0.01uF film
22K
0.1uF
C6
10
C2
0.1uF
9
1M
R7
-
U1C
+
411
13 12
+12V
LM324
8
R12
0.01uF film
-
U1D
+
411
+5V
R36
+12V
1 2 3 4
VR2
1K
+12V
1 2 3 4
AGND
VR3
R19
1K
10K 10K
22K
R8
2.2K
R10
R17
2.2K
R35
U5A
312
7
+
1
6
­LM339
TP1 LC-2-G
[U] [V]
Mot_UH Mot_UL
Mot_VH Mot_VL
Mot_WH Mot_WL
+2.5V
+5V
60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41
LED_Dig2 LED_Dig1 LED_Seg8 LED_Seg7 LED_Seg6 LED_Seg5 LED_Seg4 LED_Seg3
LED_Seg2 LED_Seg1
R21 10K R23 10K R25 10K R27 10K R29 10K R30 10K R31 10K
C7
0.1uFC80.1uFC90.1uF
C12
C13
C11
0.1uF
0.1uF
0.1uF
U2
1
HU
2
LU
3
HV
4
LV
5
HW
6
LW
7
ERR
OU OV
OW
MOT_DRV
U
8
V
9
W
10
R37
+7V+5V
VR1A
4
10K
3
1
4
U1A LM324
3
+
1
2
-
11
R2
2.2K
Velocity
R4 10K
R5 10K
R6 10K
R3 10K
FLMD0
+7V+5V
51
VR1B 10K
4
U1B
5
+
6
-
11
U4A
12
74ACT14
RESET
+5V
R32 10K
LM324
7
34
R33
10K
R1
2.2K
U4B
74ACT14
R34 10K
R13 10K R14 10K R15 10K R16 10K
R20 10K R22 10K
R24 10K R26 10K R28 10K
V_U V_V
V_W
1
ANI00
2
ANI01
3
P70/ANI20
4
P71/ANI21
5
P72/ANI22
6
P73/ANI23
7
AVDD
8
AVSS
9
CMPREF
10
AVSS
11
AVDD
12
P74/ANI24
13
P75/ANI25
14
ANI10
15
ANI11
16
ANI12
17
ANI13
18
P00/INTP0/TOQ0OFF
19
P02/INTP2/TOP2OFF
20
P03/INTP3
uPD70F3184GC
U3
75
80
79
78
77
76
PLLSIN
P17/TOP21/TIP21
P16/TOQ00/TIP20
P13/TOQ0B2/TIQ00
P14/TOQ0T3/EVTQ0
P15/TOQ0B3/TRGQ0
VDD25VSS
P04/INTP4/ADTRG0
P05/INTP5/ADTRG1
P06/INTP623P07/INTP7
21
22
24
26
74
73
72
71
70
69
68
67
VDD
EVSS
EVDD
FLMD0
P10/TOQ0T1/TIQ01/TOQ01
P12/TOQ0T2/TIQ03/TOQ03
P11/TOQ0B1/TIQ02/TOQ02
EVDD30EVSS
P40/SIB027P41/SOB028P42/SCKB0
CVDD
29
31
32X233X134
LED_Dig4
LED_WE
66
VSS
RESET36P43/TOP00/TIP00
P44/TOP01/TIP01
CVSS
35
37
38
LED_Dig3
61
PDL10
PDL1162PDL1263PDL1364PDL1465PDL15
P35/TIUD10/TO10 P33/SOB1/TXDA1
P32/SIB1/RXDA1
VSS39VDD
40
PDL5/FLMD1
P37/TCLR10
P36/TCUD10
P34/SCKB1
P31/TXDA0
P30/RXDA0
2
+5V
R11
2 1
10K
C4
47uF
SW2 SW3 SW4
7SEGLED1
KHz
uSEC
uSEC
rpm
DG1 DG2 DG3 DG4 DG5 DG6 DG7
7SEG_LEDx8
R41
2
LM339
14
LM339
1M
R42
4.7K V_V
1M
R52
4.7K V_W
R53
C18
0.1uF
U5B
C19
0.1uF
312
5
+
4
-
+12V
U5C
312
9
+
8
-
100K
R48
K
R43 10K
R44 10
R45 10K
1
A
2
B
3
C
4
D
5
E
6
F
7
G
8
DP
10 11 12 13 14 15 16
18
WE
LED_Seg1 LED_Seg2 LED_Seg3 LED_Seg4 LED_Seg5 LED_Seg6 LED_Seg7 LED_Seg8
LED_Dig1 LED_Dig2 LED_Dig3 LED_Dig4
LED_WE
15pF
R46 10K
R47 10K
4MHz
C15
C16 15pF
WD_CLR
U6A
1
CLK
2
W_CLR
3
ERR
WDT
WDO
13
Watch Dog & Error
+12V +7V
+5V +3.3V
J2
1 2 3 4 5 6
CON6
-7V
R51
10K
100K
R54
R57
10K
C14
0.1uF
0.1uF
R49
10K
R50
10K
R55
10K
R56
10K
C17
POWER
Application Note U17209EJ1V0AN
25
RESE SW
Speed Cont.
Comp. Ref.
D1
SW1
+5V
21
T
7SEGLED1
CHAPTER 2 HARDWARE CONFIGURATION
Figure 2-5. Circuit Diagram of V850E/IA4
PDL9
PLD8 EVDD EVSS
PDL7
PDL6
PDL5/FLMD1
PDL4
PDL3
PDL2
VSS
VDD PDL1 PDL0
P27/TOP31
P26/TOQ10 P37/TCLR10 P36/TCUD10
P34/SCKB1
P31/TXDA0
P30/RXDA0
VSS
1
100K
10K
100K
10K
100K
10K
TP3
TP2
LC-2-G
LC-2-G
[V]
[W]
1
1
C1
22K
C6
0.1uF
10
C2
0.1uF
R77
9
1M
1M
0.1uF
R14
11
-
U1C
+
4
-
13 12
+12V
+5V
1M
C19
C13
0.1uF
C15
0.1uF
C18
0.1uF
10K
R56
R80
+12V
+12V
R52
R61 R74
R79
OUT GND
OUT GND
NC
10K
NC
VR2
AGND
VR3
+12V
1 2 3 4
1K
+12V
1 2 3 4
R29
1K
10K 10K
10K 10K
10K 10K
C20
0.1uF
22K
R15
2.2K
R18
R27
2.2K
R49
U5A
312
7
+
1
6
­LM339
R58
U5B
312
5
+
2
4
­LM339
+12V
U5C
312
9
+
14
8
­LM339
HPS-3-AS
CT1
6
IN-
5
IN+
+12V
R17
HPS-3-AS CT2
6
IN-
5
IN+
+12V
R28
R57
R75
R81
0.01uF film
LM324
8
R19
0.01uF film
11
U1D
+
4
R50
R59
100K
LM324
14
R76
4.7K
[MOT OUT]
J1 1
2 3
CN 3P
I_V
100K
C4
C5
0.1uF I_U
4.7K V_U
4.7K V_V
V_W
TP1 LC-2-G
[U]
Mot_UH Mot_UL
Mot_VH Mot_VL
Mot_WH Mot_WL
+2.5V
+5V
75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51
LED_Dig2 LED_Dig1
LED_Seg8 LED_Seg7 LED_Seg6 LED_Seg5 LED_Seg4 LED_Seg3
LED_Seg2 LED_Seg1
WD_CLR
R32 10K R34 10K R36 10K R37 10K R39 10K R41 10K R42 10K R43 10K R45 10K
R48 10K
C7
0.1uFC80.1uFC90.1uF
C10
C11
C12
0.1uF
0.1uF
0.1uF
C14
0.1uF
Mot_Stop
U6A
1
CLK
2
W_CLR
3
ERR
WDT
WDO
13
U2
1
HU
2
LU
3
HV
4
LV
5
HW
6
LW
7
ERR
OU
OV
OW
MOT_DRV
U
8
V
9
W
10
R51
R60
R78
Watch Dog & Error
+12V +7V
J2
CON6
1 2 3 4 5 6
+5V +2.5V
-7V
+7V+5V
41
VR1A 10K
3
5
VR1B 10K
2
1
SW2SW_CW SW3SW_CCW
P
SW4SW_STO
R16 10K
U4A
12
74ACT14
C3 47uF
KHz
uSEC
411
U1A LM324
3
+
1
2
-
R2
2.2K
+7V+5V
411
U1B LM324
5
+
7
6
-
R1
2.2K
U4B
34
74ACT14
RESET
+5V
R53
R54
R55
10K
10K
10K
rpm
Velocity
R3 10K
R4 10K
R5 10K
R6 10K
R7 10K
R8 10K
R9 10K
R11 10K
R12 10K
R13 10K
R10 10K
FLMOD0
LED_Dig3
LED_Dig4
LED_WE
100
99
98
97
96
95
94
93
92
91
90
89
88
87
86
85
84
83
82
78
77
PDL1581PDL1480PDL1379PDL12
P51/DCK/TCUD11
P50/DDI/TIUD11/TO11
RESET47P43/TOP00/TIP00
CVDD
CVSS
43X244X145
46
48
R72 10K
C16
15pF
76
PDL11
PDL10
P35/TIUD10/TO10
P33/SOB1/TXDA1
P32/SIB1/RXDA1
P44/TOP01/TIP0149VDD
50
R73 10K
4MHz C17
15pF
U3
VSS
EVSS
EVDD
FLMD0
P13/TOQ0B2/TIQ00
P10/TOQ0T1/TIQ01/TOQ01
P12/TOQ0T2/TIQ03/TOQ03
P11/TOQ0B1/TIQ02/TOQ02
P21/TOQ1B1
EVDD38EVSS39P23/TOQ1B2
P41/SOB033P42/SCKB0
P20/TOQ1T1
P22/TOQ1T2
34
35
36
37
R66 10K
R67 10K
R68 10K
VDD
40
41
K
R69 10
R70 10K
P24/TOQ1T3
42
R71 10K
P52/DMS/TCLR11
P25/TOQ1B3
DDO
DRST
PLLSIN
P17/TOP21/TIP21
1 R20 10K R21 10K R22 10K R23 10K R24 10K R25 10K R26 10K
R30 10K R31 10K R33 10K R35 10K
R38 10K R40 10K
R82 10K
V_U V_V
V_W
LED_Seg1
1
A
LED_Seg2
2
B
LED_Seg3
3
C
LED_Seg4
4
D
LED_Seg5
5
E
LED_Seg6
6
F
LED_Seg7
7
G
LED_Seg8
8
DP
DG1 DG2 DG3 DG4 DG5 DG6 DG7
WE
LED_Dig1
10
LED_Dig2
11
LED_Dig3
12
LED_Dig4
13 14 15 16
LED_WE
18
ANI00
2
ANI01
3
ANI02
4
ANI03
5
P70/ANI20
6
P71/ANI21
7
P72/ANI22
8
P73/ANI23
9
AVDD
10
AVSS
11
CMPREF
12
AVSS
13
AVDD
14
P74/ANI24
15
P75/ANI25
16
P76/ANI26
17
P77/ANI27
18
ANI10
19
ANI11
20
ANI12
21
ANI13
22
P00/INTP0/TOQ0OFF
23
P01/INTP1/TOQ1OFF
24
P02/INTP2/TOP2OFF
25
P03/INTP3/TOP3OFF
uPD70F3186GC
P16/TOQ00/TIP20
P15/TOQ0B3/TRGQ0
VDD30VSS
P04/INTP4/ADTRG0
P05/INTP5/ADTRG1
P06/INTP628P07/INTP7
26
27
29
31
R63 10K
R64 10K
R65 10K
P14/TOQ0T3/EVTQ0
P40/SIB0
32
uSEC
7SEG_LEDx8
Application Note U17209EJ1V0AN
POWER
27
Speed Cont.
D1
RESET SW
SW1
21
P
7SEGLED1
+3.3V
41
SW2SW_CW SW3SW_CCW SW4SW_STO
VR1A 10K
3
R31 10K
C2 47uF
KHz
uSEC
uSEC
+7V+3.3V
411
U1A LM324
3
+
2
-
U3A
12
74AC14
RESET
+3.3V
R80
R81
10K
10K
1
R1
2.2K
34
R82
10K
rpm
7SEG_LEDx8
U3B
74AC14
DP
DG1 DG2 DG3 DG4 DG5 DG6 DG7
WE
CHAPTER 2 HARDWARE CONFIGURATION
Figure 2-6. Circuit Diagram of V850E/MA3
Velocity
1
100K
10K
100K
10K
100K
10K
+12V
R87
R111
R117
TP2 LC-2-G
1
6
5
+12V
6
5
R58
[W]
HPS-3-AS
CT1
IN-
IN+
R34
HPS-3-AS CT2
IN-
IN+
TP3 LC-2-G
1
10K
C7
0.1uF
C18
0.1uF
C21
0.1uF
+12V
+12V
OUT GND
OUT GND
NC
10K
NC
R110
R115 R116
[MOT OUT]
J1 1
2 3
100K
LM324
8
C4
R112
4.7K
100K
4.7K
4.7K
0.1uF
CN 3P
I_V
C5
I_U
V_U
V_V
V_W
C1
0.01uF film
+12V
1 2 3 4
VR2
1K
+12V
1 2 3 4
AGND
VR3
R59
1K
10K
R85 R86
10K
R91
10K 10K
10K 10K
22K
R33
2.2K
R35
R51
2.2K
U5A
312
7
+
6
-
U5B
312
5
+
4
-
+12V
U5C
312
9
+
8
-
R32
LM324
-
U1B
6
7
+
5
411
C3
0.1uF
R45
0.01uF film
22K
-
U1C
9
+
10
411
C6
+12V
0.1uF
R113
1M
1M
C22
0.1uF
+3.3V
R83
R89
1M
R79
1
LM339
R88
2
LM339
14
LM339
TP1 LC-2-G
[U] [V]
LED_WE
R4 10K
R5 10K
R6 10K
R7 10K
R8 10K
R9 10K
R3 10K
R2 10K
RESETB
140
141
142
143
U4
R36 10K R38 10K
LED_Dig4 LED_Dig3 LED_Dig2 LED_Dig1
LED_Seg8 LED_Seg7 LED_Seg6 LED_Seg5 LED_Seg4 LED_Seg3 LED_Seg2 LED_Seg1
Mot_WL Mot_VL Mot_WH
Mot_VH Mot_UH Mot_UL
SW_CW SW_CCW SW_Stop
LED_Seg1
1
A B
C D
E
F
G
LED_Seg2
2
LED_Seg3
3
LED_Seg4
4
LED_Seg5
5
LED_Seg6
6
LED_Seg7
7
LED_Seg8
8
LED_Dig1
10
LED_Dig2
11
LED_Dig3
12
LED_Dig4
13 14 15 16
LED_WE
18
R40 10K
R56 10K
R67 10K R68 10K R68 10K R68 10K R70 10K R72 10K R73 10K R75 10K R77 10K
1
AD14/PDL14
2
AD13/PDL13
3
AD12/PDL12
4
AD11/PDL11
5
AD10/PDL10
6
AD9/PDL9
7
AD8/PDL8
8
EVDD
9
EVSS
10
AD7/PDL7
11
AD6/PDL6
12
AD5/PDL5
13
AD4/PDL4
14
AD3/PDL3
15
AD2/PDL2
16
AD1/PDL1
17
AD0/PDL0
18
INTP001/TOP01/INTPP01/P01
19
INTP000/TOP00/EVTP0/TIP0/INTPP00/P00
20
INTP115/TOQB3/EVTQ/P15
21
INTP114/TOQB2/TIQ/P14
22
INTP013/TOQT3/INTPQ3/TOQ3/P13
23
VDD
24
VSS
25
INTP012/TOQT2/INTPQ2/TOQ2/P12
26
INTP011/TOQT1/INTPQ1/TOQ1/P11
27
INTP010/TOQB1/INTPQ0/TOQ0/P10
28
TDO/TC3/P27
29
TDI/INTP126/TC2/P26
30
INTP125/TC1/TIUD10/TO10/P25
31
INTP124/TC0/P24
32
TRST
33
INTP004/DMARQ0/TCLR10/INTP11/P04
34
INTP005/DMARQ1/TCUD10/INTP10/P05
35
TMS/INTP106/DMARQ2/P06
36
TCK/INTP107/DMARQ3/P07
uPD70F3134AGJ
144
PAL2/A2
PAL1/A1
PAL0/A0
PDL15/AD15
EVDD37EVSS38DMAAK3/PBD3
DMAAK2/PBD2
39
40
41
R94 10K
R93 10K
R92 10K
R10 10K
R11 10K
R12 10K
R13 10K
R14 10K
R15 10K
128
129
130
131
132
133
134
135
136
137
138
139
EVSS
EVDD
PAL9/A9
PAL8/A8
PAL7/A7
PAL6/A6
PAL5/A5
PAL4/A4
PAL3/A3
INTP134/RXD3/P34
INTP021/TOP10/EVTP1/TIP1/INTPP10/P21
INTP022/TOP11/INTPP11/P22
DMAAK1/PBD1
DMAAK0/PBD0
42
43
44
45
46
R96 10K
R97 10K
R92 10K
R92 10K
R95 10K
PAL13/A13
PAL12/A12
PAL11/A11
PAL10/A10
INTP132/ASCK2/SCK2/P32
INTP131/RXD2/SI2/P31
INTP130/TXD2/SO2/P30
INTP133/TXD3/P33
ASCK1/SCK1/P45
RXD1/SI1/P4451TXD1/SO1/P43
ASCK0/SCK0/P42
47
48
49
50
52
53
R98 10K
R99 10K
SW_Stop
V_V
V_U
V_W
5MHz
CLOCK 5MHz
R16 10K
R17 10K
125
126
127
PAL15/A15
PAL14/A14
RXD0/SI0/P4154TXD0/SO0/P40
55
56X257X158
SW_CW
SW_CCW
C19 33pF
124
VSS
CVDD
R18 10K
122
123
VDD
PAH0/A16
59
C20 33pF
R19 10K
PAH1/A17
CVSS
R20 10K
R22 10K
R23 10K
R24 10K
R21 10K
R25 10K
R26 10K
R27 10K
111
112
113
114
115
116
117
118
119
120
121
EVSS
EVDD
PAH9/A25
PAH8/A24
PAH7/A23
PAH6/A22
PAH5/A21
PAH4/A20
PAH3/A19
PAH2/A18
P50/INTP050/INTPP20/TOP20/EVTP2/TIP2
PSEL
CKSEL
VDD62VVSS63MODE064MODE165RESET66AVDD167ANO1/P8168ANO0/P80
60
61
R104 10K
R105 10K
PSEL
CKSEL
R107 10K
R106 10K
MODE
RESETB
69
R109 10K
R108 10K
R28 10K
R29 10K
R30 10K
109
110
PCD1/SDCLK
PCD0/SDCKE
PCD2/SDCAS
PCD3/SDRAS
PCS0/CS0 PCS1/CS1
PCS2/CS2/IOWR
PCS3/CS3 PCS4/CS4
PCS5/CS5/IORD
PCS6/CS6 PCS7/CS7
EVSS EVDD
PCT0/LBE/LWR/LDQM
PCT1/UBE/UWR/UDQM
PCT4/RD
PCT5/WR/WE
PCT6/ASTB
PCT7/BCYST
PCM0/WAIT
PCM1/BUSCLK
PCM2/HLDAK PCM3/HLDRQ PCM4/REFRQ
P51/INTP051/INTPP21/TOP21
AVSS170AVSS071AVDD0
P37/INTP137/ADTRG
72
P20/NMI
P70/ANI0 P71/ANI1 P72/ANI2 P73/ANI3 P74/ANI4 P75/ANI5 P76/ANI6 P77/ANI7
VSS VDD
+2.5V
+3.3V
C8
0.1uF
C12
0.1uF
C9
0.1uF
C13
0.1uF
R37 10K R39 10K R41 10K R42 10K R43 10K R44 10K R46 10K R47 10K R48 10K
R49 10K R50 10K R52 10K R53 10K R54 10K R55 10K R57 10K
R60 10K R61 10K R62 10K R63 10K R64 10K R65 10K R66 10K
R69 10K R71 10K
R74 10K R76 10K R78 10K
C10
0.1uF
C14
0.1uF
1
2
3
C11
0.1uF
C15
0.1uF
Mot_Stop
U6A
CLK
W_CLR
ERR
WDT
C16
0.1uF
108 107 106 105 104 103 102 101 100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73
WD_CLR
Watch Dog & Error
J2
1 2 3 4 5 6
CON6
Velocity
C17
0.1uF
WDO
+12V +7V
-7V
Mot_UH Mot_UL
Mot_V Mot_VL
Mot_WH Mot_WL
13
+3.3V +2.5V
H
U2
1
HU
2
LU
3
HV
4
LV
5
HW
6
LW
7
ERR
OU
OV
OW
MOT_DRV
U
8
V
9
W
10
R84
R90
R114
Application Note U17209EJ1V0AN
POWER
29

CHAPTER 3 SOFTWARE CONFIGURATION

3.1 Control Block

Figure 3-1 shows a diagram of the software control block of the reference system.
Figure 3-1. Diagram of Software Control Block of Reference System
Control by microcontroller
<6>
A/D
conver-
<7>
Current
monitor
sion
A/D
conver-
sion
iu
iv
u
<3> Speed control
v
PWM
conver-
sion
Driver
circuit
<1> Target speed
(volume)
+
<2>
Speed
<5>
w
u, v, w
detection
<1> The volume is loaded by the A/D converter as a target speed. <2> The speed to be calculated is determined by the difference from the present speed. <3> Values of phases U, V, and W are set. <4> The zero-cross point is detected by an induced voltage (by hardware). <5> The speed is calculated by the interval of zero-cross point in each phase. <6> An overcurrent is detected by the A/D converter. <7> The speed is controlled by a current value.
Motor
<4>
External
zero-cross
point
detection
Application Note U17209EJ1V0AN
31
CHAPTER 3 SOFTWARE CONFIGURATION

3.2 Peripheral I/O

The following types of peripheral I/O functions are used in this reference system.
Table 3-1. List of Peripheral I/O Functions
Function
Inverter timer Timer 00 (TM00) Timer 00 (TM00) Timer Q0 (TMQ0) Timer Q0 (TMQ0) Timer Q0 (TMQ0) 10 ms timer Timer 21 (TM21) Timer 21 (TM21) Timer P0 (TMP0) Timer P0 (TMP0) Timer D0 (TMD0) Motor control timer Timer 3 (TM3) Timer 3 (TM3) Timer P1 (TMP1) Timer P1 (TMP1) Timer D1 (TMD1) Speed measuring timer Timer 4 (TM4) Timer 4 (TM4) Timer P2 (TMP2) Timer P2 (TMP2)
U-phase current ANI00 ANI00 ANI00 ANI00 ANI0 V-phase current ANI10 ANI10 ANI10 ANI10 ANI1 Setting speed (volume) ANI01 ANI01 ANI01 ANI01 ANI4 U-phase zero-cross input INTP20 INTP20 INTP2 INTP2 INTP130 V-phase zero-cross input INTP 21 INTP21 INTP3 INTP3 INTP131 W-phase zero-cross input INTP22 INTP22 INTP4 INTP4 INTP132 CW key input P40 P40 P40 P40 P40 CCW key input P41 P41 P41 P41 P41 STOP key input P42 P42 P42 P42 P42 WDT reset output P43 P30 P30 P30 P43 LED output
Peripheral I/O
Function Name
(V850E/IA1)
PDL0 to PDL11, PDL15
Peripheral I/O
Function Name
(V850E/IA2)
PDL0 to PDL11, PDL15
Peripheral I/O
Function Name
(V850E/IA3)
PDL0 to PDL11, PDL15
Peripheral I/O
Function Name
(V850E/IA4)
PDL0 to PDL11, PDL15
Peripheral I/O
Function Name
(V850E/MA3)
Timer ENC10 (TMENC10)
PDL0 to PDL11, PDL15
32
Application Note U17209EJ1V0AN
CHAPTER 3 SOFTWARE CONFIGURATION
(1) Description of peripheral I/O functions
(a) Inverter timer
Inverter timers are used to output PWM waveforms. In this application circuit example, the settings are as shown below.
20 kHz symmetrical triangular waveform mode
Dead time: 6
µ
s
Inverter timer output: Low active
When ESO0, TOQ0OFF, or INTP000 pin input is at high level, PWM output is stopped.
(b) Motor control timer
Motor control timers are used to issue interrupts at a 50
(c) 10 ms timer
10 ms timers are used to issue interrupts at a 10 ms interval.
(d) Speed measuring timer
Used for measuring the revolution speed of the motor.
(e) Current value input
ANI00, ANI0 (V850E/MA3 only): U-phas e current value (5 to +5 A) ANI10, ANI1 (V850E/MA3 only): V-phase current value (5 to +5 A)
(f) Speed specification volume value input
ANI01 or ANI4 (V850E/MA3 only) is used to input a value from 0 to 1,023.
µ
s interval.
Application Note U17209EJ1V0AN
33
CHAPTER 3 SOFTWARE CONFIGURATION

3.3 Software Processing Structure

The software processing structure is shown below.
Figure 3-2. Main Processing Structure
CW
revolution
processing
CW
revolution operation
Operation
(STOP CW)
Processing
during
deceleration
Detection time
processing
STOP processing
Operation
(STOP CCW)
CCW
revolution
processing
CCW
revolution operation
34
Application Note U17209EJ1V0AN
CHAPTER 3 SOFTWARE CONFIGURATION
Figure 3-3. Interrupt Processing Structure
(a) Motor control processing (b) Control pin selection processing (c) Wait timer processing
U, V, W change
interrupt
50 s interval interrupt
µ
Motor control
processing
Control pin
selection
processing
Wait timer
processing
10 ms interval interrupt
The status of the operation mode switch is monitored by the main processing, and processing is transferred to CW,
CCW, and stop status. The motor is control led in the specified status by using a 50
µ
s interval interrupt.
There are the following three motor control statuses.
Stop status The motor is not controlled.
Initial operation status Estimated revolution control is performed up to the speed at which the zero-cross point of electromotive force can be detected.
Speed control status Feedback revolution control is performed so that the indication speed is attained.
Application Note U17209EJ1V0AN
35
CHAPTER 3 SOFTWARE CONFIGURATION

3.4 Flowchart

3.4.1 Main processing

Figure 3-4 shows the flowchart of the main processing.
36
Application Note U17209EJ1V0AN
CHAPTER 3 SOFTWARE CONFIGURATION
Figure 3-4. Main Processing
START
: Refer to 4.1.5, 4.2.5, 4.3.5, 4.4.5, 4.5.5 Main processing function.
(hardware initialization)
C
(used area initialization)
hinit
ainit
Enable interrupts
SW CW pressed?
Yes
SW mode = CW
: Refer to Figure 3-20 Hardware Initialization.
: Refer to Figure 3-21 Common Area Initialization.
No
SW CCW pressed?
Yes
SW mode = CCW
No
SW STOP pressed?
Yes
SW mode = STOP
No
Case?
(case 0 to case 7)
0
1
2
3
4
5
6
Application Note U17209EJ1V0AN
37
CHAPTER 3 SOFTWARE CONFIGURATION
Figure 3-5. Case 0 (Processing During Stoppage)
0
SW mode = CW?
Yes
Disable interrupts
Initialize target speed and request
CCW initialization
Enable interrupts Enable interrupts
Processing number 1
No
Disable interrupts
Initialize target speed and request
CCW initialization
Processing number 4
A
38
Application Note U17209EJ1V0AN
CHAPTER 3 SOFTWARE CONFIGURATION
Figure 3-6. Case 1 (CW Acceleration Processing)
1
No
Re-set acceleration/deceleration counter
Target speed < Indication speed?
Set speed monitor start timer to 5 seconds
Initialization of
acceleration/deceleration
counter 0 ends?
Yes
Yes
Increase target speed
No
Target speed > Indication speed?
Yes
Decrease target speed
Set speed monitor start timer to 5 seconds
No
Processing number 2
SW mode = CCW or STOP?
Yes
Processing number 3
No
A
Application Note U17209EJ1V0AN
39
CHAPTER 3 SOFTWARE CONFIGURATION
Figure 3-7. Case 2 (CW Constant-Speed Processing)
Indication speed as target speed
SW mode = CCW or STOP?
Processing number 3
2
No
Yes
A
Figure 3-8. Case 3 (CW Stop Processing)
3
No
Acceleration/deceleration c ou n ter = 0?
Yes
Re-set acceleration/deceleration counter
Target speed > Indication speed?
Yes
Decrease target speed
Set speed monitor start time to 5 seconds
No
Set stop flag to on and processing
number to 0
A
40
Application Note U17209EJ1V0AN
CHAPTER 3 SOFTWARE CONFIGURATION
Figure 3-9. Case 4 (CCW Acceleration Processing)
4
No
Set speed monitor start time to 5 seconds
Initial operation ends with
acceleration/deceleration cou nte r = 0?
Yes
Re-set acceleration/deceleration counter
Target speed < Indication speed?
Yes
Increase target speed
SW mode = CCW or STOP?
Yes
No
Target speed > Indication speed?
Yes
Decrease target speed
Set speed monitor start time to 5 seconds
No
No
Processing number 5
Processing number 6
A
Application Note U17209EJ1V0AN
41
CHAPTER 3 SOFTWARE CONFIGURATION
Figure 3-10. Case 5 (CCW Constant-Speed Processing)
5
Target speed = (– indication speed)
SW mode = CW or STOP?
Yes
Processing number 6
No
A
Figure 3-11. Case 6 (CCW Stop Processing)
No
Acceleration/deceleration counter = 0?
Re-set acceleration/deceleration counter
6
Yes
42
Target speed < ( indication speed)?
Yes
Increase target speed
Set speed monitor start t ime to 5 se co nds
A
Application Note U17209EJ1V0AN
No
Set stop flag to on and processing
number to 0
CHAPTER 3 SOFTWARE CONFIGURATION
Figure 3-12. Detect Wait (1/2)
A
No
No
No
Processing number 2 or 5?
Yes
Speed monitor starts?
Yes
Present speed < Error speed?
Yes
Set error number ERR_NO3
Stop flag on
PWM output off
B
Application Note U17209EJ1V0AN
43
CHAPTER 3 SOFTWARE CONFIGURATION
Figure 3-12. Detect Wait (2/2)
B
No
Display average counter = 0?
Yes
Set display average counter to 100
led_num
(Present average speed
indication)
led_num
(Control period indication)
led_num
(Interrupt processing
time indication)
led_num
(Operation processing
time indication)
44
No
Error flag on?
Yes
7-segment display off
500 ms?
Yes
Error number 1?
Yes
“1” displayed on 7-segment
500 ms?
Yes
Application Note U17209EJ1V0AN
No
C
No
No
“2” displayed on 7-segment

3.4.2 Motor control processing

Figure 3-13. Control Interrupt Processing (1/5)
CHAPTER 3 SOFTWARE CONFIGURATION
Motor_CONT
fcalcu
(speed calculation)
Convert radian to rpm value
No
Calculate total speed value from present
Speed counter = 0?
Yes
Re-set speed counter
value of speed counter
: Refer to 4.1.7, 4.2.7, 4.3.7, 4.4.7, 4.5.7 Motor control
interrupt processing function.
Clear total speed value
1
Application Note U17209EJ1V0AN
45
CHAPTER 3 SOFTWARE CONFIGURATION
Figure 3-13. Control Interrupt Processing (2/5)
1
Stop flag on?
Yes
All phases of PWM port off
5
No
3
No
Operation start output
Get display timer start value
Clear PWM output prohibition
Reset watchdog timer
Initial flag on?
Initial revolution processing
Yes
Increment initial counter
46
No
5
Initial counter > Output time?
Yes
Clear initial counter
CW?
Yes
Extract output value from initial CW revolution pattern table
Count up pattern extraction
Same output pattern continues to be output the number of times specified by the table.
No
Extract output value from initial CCW revolution pattern table
Count up pattern extraction
2
Application Note U17209EJ1V0AN
U phase high side output on?
U phase comparison value = 0
V and W phase comparison
values = Initial value
High side is valid by clearing the value to 0.
Write PWM output pattern
CHAPTER 3 SOFTWARE CONFIGURATION
Figure 3-13. Control Interrupt Processing (3/5)
2
No
Yes
V phase high side output on?
Yes
V phase comparison value = 0
U and W phase comparison
values = Initial value
No
W phase comparison value = 0
U and V phase comparison
values = Initial value
Pattern extraction counter 6?
Yes
Clear pattern extraction counter
init_upco > 14?
Yes
Initial flag off
No
No
To select and output six types of output patterns
End if value of number of revolutions table counter is 14 or more
Increment init_upco by 1
3
Application Note U17209EJ1V0AN
47
CHAPTER 3 SOFTWARE CONFIGURATION
Figure 3-13. Control Interrupt Processing (4/5)
3
Speed difference = Target speed – Present speed
Calculate PWM output value
Speed integral value > MAX. value?
Yes
Speed integral value = MAX. value
PWM value < 0?
Yes
PWM value as 1
Normal revolution processing
No
Speed integral value < MAX. value?
Yes
Speed integral value = MAX. value
No
PWM value > MAX.?
Yes
No
Speed integral value
calculation
No
PWM value as MAX.
4
Remarks 1. PWM = (Present speed × ksp) + (Speed difference × ksp/10) + Speed integral value + Speed
offset value
2. Speed integral value = Speed integral value + (Speed difference × ksi)
3. ksp: Speed proportion gain ksi: Speed integral gain
48
Application Note U17209EJ1V0AN
CHAPTER 3 SOFTWARE CONFIGURATION
Figure 3-13. Control Interrupt Processing (5/5)
Read present PWM output pattern
4
U phase high side output on?
Yes
U phase comparison value = 0
Set V and W phase comparison values
EXIT
No
U phase high side output on?
V phase comparison value = 0
Set U and W phase comparison
values
No
Yes
W phase comparison value = 0 Set U and V phase comparison
values
Application Note U17209EJ1V0AN
49
CHAPTER 3 SOFTWARE CONFIGURATION

3.4.3 U zero-cross point interrupt processing

Figure 3-14. U Zero-Cross Point Interrupt Processing
int_p20
No
Initial flag off and stop flag off?
Yes
Capture speed measuring timer value and restart
Set reference position from other phase status
Target revolution CCW?
Yes
Extract output pattern from CCW table according
to present zero-cross point status
U phase high side output on?
Yes
U phase comparison value = 0 Set V and W phase comparison values
: Refer to 4.1.8, 4.2.8, 4.3.8, 4.4.8, 4.5.8 Zero-cross interrupt processing function.
No
Extract output pattern from CW table according
to present zero-cross point status
No
V phase high side output on?
Yes
V phase comparison value = 0 Set U and W phase comparison values
No
W phase comparison value = 0 Set U and V phase comparison values
50
Write PWM output pattern
Speed calculation count up
EXIT
Application Note U17209EJ1V0AN
CHAPTER 3 SOFTWARE CONFIGURATION

3.4.4 V zero-cross point interrupt processing

Figure 3-15. V Zero-Cross Point Interrupt Processing
int_p21
No
Initial flag off and stop flag off?
Yes
Capture speed measuring timer value and restart
Set reference position from other phase status
Target revolution CCW?
Yes
Extract output pattern from CCW table according
to present zero-cross point status
U phase high side output on?
Yes
U phase comparison value = 0 Set V and W phase comparison values
: Refer to 4.1.8, 4.2.8, 4.3.8, 4.4.8, 4.5.8 Zero-cross interrupt processing function.
No
Extract output pattern from CW table according
to present zero-cross point status
No
V phase high side output on?
Yes
V phase comparison value = 0 Set U and W phase comparison values
No
W phase comparison value = 0 Set U and V phase comparison values
Write PWM output pattern
Speed calculation count up
EXIT
Application Note U17209EJ1V0AN
51
CHAPTER 3 SOFTWARE CONFIGURATION

3.4.5 W zero-cross point interrupt processing

Figure 3-16. W Zero-Cross Point Interrupt Processing
int_p22
: Refer to 4.1.8, 4.2.8, 4.3.8, 4.4.8, 4.5.8 Zero-cross interrupt processing function.
No
Initial flag off and stop flag off?
Yes
Capture speed measuring timer value and restart
Set reference position from other phase status
Target revolution CCW?
Yes
Extract output pattern from CCW table
according to present zero-cross point status
U phase high side output on?
Yes
U phase comparison value = 0
Set V and W phase comparison values
No
Extract output pattern from CW table according
to present zero-cross point status
No
V phase high side output on?
Yes
V phase comparison value = 0
Set U and W phase comparison
values
No
W phase comparison value = 0
Set U and V phase comparison
values
52
Write PWM output pattern
Speed calculation count up
EXIT
Application Note U17209EJ1V0AN
CHAPTER 3 SOFTWARE CONFIGURATION

3.4.6 10 mSEC interval interrupt processing

Figure 3-17. 10 mSEC Interval Interrupt Processing
Acceleration/deceleration counter = 0?
int_ETC
Wait counter = 0?
Yes
Yes
Display counter = 0?
Yes
: Refer to 4.1.9, 4.2.9, 4.3.9, 4.4.9, 4.5.9
10 mSEC interval interrupt processing function.
No
Wait counter – 1
No
Acceleration/deceleration counter – 1
No
Display counter – 1
EXIT
Application Note U17209EJ1V0AN
53
CHAPTER 3 SOFTWARE CONFIGURATION

3.4.7 A/D converter channel 0 interrupt processing

Figure 3-18. A/D Converter Channel 0 Interrupt Processing
Read U phase current value
| Current value | > MAX_I?
U, V, W phase output off
Read V phase current value
I Current value I > MAX_I?
int_ad0
Yes
Set error flag
Yes
: Refer to 4.1.10, 4.2.10, 4.3.10, 4.4.10, 4.5.10 A/D converter interrupt
processing function.
No
No
U, V, W phase output off
Set error flag
EXIT
54
Application Note U17209EJ1V0AN
CHAPTER 3 SOFTWARE CONFIGURATION

3.4.8 A/D converter channel 1 interrupt processing

Figure 3-19. A/D Converter Channel 1 Interrupt Processing
int_ad1
Read volume value
EXIT
: Refer to 4.1.10, 4.2.10, 4.3.10, 4.4.10 A/D converter
interrupt processing function.
Application Note U17209EJ1V0AN
55

3.4.9 Hardware initialization

CHAPTER 3 SOFTWARE CONFIGURATION
Figure 3-20. Hardware Initialization
Initialization of port used
7-segment LED extinguished
Motor control timer setting
Speed measuring timer setting
Initialization of inverter timer
hinit
10 ms timer setting
All phases active
: Refer to 4.1.11, 4.2.11, 4.3.11, 4.4.11, 4.5.11 Hardware
initialization processing function.
56
A/D initialization
Interrupt settings of
INTP20 to INTP22
(V850E/IA1, V850E/IA2),
INTP2 to INTP4
(V850E/IA3, V850E/IA4), or
INTP130 to INTP132 (V850E/MA3)
EXIT
Application Note U17209EJ1V0AN

3.4.10 Common area initialization

CHAPTER 3 SOFTWARE CONFIGURATION
Figure 3-21. Common Area Initialization
ainit
Error flag off
Initial flag off
Clear display counter
Stop flag on
Target speed = 0
Speed integral value = 0
EXIT

3.4.11 Revolution start initialization

Figure 3-22. Revolution Start Initialization
start_init
: Refer to 4.1.12, 4.2.12, 4.3.12, 4.4.12, 4.5.12 Common area
initialization processing function.
: Refer to 4.1.13, 4.2.13, 4.3.13, 4.4.13, 4.5.13
Revolution start initialization processing function.
Clear average speed buffer
Initialize average speed calculation area
Output initial revolution pattern
Initialize processing area
EXIT
Application Note U17209EJ1V0AN
57

3.4.12 LED display

led_num
CHAPTER 3 SOFTWARE CONFIGURATION
Figure 3-23. LED Display
: Refer to 4.1.6, 4.2.6, 4.3.6, 4.4.6, 4.5.6 LED display function.
Area 1?
Yes
Display 4 digits of area 1
EXIT
No
Revolution speed
Area 2?
Yes
Display 2 digits of area 2
Control P processing time
No
Control period
Area 3?
Display 2 digits of area 3
Operation processing time
No
Yes
Display 2 digits of area 4.
58
Application Note U17209EJ1V0AN
CHAPTER 3 SOFTWARE CONFIGURATION

3.5 Common Areas

The following table shows the major common areas used by the reference system.
Table 3-2. Common Area List
Symbol Type Usage Set Value
error_flag unsigned char Error flag
init_flag unsigned char Indicates initial revolution
cont_time unsigned short Interrupt processing time 1 µs units cont_time1 unsigned short Operation time 1 disp_co unsigned short Average speed counter for display volume unsigned short Speed volume value timer_count unsigned short Time wait counter 10 ms units accel_count unsigned short
stop_flag unsigned short Stop flag
before_posi[21][2] signed short Position buffer total_sa signed short Position total difference sum_speed unsigned int
speed_co unsigned int Counter for average speed calculation 0, 1, … now_speed signed int Present speed rpm object_speed signed int Target speed rpm d_speed signed int Display speed rpm iua signed short U-phase current iva signed short V-phase current o_iqai signed int Speed integral value base_position signed int Speed estimation reference point sa_time unsigned int For speed measurement timer_count unsigned short Time wait counter init_co unsigned short
init_pat unsigned char Initial revolution output pattern number 0 to 5 init_upco unsigned short Initial revolution output table number 0 to 10 int_co unsigned int U, V, W interrupt counter 0, 1, … pwm_value signed int PWM output value Output bit pattern
Acceleration/deceleration operation time counter
Total value area for average speed calculation
Output selection monitor counter during initial revolution
0: No error ERR_NO1: Overcurrent ERR_NO3: Speed difference error
ON: Initial revolution in progress OFF: Stop or normal revolution in progress
µ
s units
10 ms units
ON: Stopped OFF: Revolving
0, 1, …
0, 1, …
Application Note U17209EJ1V0AN
59
CHAPTER 3 SOFTWARE CONFIGURATION

3.6 Tables

(1) LED output pattern
Contains display pattern data 0 to 9.
unsigned short led_pat[10] = { 0xfc. 0x60, ~ };
(2) Initial CW output pattern
Contains an output pattern for CW initial operation.
unsigned short cw_data[6][2] = { { 0x09, 0x00 }, { 0x21, 0x00 }, };
Note The underlined values differ depending on the target microcontroller.
Figure 3-24. Bit Assignment
Note
WL WU VL VU UL UU
(3) Initial CCW output pattern
Contains an output pattern for CCW initial operation.
unsigned short ccw_data[6][2] = { { 0x18, 0x00 }, { 0x12, 0x00 }, };
Note The underlined values differ depending on the target microcontroller.
(4) Initial revolution pattern output time
The initial pattern is output with the revolution speed increased each time the interrupt of this table occurs.
unsigned short up_data[ ] = { 255, 242, ~ };
Note
60
Application Note U17209EJ1V0AN
CHAPTER 3 SOFTWARE CONFIGURATION
(5) Normal CW revolution output pattern
Contains an output pattern in accordance with the status of the zero-cross point during normal CW revolution.
unsigned short run_cw_data[8][2] = { { 0x00, 0x00 }, { 0x21, 0x00 }, };
Note The underlined values differ depending on the target microcontroller.
(6) Normal CCW revolution output pattern
Contains an output pattern in accordance with the status of the zero-cross point dur i ng normal CCW revolution.
unsigned short run_ccw_data[8][2] = { { 0x00, 0x00 }, { 0x09, 0x00 }, };
Note
The underlined values differ depending on the target microcontroller.
Note
Note
Application Note U17209EJ1V0AN
61
CHAPTER 3 SOFTWARE CONFIGURATION

3.7 Constant Definitions

The following table shows the major constants used by the reference system.
Symbol Usage Value PAI TH_U Radian value, jack-up constant 1000 RAD Radian value of one revolution 2 × PAI × TH_U OFFSET Original point OFFSET 1945 RPM_RADS rpm → radian conversion constant 2 × PAI × TH_U/60 KSP Speed proportion constant 917 KSI Speed integral constant 0 P Number of motor poles 2 KSPGETA Speed proportion constant jack-up constant 10 KSIGETA Speed integral constant jack-up constant 14 SGETA sin jack-up constant 14 PWM_TS PWM cycle 50 PWM_DATA PWM set value PWM_TS/0.05 SPEED_MAX Maximum speed 500 (3000 rpm) SPEED_MINI Minimum speed 100 (600 rpm) SPEED_INIT Initial revolution speed 700 rpm SA_SPEED_MAX Maximum speed difference 800 IQMAX Maximum speed integral value 200000 MAX_I Maximum current value 800 TS Motor control period 800 ACCEL_TIME Acceleration/deceleration time constant, 10 ms 1 ACCEL_DATA Number of acceleration/deceleration incremental revolutions 40 rpm WATCH_START Speed monitor start time, 10 ms 500 ACCEL_VAL_1ST Initial acceleration/deceleration time constant 50 ACCEL_VAL Acceleration/deceleration time constant 3 ACCEL_SPD Acceleration/deceleration constant 50 PWM_INIT PWM initial value PWM_DATA/4
π
3.141592
µ
s
µ
s
62
Application Note U17209EJ1V0AN

CHAPTER 4 PROGRAM LIST

4.1 Program List (V850E/IA1)

4.1.1 Symbol definition

/****************************************************************************** /
/* Common area */
/****************************************************************************** /
unsigned char ram_start ;
unsigned char error_flag ; /* Error flag */
unsigned char init_flag ; /* Initial flag */
unsigned short cont_time ; /* Interrupt control time uSEC */
unsigned short cont_time1 ; /* Vector operation time uSEC */
unsigned short disp_co ; /* Interrupt control time display timer */
unsigned short volume ; /* Volume value */
unsigned short timer_count ; /* Time wait counter */
unsigned short accel_count ; /* Acceleration/deceleration operation time */
/* counter */
unsigned char stop_flag ; /* Stop flag */
signed short before_posi[21][2] ; /* Position buffer */
signed short total_sa ; /* Position total difference */
signed int sum_speed ;
signed int speed_co ;
signed int now_speed ; /* Present speed rms */
signed int object_speed ; /* Target speed rms */
unsigned int d_speed ; /* Display speed rms */
unsigned char ram_end ;
#pragma section const begin
const unsigned short led_pat[10] = { 0xfc, 0x60, 0xda, 0xf2, 0x66, 0xb6, 0xbe, 0xe0,
0xfe, 0xe6 } ;
#pragma section const end
/****************************************************************************** /
/* Common flags */
/****************************************************************************** /
extern unsigned char ram_start ;
extern unsigned char error_flag ; /* Error flag */
extern unsigned char init_flag ; /* Initial flag */
extern unsigned short cont_time ; /* Interrupt control time uSEC */
extern unsigned short cont_time1 ; /* Vector operation time uSEC */
extern unsigned short disp_co ; /* Interrupt control time display timer */
extern unsigned short volume ; /* Volume value */
extern unsigned short timer_count ; /* Time wait counter */
extern unsigned short accel_count ; /* Acceleration/deceleration operation */
/* time counter */
extern unsigned char stop_flag ; /* Stop flag */
Application Note U17209EJ1V0AN
63
CHAPTER 4 PROGRAM LIST
extern signed short before_posi[21][2] ; /* Position buffer */ extern signed short total_sa ; /* Position total difference */ extern signed int sum_speed ; extern signed int speed_co ; extern signed int now_speed ; /* Present speed rms */ extern signed int object_speed ; /* Target speed rms */ extern unsigned int d_speed ; /* Display speed rms */ extern unsigned char ram_end ;
#pragma section const begin extern const unsigned short led_pat[] ;; #pragma section const end /****************************************************************************** / /* Motor common definition */ /****************************************************************************** / extern signed short iua ; /* U-phase current */ extern signed short iva ; /* V-phase current */ extern signed int o_iqai ; /* Speed integral value area */ extern signed int base_position ; /* Speed estimation value reference point */ extern unsigned int sa_time ; /* Speed measurement value */ extern unsigned short timer_count ; /* Time wait counter */ extern unsigned short accel_count ; /* Acceleration/deceleration operation */ /* time counter */
extern unsigned short init_co ; /* Initial interrupt counter */ extern unsigned char init_pat ; /* Initial pattern counter */ extern unsigned short init_upco ; /* Initial speed-up counter */ extern unsigned int int_co ; /* UVW interrupt counter */ extern signed int pwm_value ; /* PWM output value */
#pragma section const begin extern const unsigned char cw_data[][2] ; extern const unsigned char ccw_data[][2] ; extern const unsigned char up_data[] ; extern const unsigned char run_cw_data[][2] ; extern const unsigned char run_ccw_data[][2] ; #pragma section const end

4.1.2 Constant definition

/****************************************************************************** / /* I/O */ /****************************************************************************** / #define BASE_IO 0xc200000 #define LED11 3 #define LED12 2 #define LED13 1 #define LED14 0
64
Application Note U17209EJ1V0AN
CHAPTER 4 PROGRAM LIST
#define LED21 5
#define LED22 4
#define LED31 7
#define LED32 6
#define LED41 9
#define LED42 8
#define DIPSW 0x10
#define SW 0x20
#define DA1 0x30
#define DA2 0x40
#define DA3 0x50
#define WRESET 0x60
#define MODE 0x70
/****************************************************************************** /
/* Constant */
/****************************************************************************** /
#define ON 1
#define OFF 0
#define CW 1 /* CW operation mode */
#define CCW 2 /* CCW operation mode */
#define STOP 0 /* Operation stop mode */
#define ERR_NO1 1 /* Overcurrent error */
#define ERR_NO2 2 /* Speed difference error */
/****************************************************************************** /
/* Motor constant */
/****************************************************************************** /
/* Motor constant */
#define PAI 3.14159265 /* π */
#define TH_U 1000 /* Radian value jack-up constant */
#define RAD (int)(2*PAI*TH_U) /* Radian value of one revolution */
#define OFFSET 1945 /* Original point OFFSET */
#define RPM_RADS (int)((2*PAI*TH_U)/60) /* rpm -> radian conversion constant */
/* Motor constant */
#define KSP 750 /* Speed proportion constant */
#define KSI 10 /* Speed integral constant */
#define P 2 /* Number of poles */
#define KSPGETA 10 /* KP jack-up constant */
#define KSIGETA 14 /* KSI jack-up constant */
#define SGETA 14 /* sin jack-up constant */
#define PWM_TS 50 /* PWM cycle */
#define PWM_DATA (PWM_TS/0.05) /* PWM set value */
#define SPEED_MAX 3000 /* Maximum speed 3000 rpm */
#define SPEED_MINI 800 /* Minimum speed 800 rpm */
#define SPEED_INIT 700 /* Initial revolution speed rpm */
#define SA_SPEED_MAX 800 /* Maximum speed difference rpm */
Application Note U17209EJ1V0AN
65
CHAPTER 4 PROGRAM LIST
#define IQAMAX 200000 /* Maximum speed integral value */ #define MAX_I 800 /* Maximum current value */ #define TS 200 /* Motor control time interval uSEC */ #define ACCEL_TIME 1 /* Acceleration/deceleration time */ /* constant 10 mSEC */ #define ACCEL_DATA 40 /* Number of acceleration/deceleration */
/* incremental revolutions rpm */ #define WATCH_START 500 /* Speed monitor start time 10 mSEC */ #define ACCEL_VAL_1ST 50 /* Initial acceleration/deceleration */ /* time constant */ #define ACCEL_VAL 3 /* Acceleration/deceleration time */ /* constant */ #define ACCEL_SPD 50 /* Acceleration/deceleration constant */
#define PWM_INIT PWM_DATA/4 /* PWM initial value */ /****************************************************************************** / /* Function constant */ /****************************************************************************** / void fcalcu( signed int *wrm, signed int *trm ); void OUT_data( unsigned short reg, unsigned short data ); unsigned short IN_data( int reg ); void led_num( int no, long data ) ; /****************************************************************************** / /* Motor-related common area */ /****************************************************************************** / signed short iua ; /* U-phase current */ signed short iva ; /* V-phase current */ signed int o_iqai ; /* Speed integral value area */ signed int base_position ; /* Speed estimation value reference point */ unsigned int sa_time ; /* Speed measurement value */ unsigned int before_time ; /* Previous speed measuring timer value */ unsigned short accel_count ; /* Acceleration/deceleration operation time counter */
unsigned short init_co ; /* Initial interrupt counter */ unsigned char init_pat ; /* Initial pattern counter */ unsigned short init_upco ; /* Initial speed-up counter */ unsigned int int_co ; /* UVW interrupt counter */ signed int di ; signed int pwm_value ; /* PWM output value */
#pragma section const begin const unsigned char cw_data[6][2] = { {0x09,0x00},{0x21,0x00},{0x24,0x00}, {0x06,0x00},{0x12,0x00},{0x18,0x00} }; const unsigned char ccw_data[6][2] = { {0x18,0x00},{0x12,0x00},{0x06,0x00}, {0x24,0x00},{0x21,0x00},{0x09,0x00} }; const unsigned char up_data[] = { 255, 242, 229, 217, 206, 195, 185, 176, 166, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158 } ; const unsigned char run_cw_data[8][2] = { {0x00,0x00},{0x21,0x00},{0x06,0x00},
66
Application Note U17209EJ1V0AN
CHAPTER 4 PROGRAM LIST
{0x24,0x00},{0x18,0x00},{0x09,0x00}, {0x12,0x00},{0x00,0x00} }; const unsigned char run_ccw_data[8][2] = { {0x00,0x00},{0x09,0x00},{0x24,0x00}, {0x21,0x00}, {0x12,0x00},{0x18,0x00}, {0x06,0x00},{0x00,0x00} }; #pragma section const end

4.1.3 Interrupt handler setting

/****************************************************************************** / /* Interrupt symbol table */ /****************************************************************************** / .extern _ _start .extern _int_MOTOR .extern _int_U .extern _int_V .extern _int_W .extern _int_AD0 .extern _int_AD1 .extern _int_ETC
.globl V_RESET .globl V_U .globl V_V .globl V_W .globl V_ETC .globl V_MOTOR .globl V_AD0 .globl V_AD1 #******************************************************************************* .section ".handler",text V_RESET: jr _start V_U: ld.w [sp],r1 add 4,sp jr _int_U -- INTP20 V_V: ld.w [sp],r1 add 4,sp jr _int_V -- INTP21 V_W: ld.w [sp],r1 add 4,sp jr _int_W -- INTP22 V_ETC: ld.w [sp],r1 add 4,sp
Application Note U17209EJ1V0AN
67
CHAPTER 4 PROGRAM LIST
jr _int_ETC -- Other timers V_MOTOR: ld.w [sp],r1 add 4,sp jr _int_MOTOR -- Speed control timer V_AD0: ld.w [sp],r1 add 4,sp jr _int_AD0 -- A/D converter CH0 V_AD1: ld.w [sp],r1 add 4,sp jr _int_AD1 -- A/D converter CH1
.extern V_RESET .extern V_U .extern V_V .extern V_W .extern V_ETC .extern V_MOTOR .extern V_AD0 .extern V_AD1 /****************************************************************************** / /* Interrupt jump table */ /****************************************************************************** / .section ".vect_RESET",text mov #V_RESET,r1 jmp [r1]
.section ".id_NO",text .byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
.section ".vect_U",text add -4,sp st.w r1,[r3] mov #V_U,r1 jmp [r1]
.section ".vect_V",text add -4,sp st.w r1,[r3] mov #V_V,r1 jmp [r1]
.section ".vect_W",text add -4,sp st.w r1,[r3] mov #V_W,r1
68
Application Note U17209EJ1V0AN
CHAPTER 4 PROGRAM LIST
jmp [r1]
.section ".vect_ETC",text add -4,sp st.w r1,[r3] mov #V_ETC,r1 jmp [r1]
.section ".vect_MOTOR",text add -4,sp st.w r1,[r3] mov #V_MOTOR,r1 jmp [r1]
.section ".vect_AD0",text add -4,sp st.w r1,[r3] mov #V_AD0,r1 jmp [r1]
.section ".vect_AD1",text add -4,sp st.w r1,[r3] mov #V_AD1,r1 jmp [r1]

4.1.4 Startup routine setting

#============================================================================= # DESCRIPTIONS: # This assembly program is a sample of start-up module for ca850. # If you modified this program, you must assemble this file, and # locate a given directory. # # Unless -G is specified, sections are located as the following. # # | : | # | : | # tp -> -+-------------- + _ _start _ _tp_TEXT # | start up | # |-------------- | # text section | | # | user program | # | | # |-------------- | # | library | # -+-------------- + # | |
Application Note U17209EJ1V0AN
69
CHAPTER 4 PROGRAM LIST
# sdata section | | # | | # gp -> -+-------------- + _ _ssbss # | | # sbss section | | # | | # +-------------- + _ _stack _ _esbss _ _sbss # | stack area | # bss section | | # | 0x400 bytes | # sp -> -+-------------- + _ _stack + STACKSIZE _ _ebss # | : | # | : | # | : | # ep -> -+-------------- + _ _ep_DATA # tidata section | | # -+-------------- + # sidata section | | # -+-------------- + # | : | # | : | # #============================================================================= #----------------------------------------------------------------------------­# special symbols #----------------------------------------------------------------------------­ .extern _ _tp_TEXT, 4 .extern _ _gp_DATA, 4 .extern _ _ep_DATA, 4 .extern _ _ssbss, 4 .extern _ _esbss, 4 .extern _ _sbss, 4 .extern _ _ebss, 4
#----------------------------------------------------------------------------­# C program main function #----------------------------------------------------------------------------­ .extern _main
#----------------------------------------------------------------------------­# dummy data declaration for creating sbss section #----------------------------------------------------------------------------­ .sbss .lcomm _ _sbss_dummy, 0, 0
70
Application Note U17209EJ1V0AN
CHAPTER 4 PROGRAM LIST
#----------------------------------------------------------------------------­# system stack #----------------------------------------------------------------------------­ .set STACKSIZE, 0x400 .bss .lcomm _ _stack, STACKSIZE, 4
#----------------------------------------------------------------------------­# start up # pointers: tp - text pointer # gp - global pointer # sp - stack pointer # ep - element pointer # exit status is set to r10 #----------------------------------------------------------------------------­ .text .align 4 .globl _ _start .globl _exit .globl _ _exit _ _start: mov 0x12,r10 st.b r10,VSWC[r0] -- Set peripheral I/O wait
mov 0x07,r10 -- ×10 st.b r0,PHCMD[r0] st.b r10,CKC[r0] -- PLL xx multiplication nop nop nop nop nop
mov #_ _tp_TEXT, tp -- set tp register mov #_ _gp_DATA, gp -- set gp register offset add tp, gp -- set gp register mov #_ _stack+STACKSIZE, sp -- set sp register mov #_ _ep_DATA, ep -- set ep register # mov #_ _ssbss, r13 -- clear sbss section mov #_ _esbss, r12 cmp r12, r13 jnl .L11 .L12: st.w r0, [r13] add 4, r13 cmp r12, r13 jl .L12
Application Note U17209EJ1V0AN
71
CHAPTER 4 PROGRAM LIST
.L11: # mov #_ _sbss, r13 -- clear bss section mov #_ _ebss, r12 cmp r12, r13 jnl .L14 .L15: st.w r0, [r13] add 4, r13 cmp r12, r13 jl .L15 .L14: # jarl _main, lp -- call main function _ _exit: halt -- end of program _ _startend: nop # # #-------------------------- end of start up module ----------------------------# # #

4.1.5 Main processing function

#include "Common.h" #include "Motor.h" #pragma ioreg /* Peripheral I/O register definition */
static int save_psw; /****************************************************************************** / /* 3-phase motor control program */ /****************************************************************************** / void main() { unsigned char proc_no ; /* Present processing number */ signed int speed ; /* Indication speed rms */ signed int accel_spd ; int sw, sw_mode ; /* */ hinit() ; /* Hardware initialization */ ainit() ; /* Initialization of area used */ proc_no = 0 ; _ _EI(); while( 1 ) { accel_spd = ( SPEED_MAX - SPEED_MINI ) / 100; speed = ( ( SPEED_MAX - SPEED_MINI ) * volume / 1024 ) + SPEED_MINI ; /* Indication speed calculation by volume */ sw = ~IN_data( SW ) & 0x07 ; /* Read operation button */
72
Application Note U17209EJ1V0AN
CHAPTER 4 PROGRAM LIST
if ( sw == 1 ) { sw_mode = CW ; } else if ( sw == 2 ) { sw_mode = CCW ; } else if ( sw == 4 ) { sw_mode = STOP ; } switch( proc_no ) { /* STOP processing */ case 0 : if ( sw_mode == CW ) { _ _DI() ; object_speed = SPEED_MINI ; /* Set target speed to minimum value */ stop_flag = OFF ; timer_count = WATCH_START ; /* Set speed monitor start time to 5 SEC */ accel_count = ACCEL_VAL_1ST ; /* Set acceleration/deceleration counter */ init_flag = 2 ; /* CCW initial request */ start_init() ; /* Initialize revolution start */ _ _EI() ; proc_no = 1 ; /* Set next processing number */ } else if ( sw_mode == CCW ) { _ _DI() ; stop_flag = OFF ; /* Stop flag off */ object_speed = -SPEED_MINI ; /* Set target speed to minimum value */ timer_count = WATCH_START ; /* Set speed monitor start time to */ /* 5 SEC */ accel_count = ACCEL_VAL_1ST ; /* Set acceleration/deceleration counter */ init_flag = 3 ; /* CCW initial request */ start_init() ; /* Initialize revolution start */ _ _EI() ; proc_no = 4 ; /* Set CCW processing number */ } break ; /* CW processing, acceleration */ case 1 : if ( accel_count == 0 ) { accel_count = ACCEL_VAL ; /* Set acceleration/deceleration counter */ if ( object_speed < speed ) { object_speed += accel_spd ; if ( object_speed > speed ) object_speed = speed; timer_count = WATCH_START ; /* Set speed monitor start time to 5 SEC */ } else if ( object_speed > speed ) { object_speed -= accel_spd ; if ( object_speed < speed ) object_speed = speed; timer_count = WATCH_START ; /* Set speed monitor start time to 5 SEC */ } else { proc_no = 2 ; /* Constant-speed processing */ }
Application Note U17209EJ1V0AN
73
CHAPTER 4 PROGRAM LIST
} if ( (sw_mode == CCW) || (sw_mode == STOP) ) { proc_no = 3 ; /* Deceleration, set processing number */ } break ; /* CW processing, constant-speed */ case 2 : object_speed = speed ; if ( (sw_mode == CCW) || (sw_mode == STOP) ) { proc_no = 3 ; /* Deceleration, set processing number */ } break ; /* CW stop processing */ case 3 : if ( accel_count == 0 ) { accel_count = ACCEL_VAL ; /* Set acceleration/deceleration counter */ if ( object_speed > SPEED_MINI ) { object_speed -= accel_spd ; if ( object_speed < SPEED_MINI ) object_speed = SPEED_MINI; timer_count = WATCH_START ; /* Set speed monitor start time to 5 SEC */ } else { stop_flag = ON ; /* Stop flag on */ proc_no = 0 ; /* Set stop processing number */ } } break ; /* CCW processing, acceleration */ case 4 : if ( accel_count == 0 ) { accel_count = ACCEL_VAL ; /* Set acceleration/deceleration counter */ if ( object_speed < -speed ) { object_speed += accel_spd ; if ( object_speed > -speed ) object_speed = -speed; timer_count = WATCH_START ; /* Set speed monitor start time to 5 SEC */ } else if ( object_speed > -speed ) { object_speed -= accel_spd ; if ( object_speed < -speed ) object_speed = -speed; timer_count = WATCH_START ; /* Set speed monitor start time to 5 SEC */ } else { proc_no = 5 ; /* Constant-speed processing */ } } if ( (sw_mode == CW) || (sw_mode == STOP) ) { proc_no = 6 ; /* Deceleration, set processing number */ } break ; /* CCW processing, constant-speed */ case 5 :
74
Application Note U17209EJ1V0AN
CHAPTER 4 PROGRAM LIST
object_speed = -speed ; if ( (sw_mode == CW) || (sw_mode == STOP) ) { proc_no = 6 ; /* Deceleration, set processing number */ } break ; /* CCW stop processing */ case 6 : if ( accel_count == 0 ) { accel_count = ACCEL_VAL ; /* Set acceleration/deceleration counter */ if ( object_speed < -SPEED_MINI ) { object_speed += accel_spd ; if ( object_speed > -SPEED_MINI ) object_speed = -SPEED_MINI; timer_count = WATCH_START ; /* Set speed monitor start time to 5 SEC */ } else { stop_flag = ON ; /* Stop flag on */ proc_no = 0 ; /* Set stop processing number */ } } break ; }
if ( ( proc_no == 2 ) || ( proc_no == 5 ) ) { if ( timer_count == 0 ) { if ( abs( object_speed - now_speed ) > SA_SPEED_MAX ) { error_flag = ERR_NO2 ; /* Set error No. */ } } }
if ( disp_co == 0 ) { led_num(1, d_speed / 100 ); /* Number of revolutions */ d_speed = 0 ; disp_co = 100 ; if ( abs(now_speed) == 0 ) { disp_co = 0; } led_num(2, 1000/PWM_TS ); /* Carrier frequency */ led_num(3, cont_time ); /* Overall processing time */ led_num(4, cont_time1 ); /* Vector operation processing time */ } if ( error_flag ) { while( 1 ) { OUT_data( LED41, ~0x00 ) ; /* LED display off */ OUT_data( LED42, ~0x00 ) ; timer_count = 50 ; while( timer_count ) ; if ( error_flag == ERR_NO1 ) { OUT_data( LED41, ~0x9e ) ; /* E1 display */
Application Note U17209EJ1V0AN
75
CHAPTER 4 PROGRAM LIST
OUT_data( LED42, ~0x60 ) ; } else if ( error_flag == ERR_NO2 ) { OUT_data( LED41, ~0x9e ) ; /* E2 display */ OUT_data( LED42, ~0xda ) ; } else { OUT_data( LED41, ~0x9e ) ; /* E3 display */ OUT_data( LED42, ~0xf2 ) ; } timer_count = 50 ; while( timer_count ) ; } } } }

4.1.6 LED display function

/****************************************************************************** / /* LED value display subroutine */ /* no : Display area number (1 to 4) */ /* data: Display data (0 to 99) */ /****************************************************************************** / void led_num( int no, long data ) { if ( no == 1 ) { data = data % 10000; OUT_data( LED11, ~led_pat[data/1000]&0xff ) ; OUT_data( LED12, ~led_pat[(data%1000)/100]&0xff ) ; OUT_data( LED13, ~led_pat[(data%100)/10]&0xff ) ; OUT_data( LED14, ~led_pat[data%10]&0xff ) ; } else if ( no == 2 ) { OUT_data( LED21, ~led_pat[(data%100)/10]&0xff ) ; OUT_data( LED22, ~led_pat[data%10]&0xff ) ; } else if ( no == 3 ) { OUT_data( LED31, ~led_pat[(data%100)/10]&0xff ) ; OUT_data( LED32, ~led_pat[data%10]&0xff ) ; } else { OUT_data( LED41, ~led_pat[(data%100)/10]&0xff ) ; OUT_data( LED42, ~led_pat[data%10]&0xff ) ; } } /****************************************************************************** / /* External I/O output subroutine */ /* reg : Output register number */ /* data: Output data */ /****************************************************************************** / void OUT_data( unsigned short reg, unsigned short data ) {
76
Application Note U17209EJ1V0AN
CHAPTER 4 PROGRAM LIST
if ( reg == WRESET ) { P4.3 = 0; data = 1; /* Dummy step */ P4.3 = 1; } else { PDL = data | ( reg << 8 ); PDL = reg | ( reg << 8 ) | 0x8000; } } /****************************************************************************** / /* External I/O input subroutine */ /* reg: Input register number */ /****************************************************************************** / unsigned short IN_data( int reg ) { unsigned char *po; /* */ if ( reg == SW ) { return P4; } else { return 0; } }

4.1.7 Motor control interrupt processing function

#include "Common.h" #include "Motor.h" #pragma ioreg /* Peripheral I/O register definition */ /****************************************************************************** / /* Motor control timer interrupt processing */ /****************************************************************************** / _ _interrupt void int_MOTOR(void) { ADSCM00 = 0x8001 ; /* Start AD0 */ ADSCM10 = 0x8000 ; /* Start AD1 */ } /****************************************************************************** / /* Motor control processing */ /****************************************************************************** / void Motor_CONT(void) { signed int wrm, wre, trm, tre ; signed int o_wre, we, o_iqap, o_iqa ; signed int s_time, ek, sa ; unsigned char wk ; signed int cow ;
Application Note U17209EJ1V0AN
77
CHAPTER 4 PROGRAM LIST
signed int o_vua, o_vva, o_vwa ; signed int o_vda, o_vqa ; /* */ /****************************************************************************** / /* Calculation processing of speed and rotor position */ /****************************************************************************** / fcalcu( &wrm, &trm ) ; sum_speed += ( wrm * TH_U / RPM_RADS ) ; /* Radian -> rpm */ if ( --speed_co == 0 ) { speed_co = 100000 / TS ; /* Set 100 mSEC counter value */ now_speed = sum_speed / speed_co ; sum_speed = 0 ; } wrm = now_speed * RPM_RADS / TH_U ; wre = wrm * P ; tre = ( trm * P + OFFSET ) % RAD ;
if ( ( stop_flag == OFF ) && ( error_flag == 0 ) ) { s_time = TM3 ; TUC00 = 0x02 ; /* Clear PWM output prohibition */ OUT_data( WRESET, 0 ) ; /* Reset watchdog timer */ /****************************************************************************** / /* Initial revolution processing */ /****************************************************************************** / if ( init_flag ) { cow = init_upco ; if ( cow > 4 ) cow = 4; if ( ++init_co > ( (long)up_data[ cow ] * 34000L / ( SPEED_INIT * TS ) ) ) { init_co = 0 ; if ( init_flag == 2 ) { wk = cw_data[ init_pat++ ][0] ; } else { wk = ccw_data[ init_pat++ ][0] ; } if ( wk & 0x01 ) { BFCM00 = 0 ; BFCM01 = PWM_INIT ; BFCM02 = PWM_INIT ; } else if ( wk & 0x04 ) { BFCM00 = PWM_INIT ; BFCM01 = 0 ; BFCM02 = PWM_INIT ; } else { BFCM00 = PWM_INIT ; BFCM01 = PWM_INIT ; BFCM02 = 0 ; } POER0 = wk ;
78
Application Note U17209EJ1V0AN
CHAPTER 4 PROGRAM LIST
if ( init_pat >= 6 ) { init_pat = 0 ; if ( init_upco > 14 ) { init_flag = 0 ; } else { init_upco++ ; } } } } else { /****************************************************************************** / /* Normal revolution processing */ /****************************************************************************** / o_wre = abs(object_speed) * RPM_RADS * P / TH_U ; /* rpm -> radian conversion */ we = o_wre - wre ;
o_iqap = ( ( wre * KSP ) + ( we * KSP ) ) >> KSPGETA ; o_iqa = o_iqap + ( o_iqai >> KSIGETA ) ;
if ( o_iqai > IQAMAX ) { o_iqai = IQAMAX ; } else if ( o_iqai < -IQAMAX ) { o_iqai = -IQAMAX ; } else { o_iqai += ( KSI * we ) ; }
pwm_value = o_iqa ; if ( pwm_value <= 0 ) { pwm_value = 1 ; } else if ( pwm_value >= PWM_DATA ) { pwm_value = ( PWM_DATA ) - 1 ; } wk = POER0 ; if ( wk & 0x01 ) { BFCM00 = 0 ; BFCM01 = pwm_value ; BFCM02 = pwm_value ; } else if ( wk & 0x04 ) { BFCM00 = pwm_value ; BFCM01 = 0 ; BFCM02 = pwm_value ; } else { BFCM00 = pwm_value ; BFCM01 = pwm_value ; BFCM02 = 0 ; }
Application Note U17209EJ1V0AN
79
CHAPTER 4 PROGRAM LIST
cont_time1 = ( TM3 - s_time ) * 10 / 16; /* Convert to uSEC */ } } else { POER0 = 0x00 ; /* All phases off */ now_speed = 0; cont_time1 = 0; } } /****************************************************************************** / /* Calculation processing of speed, etc. */ /****************************************************************************** / void fcalcu( signed int *wrm, signed int *trm ) { signed short es_trm, cur_time, delta, i ; signed int wwrm, wk, *p1, *p2; // // Speed and position calculation from zero-cross point // cur_time = TM4 ; delta = ( (RAD/6/P) * cur_time ) / sa_time ; /* Calculation of rotor position */ /* difference from reference point */ /* (radian) */ if ( object_speed >= 0 ) { es_trm = base_position + delta; } else { es_trm = base_position - delta; if ( es_trm < 0 ) es_trm += (RAD/P); }
total_sa -= before_posi[20][1] ;
p1 = (int *)before_posi[19] ; p2 = (int *)before_posi[20] ; for ( i = 0; i <= 19 ; i++ ) { *p2-- = *p1-- ; } before_posi[0][0] = *trm = es_trm % (RAD/P) ;
wk = before_posi[0][0] - before_posi[1][0] ; if ( abs(wk) > (RAD/2/P) ) { if ( wk < 0 ) { wk = (RAD/P) + wk ; } else { wk = wk - (RAD/P) ; } }
before_posi[1][1] = wk ;
80
Application Note U17209EJ1V0AN
CHAPTER 4 PROGRAM LIST
total_sa += wk ; /* Total difference in average buffer */ wwrm = ( total_sa * ( 1000000 / 20 / TH_U ) / TS ); *wrm = wwrm ; /* Speed radian/second */ }

4.1.8 Zero-cross interrupt processing function

/****************************************************************************** / /* U zero-cross point interrupt */ /****************************************************************************** / _ _interrupt void int_U(void) { unsigned char wk ; /* */ if ( ( ( init_flag == 0 ) && ( stop_flag == OFF) ) ) { sa_time = TM4 ; TMC4 = 0x61; TMC4 = 0x63; /* Restart timer */
if ( ~P2 & 0x04 ) { /* Check W phase */ base_position = 0 ; } else { base_position = RAD/2/P ; }
if ( object_speed < 0 ) { wk = run_ccw_data[ P2 & 0x07 ][0] ; } else { wk = run_cw_data[ P2 & 0x07 ][0] ; } if ( wk & 0x01 ) { BFCM00 = 0 ; BFCM01 = pwm_value ; BFCM02 = pwm_value ; } else if ( wk & 0x04 ) { BFCM00 = pwm_value ; BFCM01 = 0 ; BFCM02 = pwm_value ; } else { BFCM00 = pwm_value ; BFCM01 = pwm_value ; BFCM02 = 0 ; } POER0 = wk ; } int_co++ ; }
Application Note U17209EJ1V0AN
81
CHAPTER 4 PROGRAM LIST
/****************************************************************************** / /* V zero-cross point interrupt */ /****************************************************************************** / _ _interrupt void int_V(void) { unsigned char wk ; /* */ if ( ( ( init_flag == 0 ) && ( stop_flag == OFF) ) ) { sa_time = TM4 ; TMC4 = 0x61; TMC4 = 0x63; /* Restart timer */
if ( ~P2 & 0x01 ) { /* Check U phase */ base_position = RAD/3/P ; } else { base_position = RAD*5/6/P ; }
if ( object_speed < 0 ) { wk = run_ccw_data[ P2 & 0x07 ][0] ; } else { wk = run_cw_data[ P2 & 0x07 ][0] ; } if ( wk & 0x01 ) { BFCM00 = 0 ; BFCM01 = pwm_value ; BFCM02 = pwm_value ; } else if ( wk & 0x04 ) { BFCM00 = pwm_value ; BFCM01 = 0 ; BFCM02 = pwm_value ; } else { BFCM00 = pwm_value ; BFCM01 = pwm_value ; BFCM02 = 0 ; } POER0 = wk ; } int_co++ ; } /****************************************************************************** / /* W zero-cross point interrupt */ /****************************************************************************** / _ _interrupt void int_W(void) { unsigned char wk ;
82
Application Note U17209EJ1V0AN
CHAPTER 4 PROGRAM LIST
/* */ if ( ( ( init_flag == 0 ) && ( stop_flag == OFF) ) ) { sa_time = TM4 ; TMC4 = 0x61; TMC4 = 0x63; /* Restart timer */
if ( ~P2 & 0x02 ) { /* Check V phase */ base_position = RAD*2/3/P ; } else { base_position = RAD/6/P ; }
if ( object_speed < 0 ) { wk = run_ccw_data[ P2 & 0x07 ][0] ; } else { wk = run_cw_data[ P2 & 0x07 ][0] ; } if ( wk & 0x01 ) { BFCM00 = 0 ; BFCM01 = pwm_value ; BFCM02 = pwm_value ; } else if ( wk & 0x04 ) { BFCM00 = pwm_value ; BFCM01 = 0 ; BFCM02 = pwm_value ; } else { BFCM00 = pwm_value ; BFCM01 = pwm_value ; BFCM02 = 0 ; } POER0 = wk ; } int_co++ ; }

4.1.9 10 mSEC interval interrupt processing function

/****************************************************************************** / /* Other timer interrupt processing (10 mSEC interval) */ /****************************************************************************** / _ _multi_interrupt void int_ETC(void) { unsigned short dummy ; /* Wait timer processing */ if ( timer_count != 0 ) { timer_count -= 1 ; }
Application Note U17209EJ1V0AN
83
CHAPTER 4 PROGRAM LIST
/* Acceleration/deceleration timer processing */ if ( accel_count != 0 ) { accel_count -= 1 ; } /* */ if ( disp_co != 0 ) { d_speed += abs( now_speed ) ; disp_co -= 1 ; } }

4.1.10 A/D converter interrupt processing function

/****************************************************************************** / /* A/D converter interrupt processing for U-phase current and speed volume */ /****************************************************************************** / _ _multi_interrupt void int_AD0(void) { iua = (( ADCR00 & 0x3ff ) - 0x200) ; if ( abs(iua) > MAX_I ) { POER0 = 0 ; /* PWM output off */ error_flag = ERR_NO1 ; /* Set error No. */ } volume = 1023 - ( ADCR01 & 0x3ff ) ; /* Set volume value */ Motor_CONT() ; cont_time = TM3 * 10 / 16; /* Convert to uSEC */ } /****************************************************************************** / /* A/D converter interrupt processing for V-phase current */ /****************************************************************************** / _ _interrupt void int_AD1(void) { iva = (( ADCR10 & 0x3ff ) - 0x200) ; if ( abs(iva) > MAX_I ) { POER0 = 0 ; /* PWM output off */ error_flag = ERR_NO1 ; /* Set error No. */ } }

4.1.11 Hardware initialization processing function

/****************************************************************************** / /* Hardware (peripheral I/O) initialization */ /****************************************************************************** / void hinit( void ) {
84
Application Note U17209EJ1V0AN
CHAPTER 4 PROGRAM LIST
short dummy ; /* Port mode register initialization */ PM4 = 0xf7 ; PMDL = 0x0000 ;
OUT_data( LED11, 0xff ) ; /* LED OFF */ OUT_data( LED12, 0xff ) ; OUT_data( LED13, 0xff ) ; OUT_data( LED14, 0xff ) ; OUT_data( LED21, 0xff ) ; OUT_data( LED22, 0xff ) ; OUT_data( LED31, 0xff ) ; OUT_data( LED32, 0xff ) ; OUT_data( LED41, 0xff ) ; OUT_data( LED42, 0xff ) ; /* Set 10 mSEC timer TM2 */ STOPTE0 = 0x0000; PRM02 = 0x01; /* Select fXX/2 */ CSE0 = 0x0028; /* Select fCLK/64 (3.2 uSEC) */ TCRE0 = 0x2000; /* Start timer */ CVSE50 = 1562*2 ; /* 10 mSEC */ CMSE050 = 0x2400; CC2IC5 = 0x06; /* Set motor control interrupt timer TM3 */ PRM03 = 1 ; /* fCLK = fXX */ TMC30 = 0x51; /* fXX = 4 MHz*10/64(1.6 uSEC) */ TMC31 = 0x09 ; CC30 = TS * 10 / 16 ; /* TS uSEC interval */ TMC30 = 0x53; /* Start timer */ CC3IC0 = 0x02; /* Reset interrupt mask */ /* Set speed measuring timer TM4 */ TMC4 = 0x61; /* fXX(4 MHz*10/2)/128(6.4 uSEC) */ CM4 = 0xffff; TMC4 = 0x63; /* TM4 start */ /* TM0 initialization */ PRM01 = 0 ; /* fCLK = fXX/2 */ SPEC0 = 0x0000 ; TOMR0 = 0x80 ; /* Set output mode */ PSTO0 = 0x00 ; /* Disable real-time output */ BFCM00 = PWM_DATA /2 ; /* Set duty to 50 */ BFCM01 = PWM_DATA /2 ; /* Set duty to 50 */ BFCM02 = PWM_DATA /2 ; /* Set duty to 50 */ BFCM03 = PWM_DATA ; /* Set PWM cycle */ DTRR0 = 40*3 ; /* Dead time 6 uSEC */ POER0 = 0x3f ; /* All phases active */ TMC00 = 0x8018 ; /* Start TMPWM timer */ /* Set A/D */
Application Note U17209EJ1V0AN
85
CHAPTER 4 PROGRAM LIST
ADSCM00 = 0x0001 ; ADSCM10 = 0x0000 ; ADIC0 = 0x03 ; ADIC1 = 0x03 ; /* Set zero-cross signal interrupt pin */ FEM0 = 0x0c ; /* INTP20 both-edge interrupt */ CC2IC0 = 0x01 ; FEM1 = 0x0c ; /* INTP21 both-edge interrupt */ CC2IC1 = 0x01 ; FEM2 = 0x0c ; /* INTP22 both-edge interrupt */ CC2IC2 = 0x01 ; OUT_data( MODE, 0x02 ) ; /* Voltage comparator mode */ }

4.1.12 Common area initialization processing function

/****************************************************************************** / /* Common area initialization */ /****************************************************************************** / void ainit( void ) { /* Initialization of flags */ error_flag = 0 ; /* Clear error flag */ init_flag = OFF ; /* Initial flag off */ disp_co = 100 ; d_speed = 0 ; /* Motor control area initialization */ stop_flag = ON ; /* Stop flag on */ object_speed = 0 ; /* Target speed 0 */ o_iqai = 0 ; /* Speed integral value 0 */ }

4.1.13 Revolution start initialization processing function

/****************************************************************************** / /* Revolution start initialization */ /****************************************************************************** / void start_init( void ) { int i; /* */ for ( i = 0 ; i < 21 ; i++ ) before_posi[i][1] = 0; total_sa = 0 ; sum_speed = 0 ; speed_co = 100000 / TS ;
init_co = 0 ; init_pat = 0 ;
86
Application Note U17209EJ1V0AN
CHAPTER 4 PROGRAM LIST
init_upco = 0 ; }

4.1.14 Link directive file for V850E/IA1

/****************************************************************************** / /* Link directive file for V850E/IA1 */ /****************************************************************************** / VECT_RESET: !LOAD ?RX V0x0000000 { .vect_RESET = $PROGBITS ?AX .vect_RESET; }; ID_NO: !LOAD ?RX V0x0000070 { .id_NO = $PROGBITS ?AX .id_NO; }; VECT_U: !LOAD ?RX V0x00001f0 { .vect_U = $PROGBITS ?AX .vect_U; }; VECT_V: !LOAD ?RX V0x0000200 { .vect_V = $PROGBITS ?AX .vect_V; }; VECT_W: !LOAD ?RX V0x0000210 { .vect_W = $PROGBITS ?AX .vect_W; }; VECT_ETC: !LOAD ?RX V0x0000240 { .vect_ETC = $PROGBITS ?AX .vect_ETC; }; VECT_MOTOR: !LOAD ?RX V0x0000260 { .vect_MOTOR = $PROGBITS ?AX .vect_MOTOR; }; VECT_AD0: !LOAD ?RX V0x00003a0 { .vect_AD0 = $PROGBITS ?AX .vect_AD0; }; VECT_AD1: !LOAD ?RX V0x00003b0 { .vect_AD1 = $PROGBITS ?AX .vect_AD1; };
HANDLER: !LOAD ?RX V0x00001000 { .handler = $PROGBITS ?AX .handler; }; TEXT: !LOAD ?RX { .text = $PROGBITS ?AX .text; };
CONST : !LOAD ?R { .const = $PROGBITS ?A .const; };
DATA : !LOAD ?RW V0x0fffc000 {
Application Note U17209EJ1V0AN
87
CHAPTER 4 PROGRAM LIST
.data = $PROGBITS ?AW ; .sdata = $PROGBITS ?AWG ; .sbss = $NOBITS ?AWG ; .bss = $NOBITS ?AW ; };
_ _tp_TEXT @ %TP_SYMBOL; _ _gp_DATA @ %GP_SYMBOL &_ _tp_TEXT{DATA}; _ _ep_DATA @ %EP_SYMBOL;
88
Application Note U17209EJ1V0AN
CHAPTER 4 PROGRAM LIST

4.2 Program List (V850E/IA2)

4.2.1 Symbol definition

/****************************************************************************** / /* Common area */ /****************************************************************************** / unsigned char ram_start ; unsigned char error_flag ; /* Error flag */ unsigned char init_flag ; /* Initial flag */ unsigned short cont_time ; /* Interrupt control time uSEC */ unsigned short cont_time1 ; /* Vector operation time uSEC */ unsigned short disp_co ; /* Interrupt control time display timer */ unsigned short volume ; /* Volume value */ unsigned short timer_count ; /* Time wait counter */ unsigned short accel_count ; /* Acceleration/deceleration operation time */ /* counter */ unsigned char stop_flag ; /* Stop flag */ signed short before_posi[21][2] ; /* Position buffer */ signed short total_sa ; /* Position total difference */ signed int sum_speed ; signed int speed_co ; signed int now_speed ; /* Present speed rms */ signed int object_speed ; /* Target speed rms */ unsigned int d_speed ; /* Display speed rms */ unsigned char ram_end ;
#pragma section const begin const unsigned short led_pat[10] = { 0xfc, 0x60, 0xda, 0xf2, 0x66, 0xb6, 0xbe, 0xe0, 0xfe, 0xe6 } ; #pragma section const end /****************************************************************************** / /* Common flags */ /****************************************************************************** / extern unsigned char ram_start ; extern unsigned char error_flag ; /* Error flag */ extern unsigned char init_flag ; /* Initial flag */ extern unsigned short cont_time ; /* Interrupt control time uSEC */ extern unsigned short cont_time1 ; /* Vector operation time uSEC */ extern unsigned short disp_co ; /* Interrupt control time display timer */ extern unsigned short volume ; /* Volume value */ extern unsigned short timer_count ; /* Time wait counter */ extern unsigned short accel_count ; /* Acceleration/deceleration operation */ /* time counter */ extern unsigned char stop_flag ; /* Stop flag */ extern signed short before_posi[21][2] ; /* Position buffer */ extern signed short total_sa ; /* Position total difference */ extern signed int sum_speed ;
Application Note U17209EJ1V0AN
89
CHAPTER 4 PROGRAM LIST
extern signed int speed_co ; extern signed int now_speed ; /* Present speed rms */ extern signed int object_speed ; /* Target speed rms */ extern unsigned int d_speed ; /* Display speed rms */ extern unsigned char ram_end ;
#pragma section const begin extern const unsigned short led_pat[] ;; #pragma section const end /****************************************************************************** / /* Motor common definition */ /****************************************************************************** / extern signed short iua ; /* U-phase current */ extern signed short iva ; /* V-phase current */ extern signed int o_iqai ; /* Speed integral value area */ extern signed int base_position ; /* Speed estimation value reference point */ extern unsigned int sa_time ; /* Speed measurement value */ extern unsigned short timer_count ; /* Time wait counter */ extern unsigned short accel_count ; /* Acceleration/deceleration operation */ /* time counter */
extern unsigned short init_co ; /* Initial interrupt counter */ extern unsigned char init_pat ; /* Initial pattern counter */ extern unsigned short init_upco ; /* Initial speed-up counter */ extern unsigned int int_co ; /* UVW interrupt counter */ extern signed int pwm_value ; /* PWM output value */
#pragma section const begin extern const unsigned char cw_data[][2] ; extern const unsigned char ccw_data[][2] ; extern const unsigned char up_data[] ; extern const unsigned char run_cw_data[][2] ; extern const unsigned char run_ccw_data[][2] ; #pragma section const end

4.2.2 Constant definition

/****************************************************************************** / /* I/O */ /****************************************************************************** / #define BASE_IO 0xc200000 #define LED11 3 #define LED12 2 #define LED13 1 #define LED14 0 #define LED21 5 #define LED22 4 #define LED31 7
90
Application Note U17209EJ1V0AN
CHAPTER 4 PROGRAM LIST
#define LED32 6 #define LED41 9 #define LED42 8
#define DIPSW 0x10 #define SW 0x20 #define DA1 0x30 #define DA2 0x40 #define DA3 0x50 #define WRESET 0x60 #define MODE 0x70 /****************************************************************************** / /* Constant */ /****************************************************************************** / #define ON 1 #define OFF 0 #define CW 1 /* CW operation mode */ #define CCW 2 /* CCW operation mode */ #define STOP 0 /* Operation stop mode */ #define ERR_NO1 1 /* Overcurrent error */ #define ERR_NO2 2 /* Speed difference error */ /****************************************************************************** / /* Motor constant */ /****************************************************************************** / /* Motor constant */ #define PAI 3.14159265 /* π */ #define TH_U 1000 /* Radian value jack-up constant */ #define RAD (int)(2*PAI*TH_U) /* Radian value of one revolution */ #define OFFSET 1945 /* Original point OFFSET */ #define RPM_RADS (int)((2*PAI*TH_U)/60) /* rpm -> radian conversion constant */ /* Motor constant */ #define KSP 750 /* Speed proportion constant */ #define KSI 10 /* Speed integral constant */ #define P 2 /* Number of poles */
#define KSPGETA 10 /* KP jack-up constant */ #define KSIGETA 14 /* KSI jack-up constant */ #define SGETA 14 /* sin jack-up constant */
#define PWM_TS 80 /* PWM cycle */ #define PWM_DATA (PWM_TS/0.05) /* PWM set value */ #define SPEED_MAX 3000 /* Maximum speed 3000 rpm */ #define SPEED_MINI 800 /* Minimum speed 800 rpm */ #define SPEED_INIT 700 /* Initial revolution speed rpm */ #define SA_SPEED_MAX 800 /* Maximum speed difference rpm */ #define IQAMAX 200000 /* Maximum speed integral value */ #define MAX_I 800 /* Maximum current value */ #define TS 200 /* Motor control time interval uSEC */
Application Note U17209EJ1V0AN
91
CHAPTER 4 PROGRAM LIST
#define ACCEL_TIME 1 /* Acceleration/deceleration time */ /* constant 10 mSEC */ #define ACCEL_DATA 40 /* Number of acceleration/deceleration */ /* incremental revolutions rpm */ #define WATCH_START 500 /* Speed monitor start time 10 mSEC */ #define ACCEL_VAL_1ST 50 /* Initial acceleration/deceleration */ /* time constant */ #define ACCEL_VAL 3 /* Acceleration/deceleration time */ /* constant */ #define ACCEL_SPD 50 /* Acceleration/deceleration constant */
#define PWM_INIT PWM_DATA/4 /* PWM initial value */ /****************************************************************************** / /* Function constant */ /****************************************************************************** / void fcalcu( signed int *wrm, signed int *trm ); void OUT_data( unsigned short reg, unsigned short data ); unsigned short IN_data( int reg ); void led_num( int no, long data ) ; /****************************************************************************** / /* Motor-related common area */ /****************************************************************************** / signed short iua ; /* U-phase current */ signed short iva ; /* V-phase current */ signed int o_iqai ; /* Speed integral value area */ signed int base_position ; /* Speed estimation value reference point */ unsigned int sa_time ; /* Speed measurement value */ unsigned short timer_count ; /* Time wait counter */ unsigned short accel_count ; /* Acceleration/deceleration operation time counter */
unsigned short init_co ; /* Initial interrupt counter */ unsigned char init_pat ; /* Initial pattern counter */ unsigned short init_upco ; /* Initial speed-up counter */ unsigned int int_co ; /* UVW interrupt counter */ signed int di ; signed int pwm_value ; /* PWM output value */
#pragma section const begin const unsigned char cw_data[6][2] = { {0x09,0x00},{0x21,0x00},{0x24,0x00}, {0x06,0x00},{0x12,0x00},{0x18,0x00} }; const unsigned char ccw_data[6][2] = { {0x18,0x00},{0x12,0x00},{0x06,0x00}, {0x24,0x00},{0x21,0x00},{0x09,0x00} }; const unsigned char up_data[] = { 255, 242, 229, 217, 206, 195, 185, 176, 166, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, 158 } ; const unsigned char run_cw_data[8][2] = { {0x00,0x00},{0x21,0x00},{0x06,0x00}, {0x24,0x00},{0x18,0x00},{0x09,0x00}, {0x12,0x00},{0x00,0x00} };
92
Application Note U17209EJ1V0AN
CHAPTER 4 PROGRAM LIST
const unsigned char run_ccw_data[8][2] = { {0x00,0x00},{0x09,0x00},{0x24,0x00}, {0x21,0x00},{0x12,0x00},{0x18,0x00}, {0x06,0x00},{0x00,0x00} }; #pragma section const end

4.2.3 Interrupt handler setting

/****************************************************************************** / /* Interrupt symbol table */ /****************************************************************************** / .extern _ _start .extern _int_MOTOR .extern _int_U .extern _int_V .extern _int_W .extern _int_AD0 .extern _int_AD1 .extern _int_ETC
.globl V_RESET .globl V_U .globl V_V .globl V_W .globl V_ETC .globl V_MOTOR .globl V_AD0 .globl V_AD1 #******************************************************************************* .section ".handler",text V_RESET: Jr _ _start V_U: ld.w [sp],r1 add 4,sp jr _int_U -- INTP20 V_V: ld.w [sp],r1 add 4,sp jr _int_V -- INTP21 V_W: ld.w [sp],r1 add 4,sp jr _int_W -- INTP22 V_ETC: ld.w [sp],r1 add 4,sp jr _int_ETC -- Other timers V_MOTOR:
Application Note U17209EJ1V0AN
93
CHAPTER 4 PROGRAM LIST
ld.w [sp],r1 add 4,sp jr _int_MOTOR -- Speed control timer V_AD0: ld.w [sp],r1 add 4,sp jr _int_AD0 -- A/D converter CH0 V_AD1: ld.w [sp],r1 add 4,sp jr _int_AD1 -- A/D converter CH1
.extern V_RESET .extern V_U .extern V_V .extern V_W .extern V_ETC .extern V_MOTOR .extern V_AD0 .extern V_AD1 /****************************************************************************** / /* Interrupt jump table */ /****************************************************************************** / .section ".vect_RESET",text mov #V_RESET,r1 jmp [r1]
.section ".id_NO",text .byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
.section ".vect_U",text add -4,sp st.w r1,[r3] mov #V_U,r1 jmp [r1]
.section ".vect_V",text add -4,sp st.w r1,[r3] mov #V_V,r1 jmp [r1]
.section ".vect_W",text add -4,sp st.w r1,[r3] mov #V_W,r1 jmp [r1]
94
Application Note U17209EJ1V0AN
CHAPTER 4 PROGRAM LIST
.section ".vect_ETC",text add -4,sp st.w r1,[r3] mov #V_ETC,r1 jmp [r1]
.section ".vect_MOTOR",text add -4,sp st.w r1,[r3] mov #V_MOTOR,r1 jmp [r1]
.section ".vect_AD0",text add -4,sp st.w r1,[r3] mov #V_AD0,r1 jmp [r1]
.section ".vect_AD1",text add -4,sp st.w r1,[r3] mov #V_AD1,r1 jmp [r1]

4.2.4 Startup routine setting

#============================================================================= # DESCRIPTIONS: # This assembly program is a sample of start-up module for ca850. # If you modified this program, you must assemble this file, and # locate a given directory. # # Unless -G is specified, sections are located as the following. # # | : | # | : | # tp -> -+-------------- + _ _start _ _tp_TEXT # | start up | # |-------------- | # text section | | # | user program | # | | # |-------------- | # | library | # -+-------------- + # | | # sdata section | | # | |
Application Note U17209EJ1V0AN
95
CHAPTER 4 PROGRAM LIST
# gp -> -+-------------- + _ _ssbss # | | # sbss section | | # | | # +-------------- + _ _stack _ _esbss _ _sbss # | stack area | # bss section | | # | 0x400 bytes | # sp -> -+-------------- + _ _stack + STACKSIZE _ _ebss # | : | # | : | # | : | # ep -> -+-------------- + _ _ep_DATA # tidata section | | # -+-------------- + # sidata section | | # -+-------------- + # | : | # | : | # #============================================================================= #----------------------------------------------------------------------------­# special symbols #----------------------------------------------------------------------------­ .extern _ _tp_TEXT, 4 .extern _ _gp_DATA, 4 .extern _ _ep_DATA, 4 .extern _ _ssbss, 4 .extern _ _esbss, 4 .extern _ _sbss, 4 .extern _ _ebss, 4
#----------------------------------------------------------------------------­# C program main function #----------------------------------------------------------------------------­ .extern _main
#----------------------------------------------------------------------------­# dummy data declaration for creating sbss section #----------------------------------------------------------------------------­ .sbss .lcomm _ _sbss_dummy, 0, 0
#----------------------------------------------------------------------------­# system stack
96
Application Note U17209EJ1V0AN
CHAPTER 4 PROGRAM LIST
#----------------------------------------------------------------------------­ .set STACKSIZE, 0x400 .bss .lcomm _ _stack, STACKSIZE, 4
#----------------------------------------------------------------------------­# start up # pointers: tp - text pointer # gp - global pointer # sp - stack pointer # ep - element pointer # exit status is set to r10 #----------------------------------------------------------------------------­ .text .align 4 .globl _ _start .globl _exit .globl _ _exit _ _start: mov 0x02,r10 st.b r10,VSWC[r0] -- Set peripheral I/O wait
mov 0x07,r10 -- ×10 st.b r0,PHCMD[r0] st.b r10,CKC[r0] -- PLL xx multiplication nop nop nop nop nop
mov #_ _tp_TEXT, tp -- set tp register mov #_ _gp_DATA, gp -- set gp register offset add tp, gp -- set gp register mov #_ _stack+STACKSIZE, sp -- set sp register mov #_ _ep_DATA, ep -- set ep register # mov #_ _ssbss, r13 -- clear sbss section mov #_ _esbss, r12 cmp r12, r13 jnl .L11 .L12: st.w r0, [r13] add 4, r13 cmp r12, r13 jl .L12 .L11: #
Application Note U17209EJ1V0AN
97
CHAPTER 4 PROGRAM LIST
mov #_ _sbss, r13 -- clear bss section mov #_ _ebss, r12 cmp r12, r13 jnl .L14 .L15: st.w r0, [r13] add 4, r13 cmp r12, r13 jl .L15 .L14: # jarl _main, lp -- call main function _ _exit: halt -- end of program _ _startend: nop # # #-------------------------- end of start up module ----------------------------# # #

4.2.5 Main processing function

#include "Common.h" #include "Motor.h" #pragma ioreg /* Peripheral I/O register definition */
static int save_psw; /****************************************************************************** / /* 3-phase motor control program */ /****************************************************************************** / void main() { unsigned char proc_no ; /* Present processing number */ signed int speed ; /* Indication speed rms */ signed int accel_spd ; int sw, sw_mode ; /* */ hinit() ; /* Hardware initialization */ ainit() ; /* Initialization of area used */ proc_no = 0 ; _ _EI(); while( 1 ) { accel_spd = ( SPEED_MAX - SPEED_MINI ) / 100; speed = ( ( SPEED_MAX - SPEED_MINI ) * volume / 1024 ) + SPEED_MINI ; /* Indication speed calculation by volume */ sw = ~IN_data( SW ) & 0x07 ; /* Read operation button */ if ( sw == 1 ) { sw_mode = CW ;
98
Application Note U17209EJ1V0AN
CHAPTER 4 PROGRAM LIST
} else if ( sw == 2 ) { sw_mode = CCW ; } else if ( sw == 4 ) { sw_mode = STOP ; } switch( proc_no ) { /* STOP processing */ case 0 : if ( sw_mode == CW ) { _ _DI() ; object_speed = SPEED_MINI ; /* Set target speed to minimum value */ stop_flag = OFF ; timer_count = WATCH_START ; /* Set speed monitor start time to 5 SEC */ accel_count = ACCEL_VAL_1ST ; /* Set acceleration/deceleration counter */ init_flag = 2 ; /* CCW initial request */ start_init() ; /* Initialize revolution start */ _ _EI() ; proc_no = 1 ; /* Set next processing number */ } else if ( sw_mode == CCW ) { _ _DI() ; stop_flag = OFF ; /* Stop flag off */ object_speed = -SPEED_MINI ; /* Set target speed to minimum value */ timer_count = WATCH_START ; /* Set speed monitor start time to 5 SEC */ accel_count = ACCEL_VAL_1ST ; /* Set acceleration/deceleration counter */ init_flag = 3 ; /* CCW initial request */ start_init() ; /* Initialize revolution start */ _ _EI() ; proc_no = 4 ; /* Set CCW processing number */ } break ; /* CW processing, acceleration */ case 1 : if ( accel_count == 0 ) { accel_count = ACCEL_VAL ; /* Set acceleration/deceleration counter */ if ( object_speed < speed ) { object_speed += accel_spd ; if ( object_speed > speed ) object_speed = speed; timer_count = WATCH_START ; /* Set speed monitor start time to 5 SEC */ } else if ( object_speed > speed ) { object_speed -= accel_spd ; if ( object_speed < speed ) object_speed = speed; timer_count = WATCH_START ; /* Set speed monitor start time to 5 SEC */ } else { proc_no = 2 ; /* Constant-speed processing */ } } if ( (sw_mode == CCW) || (sw_mode == STOP) ) { proc_no = 3 ; /* Deceleration, set processing number */
Application Note U17209EJ1V0AN
99
CHAPTER 4 PROGRAM LIST
} break ; /* CW processing, constant-speed */ case 2 : object_speed = speed ; if ( (sw_mode == CCW) || (sw_mode == STOP) ) { proc_no = 3 ; /* Deceleration, set processing number */ } break ; /* CW stop processing */ case 3 : if ( accel_count == 0 ) { accel_count = ACCEL_VAL ; /* Set acceleration/deceleration counter */ if ( object_speed > SPEED_MINI ) { object_speed -= accel_spd ; if ( object_speed < SPEED_MINI ) object_speed = SPEED_MINI; timer_count = WATCH_START ; /* Set speed monitor start time to 5 SEC */ } else { stop_flag = ON ; /* Stop flag on */ proc_no = 0 ; /* Set stop processing number */ } } break ; /* CCW processing, acceleration */ case 4 : if ( accel_count == 0 ) { accel_count = ACCEL_VAL ; /* Set acceleration/deceleration counter */ if ( object_speed < -speed ) { object_speed += accel_spd ; if ( object_speed > -speed ) object_speed = -speed; timer_count = WATCH_START ; /* Set speed monitor start time to 5 SEC */ } else if ( object_speed > -speed ) { object_speed -= accel_spd ; if ( object_speed < -speed ) object_speed = -speed; timer_count = WATCH_START ;/* Set speed monitor start time to 5 SEC */ } else { proc_no = 5 ; /* Constant-speed processing */ } } if ( (sw_mode == CW) || (sw_mode == STOP) ) { proc_no = 6 ; /* Deceleration, set processing number */ } break ; /* CCW processing, constant-speed */ case 5 : object_speed = -speed ; if ( (sw_mode == CW) || (sw_mode == STOP) ) { proc_no = 6 ; /* Deceleration, set processing number */
100
Application Note U17209EJ1V0AN
CHAPTER 4 PROGRAM LIST
} break ; /* CCW stop processing */ case 6 : if ( accel_count == 0 ) { accel_count = ACCEL_VAL ; /* Set acceleration/deceleration counter */ if ( object_speed < -SPEED_MINI ) { object_speed += accel_spd ; if ( object_speed > -SPEED_MINI ) object_speed = -SPEED_MINI; timer_count = WATCH_START ; /* Set speed monitor start time to 5 SEC */ } else { stop_flag = ON ; /* Stop flag on */ proc_no = 0 ; /* Set stop processing number */ } } break ; }
if ( ( proc_no == 2 ) || ( proc_no == 5 ) ) { if ( timer_count == 0 ) { if ( abs( object_speed - now_speed ) > SA_SPEED_MAX ) { error_flag = ERR_NO2 ; /* Set error No.*/ } } }
if ( disp_co == 0 ) { led_num(1, d_speed / 100 ); /* Number of revolutions */ d_speed = 0 ; disp_co = 100 ; if ( abs(now_speed) == 0 ) { disp_co = 0; } led_num(2, 1000/PWM_TS ); /* Carrier frequency */ led_num(3, cont_time ); /* Overall processing time */ led_num(4, cont_time1 ); /* Vector operation processing time */ } if ( error_flag ) { while( 1 ) { OUT_data( LED41, ~0x00 ) ; /* LED display off */ OUT_data( LED42, ~0x00 ) ; timer_count = 50 ; while( timer_count ) ; if ( error_flag == ERR_NO1 ) { OUT_data( LED41, ~0x9e ) ; /* E1 display */ OUT_data( LED42, ~0x60 ) ; } else if ( error_flag == ERR_NO2 ) { OUT_data( LED41, ~0x9e ) ; /* E2 display */
Application Note U17209EJ1V0AN
101
CHAPTER 4 PROGRAM LIST
OUT_data( LED42, ~0xda ) ; } else { OUT_data( LED41, ~0x9e ) ; /* E3 display */ OUT_data( LED42, ~0xf2 ) ; } timer_count = 50 ; while( timer_count ) ; } } } }

4.2.6 LED display function

/****************************************************************************** / /* LED value display subroutine */ /* no : Display area number (1 to 4) */ /* data : Display data (0 to 99) */ /****************************************************************************** / void led_num( int no, long data ) { if ( no == 1 ) { data = data % 10000; OUT_data( LED11, ~led_pat[data/1000]&0xff ) ; OUT_data( LED12, ~led_pat[(data%1000)/100]&0xff ) ; OUT_data( LED13, ~led_pat[(data%100)/10]&0xff ) ; OUT_data( LED14, ~led_pat[data%10]&0xff ) ; } else if ( no == 2 ) { OUT_data( LED21, ~led_pat[(data%100)/10]&0xff ) ; OUT_data( LED22, ~led_pat[data%10]&0xff ) ; } else if ( no == 3 ) { OUT_data( LED31, ~led_pat[(data%100)/10]&0xff ) ; OUT_data( LED32, ~led_pat[data%10]&0xff ) ; } else { OUT_data( LED41, ~led_pat[(data%100)/10]&0xff ) ; OUT_data( LED42, ~led_pat[data%10]&0xff ) ; } } /****************************************************************************** / /* External I/O output subroutine */ /* reg : Output register number */ /* data : Output data */ /****************************************************************************** / void OUT_data( unsigned short reg, unsigned short data ) { if ( reg == WRESET ) { P3.0 = 0; data = 1; /* Dummy step */
102
Application Note U17209EJ1V0AN
CHAPTER 4 PROGRAM LIST
P3.0 = 1; } else { PDL = data | ( reg << 8 ); PDL = reg | ( reg << 8 ) | 0x8000; } } /****************************************************************************** / /* External I/O input subroutine */ /* reg : Input register number */ /****************************************************************************** / unsigned short IN_data( int reg ) { unsigned char *po; /* */ if ( reg == SW ) { return P4; } else { return 0; } }

4.2.7 Motor control interrupt processing function

#include "Common.h" #include "Motor.h" #pragma ioreg /* Peripheral I/O register definition */ /****************************************************************************** / /* Motor control timer interrupt processing */ /****************************************************************************** / _ _interrupt void int_MOTOR(void) { ADSCM00 = 0x8001 ; /* Start AD0 */ ADSCM10 = 0x8000 ; /* Start AD1 */ } /****************************************************************************** / /* Motor control processing */ /****************************************************************************** / void Motor_CONT(void) { signed int wrm, wre, trm, tre ; signed int o_wre, we, o_iqap, o_iqa ; signed int s_time, ek, sa ; unsigned char wk ; signed int cow ; signed int o_vua, o_vva, o_vwa ; signed int o_vda, o_vqa ; /* */
Application Note U17209EJ1V0AN
103
Loading...