78K0 uPD78010x Subseries Low Cost DC

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 1st, 2010
Renesas Electronics Corporation
Issued by: Renesas Electronics Corporation (http://www.renesas.com)
Send any inquiries to http://www.renesas.com/inquiry.
Notice
1.
2.
3.
4.
5.
6.
7.
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.
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.
You should not alter, modify, copy, or otherwise misappropriate any Renesas Electronics product, whether in whole or in part.
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.
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.
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.
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”:
8.
9.
10.
11.
12.
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; anticrime 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.
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.
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.
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.
This document may not be reproduced or duplicated, in any form, in whole or in part, without prior written consent of Renesas
Electronics.
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 majorityowned subsidiaries.
(Note 2) “Renesas Electronics product(s)” means any product developed or manufactured by or for Renesas Electronics.
Application Note
78K0
µPD78010x Subseries
Low Cost DC-Motor Control
using NEC 8-bit Single-Chip Microcontrollers
Document No. U17482EE1V0AN00
Date Published April 2005
 NEC Corporation 2005
Printed in Germany
NOTES FOR CMOS DEVICES
1
PRECAUTION AGAINST ESD FOR SEMICONDUCTORS
Note:
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 once, when it has occurred. Environmental control
must be adequate. When it is dry, humidifier should be used. It is recommended to avoid using
insulators that easily build 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 bench and floor should be grounded. The operator should be grounded using
wrist strap. Semiconductor devices must not be touched with bare hands. Similar precautions need
to be taken for PW boards with semiconductor devices on it.
2
HANDLING OF UNUSED INPUT PINS FOR CMOS
Note:
No connection for CMOS device inputs can be cause of malfunction. If no connection is provided
to the input pins, it is possible that an internal input level may be generated due to noise, etc., hence
causing malfunction. CMOS devices behave differently than Bipolar or NMOS devices. Input levels
of CMOS devices must be fixed high or low by using a pull-up or pull-down circuitry. Each unused
pin should be connected to V DD or GND with a resistor, if it is considered to have a possibility of
being an output pin. All handling related to the unused pins must be judged device by device and
related specifications governing the devices.
3
STATUS BEFORE INITIALIZATION OF MOS DEVICES
Note:
Power-on does not necessarily define initial status of MOS device. Production process of MOS
does not define the initial operation status of the device. Immediately after the power source is
turned ON, the devices with reset function have not yet been initialized. Hence, power-on does
not guarantee out-pin levels, I/O settings or contents of registers. Device is not initialized until the
reset signal is received. Reset operation must be executed immediately after power-on for devices
having reset function.
All other product, brand, or trade names used in this publication are the trademarks
or registered trademarks of their respective trademark owners.
Product specifications are subject to change without notice. To ensure that you have the latest
product data, please contact your local NEC Electronics sales office.
2
Application Note U17482EE1V0AN00
• The information in this document is current as of April, 2005. 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 customerdesignated "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 02. 11-1
Application Note U17482EE1V0AN00
3
Regional Information
Some information contained in this document may vary from country to country. Before using any NEC
product in your application, please contact the NEC 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.
NEC Electronics America Inc.
Santa Clara, California
Tel: 408-588-6000
800-366-9782
Fax: 408-588-6130
800-729-9288
NEC Electronics (Europe) GmbH
Duesseldorf, Germany
Tel: 0211-65 03 1101
Fax: 0211-65 03 1327
Sucursal en España
Madrid, Spain
Tel: 091- 504 27 87
Fax: 091- 504 28 60
Succursale Française
Vélizy-Villacoublay, France
Tel: 01-30-67 58 00
Fax: 01-30-67 58 99
4
Filiale Italiana
Milano, Italy
Tel: 02-66 75 41
Fax: 02-66 75 42 99
NEC Electronics Hong Kong Ltd.
Hong Kong
Tel: 2886-9318
Fax: 2886-9022/9044
Branch The Netherlands
Eindhoven, The Netherlands
Tel: 040-244 58 45
Fax: 040-244 45 80
NEC Electronics Hong Kong Ltd.
Seoul Branch
Seoul, Korea
Tel: 02-528-0303
Fax: 02-528-4411
Branch Sweden
Taeby, Sweden
Tel: 08-63 80 820
Fax: 08-63 80 388
United Kingdom Branch
Milton Keynes, UK
Tel: 01908-691-133
Fax: 01908-670-290
NEC Electronics Singapore Pte. Ltd.
Singapore
Tel: 65-6253-8311
Fax: 65-6250-3583
NEC Electronics Taiwan Ltd.
Taipei, Taiwan
Tel: 02-2719-2377
Fax: 02-2719-5951
Application Note U17482EE1V0AN00
Table of Contents
Chapter 1
1.1
1.2
Chapter 2
2.1
2.2
Chapter 3
3.1
3.2
Chapter 4
4.1
4.2
4.3
4.4
4.5
Chapter 5
Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
µPD780103 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
DC-Motors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
DC Motor Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
DC Motor Control Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
System Concept . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
System Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
System Configuration. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Hardware Configuration. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Schematic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
µPD780103 Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Peripherals and I/O Usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
8-bit Hn Timer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
A/D Converter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Software Process Descriptions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
5.1
5.2
5.3
5.4
5.5
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Main . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
AD_convert (ISR). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Ramp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
5.5.1 CMP_reg. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
5.6 turn_left or turn_right . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Chapter 6
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Chapter 7
Software Flow Charts. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Chapter 8
Program Listing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Application Note U17482EE1V0AN00
5
List of Figures
Figure 2-1:
Figure 2-2:
Figure 3-1:
Figure 3-2:
Figure 4-1:
Figure 4-2:
Figure 4-3:
Figure 4-4:
Figure 5-1:
Figure 7-1:
Figure 7-2:
Figure 7-3:
Figure 7-4:
Figure 7-5:
Figure 7-6:
Figure 7-7:
Figure 7-8:
Figure 7-9:
Figure 7-10:
Figure 7-11:
6
DC Motor - Operation .................................................................................................. 11
H-bridge....................................................................................................................... 12
Basic System Configuration ........................................................................................ 13
System Configuration with µPD780103 Peripherals.................................................... 14
Schematic Diagram ..................................................................................................... 16
Block Diagram of 8-bit H0 Timer ................................................................................. 19
Block Diagram of 8-bit H1 Timer ................................................................................. 20
Block Diagram of A/D Converter ................................................................................. 21
Initialization Process.................................................................................................... 24
Main Program Flowchart ............................................................................................. 27
CPU Clock Initialization ............................................................................................... 28
Hardware Initialization ................................................................................................. 29
Main Endless Loop ...................................................................................................... 29
AD_convert (ISR) ........................................................................................................ 30
Left_turn() .................................................................................................................... 31
Right_turn().................................................................................................................. 32
Ramp()......................................................................................................................... 33
CMP_reg() ................................................................................................................... 34
Disable all Interrupts.................................................................................................... 35
Enable all Interrupts..................................................................................................... 35
Application Note U17482EE1V0AN00
List of Tables
Table 1-1:
Table 4-1:
Functional Outline........................................................................................................... 10
I/O Configuration ............................................................................................................ 18
Application Note U17482EE1V0AN00
7
8
Application Note U17482EE1V0AN00
Chapter 1 Overview
1.1 Introduction
This application note describes a low-cost motor control application using an NEC µPD780103 microcontroller.
It covers the issues involved in driving and controlling a DC motor and is intended to help users to
understand the dedicated motor control peripherals of the µPD780103 Subseries. The published software and hardware configurations are meant to serve as examples only and are not intended for mass
production.
Application Note U17482EE1V0AN00
9
Chapter 1
Overview
1.2 µPD780103 Overview
Table 1-1:
Functional Outline
Item
Internal memory
Function
ROM
24 kbytes
High-speed RAM
768 bytes
Memory space
64 kbytes
X1 input clock (oscillation frequency)
Ceramic/crystal/external clock oscillation
10 MHz (VDD = 4.0 to 5.5 V)
8.38 MHz (VDD = 3.3 to 5.5 V)
5
MHz (VDD = 2.7 to 5.5 V)
Ring OSC clock (oscillation frequency)
On-chip ring oscillation (240 kHz (typ.))
General-purpose registers
8 bits × 32 registers (8 bits × 8 registers × 4 banks)
Minimum instruction execution time
0.2 µs/0.4 µs/0.8 µs/1.6 µs/3.2 µs
(X1 input clock: @ fXP = 10 MHz operation)
8.3 µs/16.6 µs/33.2 µs/66.4 µs/132.8 µs (TYP.)
(Ring OSC clock: @ fR = 240 kHz (typ.) operation)
Instruction set
•
•
•
•
I/O ports
Total
CMOS I/O
CMOS input
CMOS output
Timers
•
•
•
•
Timer outputs
16-bit operation
Multiply/divide (8 bits × 8 bits, 16 bits ÷ 8 bits)
Bit manipulate (set, reset, test, and Boolean operation)
BCD adjust, etc.
22
17
4
1
16-bit timer/event counter: 1 channel
8 -bit timer/event counter: 1 channel
8 -bit timer:
2 channels
Watchdog timer:
1 channel
4 (PWM: 3)
A/D converter
10-bit resolution × 4 channels
Serial interface
•
•
Vectored
interrupt sources
Internal
12
External
6
UART mode supporting LIN bus:
3-wire serial I/O mode/UART mode
Reset
•
•
•
•
•
Supply voltage
VDD = 2.7 to 5.5 V
Ambient operating temperature
TA = -40 to +85 °C
Package
30-pin plastic SSOP (7.62 mm (300))
Reset using RESET pin
Internal reset by watchdog timer
Internal reset by clock monitor
Internal reset by power-on-clear
Internal reset by low-voltage detector
Note: * - Select either of these alternate-functions pins.
10
1 channel
*:
Application Note U17482EE1V0AN00
1 channel
Chapter 2
DC-Motors
2.1 DC Motor Basics
DC motors are rotating electric machines designed to operate from source of direct voltage. They are
inexpensive, easy to drive, and readily available in all shapes and sizes. As such, they are used widely
in the industrial, automotive and consumer markets, e.g., for windshield wipers and fans.
A brushed DC motor is the simplest of all motor types, and typically consists a stator, rotor (armature), car-
bon brushes and commutator.
Figure 2-1:
DC Motor - Operation
Rotor
Torque
Coil
S
S
N
Current
Core
- Brush
N
Stator
+ Brush
Current
Current
-
Current
+
Commutator
Battery
The stator of a brushed DC motor consists of two or more permanent magnets generating a stationary
magnetic field that surrounds the rotor.
The rotor (armature) of a DC motor has coils of wire wrapped around its core. These coils are connected to small copper surface, called commutators, mounted on the rotor shaft. The rotor coils are
energized by passing current through the carbon brushes that slide over the commutator segments.
The energized rotor coils produce a magnetic field. The opposite polarities of the rotor and stator field
attract each other and the rotor starts to turn.
When the rotor and stator fields are aligned, the brushes move across the commutator segments and
energize the next rotor winding.
The speed and torque of the motor depends on the strength of the magnetic field generated by the
energized windings of the motor. The strength of the magnetic field depends on the strength of the current. Since speed is directly proportional to armature voltage and inversely proportional to the magnetic
flux produced by the poles, adjusting the armature voltage and/or the field current changes the motor
speed. In this application note speed control is based on generating and varying a PWM signal.
Application Note U17482EE1V0AN00
11
Chapter 2
DC-Motors
2.2 DC Motor Control Requirements
A popular circuit for driving DC motors is the H-bridge where four power switches, e.g., field effect transistors (MOSFET), are configured in an H pattern.
The H-bridge is used to change the sense of rotation, allowing a DC motor to run forward or backward
with a single supply.
The motor speed is influenced by varying the duty cycle of the PWM signal. Varying the duty cycle
changes the average DC voltage that is used to drive the power MOSFETs.
Figure 2-2 shows the basic principle.
Figure 2-2:
H-bridge
H-bridge (forward)
H-bridge (backward)
PWM
T1
PWM
T2
T1
I T2
I T1
IM
M
M
IM
T3
DC
I T3
T2
T3
DC
I T4
T4
T4
The H-bridge consists of two of high-side (T1, T2) and of two low-side (T3, T4) transistors. To drive the
motor in the forward direction, one high-side transistor (T2) is controlled with PWM, and one low-side
transistor (T3) is controlled by DC (soft chopping). T1 and T4 are turned off.
If the PWM pulse is high, T2 is open, and the current flows through T2, over the motor and through T3
to ground (Fig. 2-2a). If the PWM pulse is low, T2 is turned off, and the motor is slowed down. Changing
the duty cycle changes the motor speed.
To drive the motor in the reverse direction, T1 is controlled with PWM, and T4 is controlled by DC. T2
and T3 are turned off. The current flows in reverse direction and the motor turns in the opposite direction (Fig. 2-2b).
12
Application Note U17482EE1V0AN00
Chapter 3 System Concept
3.1 System Design
Figure 3-1 shows the basic block diagram for the DC motor control.
Figure 3-1:
INPUT:
Speed value
Direction
Basic System Configuration
µPD780103
Motor Driver
DC Motor
The µPD780103 evaluates the input signal for sense of rotation and motor speed. The µPD780103
uses this information to generate the appropriate control signals for the motor driver.
Application Note U17482EE1V0AN00
13
Chapter 3
System Concept
3.2 System Configuration
Figure 3-2 shows the system configuration and the µPD780103 peripherals used for the DC motor control.
Figure 3-2:
System Configuration with µPD780103 Peripherals
I/O Port 00
8-bit H0 Timer
Bit 2
P15
Motor Driver
High side
Direction
Bit 3
8-bit H1 Timer
P16
Low side
I/O Port 03
Speed reference
value
10-bit A/D Converter
ANI0/P20
Bit 0
Bit 1
µPD780103
DC Motor
Bit 2 and bit 3 of port 00 are used to scan the switch position that defines the sense of rotation of the
motor. The H0 or H1 timers are activated to generate a PWM signal.
The set voltage on the potentiometer is proportional to the desired motor speed. This voltage is converted by the 10 bit A/D converter and then normalized to 8 bits. The normalized A/D value defines the
duty cycle of the PWM signal that is generated by the H0 or H1 timer. Bit 0 and bit 1 of port 03 are used
to control the low-side driver.
The function of each of the peripherals is described in the next chapter.
14
Application Note U17482EE1V0AN00
Chapter 4 Hardware Configuration
4.1 Schematic
The DC motor in this application has a rated speed of 3000 rpm @ 24 V.
The diagram shows the DC motor control design using a µPD780103 microcontroller and NEC's
NP88N004 CHE PowerMOSFET.
Application Note U17482EE1V0AN00
15
Application Note U17482EE1V0AN00
+
5V
+
56n
5V
50K
1K2
1K2
P1 (Speed reference)
5V
RESET
S2
Direction
B1
15K
+
12p
1 0 M Hz
12p
5V
X2
X1
P130
P03
AVSS
P20 / ANI0
P02
VCC
+
P30
P31
P16
P15
5V
VSS
IC (VPP)
P23 / ANI3
P22 / ANI2
P21 / ANI1
P01
P00
P17
P14
P13
P12
P11
P10
P120
P33
P32
µPD780103
RESET
AVREF
+
S1
10k
10k
10k
10k
10k
10k
10k
10k
10k
10k
10k
2K2
560p
560p
15 V
GND
VS
CS
VB
OUT
15 V
15 V
VS
VCC
+
GND
CS
OUT
IN2
GND
OUT2
MIC 4427
IN1 OUT1
Err
IN
VCC VB
+
Err
IN
VCC
+
1N 4148
IA R 2 1 2 5
1N 4148
IA R 2 1 2 5
24 V
1n
100n
100n
47µ
100n
47µ
1n
1µ
100n
1N4148
10R
100n
100n
1N4148
10R
10R
10R
BZ X 79C 15
47µ
N P88N04 CH E
BZX 79C15
100n
R033
N P88N04 C HE
+
10R
10R
BZX 79C15
NP 88N 04 C H E
100n
BZX 79C15
BYW 96E PH
16
BYW 96E PH
R033
M
M
Figure 4-1:
N P88N04 CH E
Chapter 4
Hardware Configuration
Schematic Diagram
BYW 96E PH
BYW 96E PH
Chapter 4
Hardware Configuration
4.2 µPD780103 Configuration
The µPD780103 device is a member of the high-performance 78K 8-bit microcontroller family, designed
specifically for mid-range motor control applications. The configuration of the device and the operating
environment used in this application are listed below:
• CPU
µPD780103
• Operating clock
System clock – 10 MHz
• Operating voltage
5V
• Internal ROM
24 Kbytes
• Internal RAM
768 bytes
Application Note U17482EE1V0AN00
17
Chapter 4
Hardware Configuration
4.3 Peripherals and I/O Usage
Table 4-2 shows the microcontroller’s I/O pins.
The pins used in the application and their functions are listed.
Table 4-1:
Pin number
18
Pin name
I/O Configuration
Signal name
Mode setting
Function
1
P33/INTP4
I/O
Input
Not used
2
P32/INTP3
I/O
Input
Not used
3
P31/INTP3
I/O
Output
Low-side control
4
P30/INTP1
I/O
Output
Low-side control
5
IC
VPP
6
VSS
Ground
Ground
7
VDD
VDD
VDD
8
X1
Input
Main crystal
9
X2
10
RESET
11
P03
12
Not used
Main crystal
Input
System reset
I/O
Input
Different direction
P02
I/O
Input
Different direction
13
P01/TI010/TO00
I/O
Input
Not used
14
P00/TI000
I/O
Input
Not used
15
P10/SCK10/TXD0
I/O
Input
Not used
16
P11/SI10/RXD0
I/O
Input
Not used
17
P12/SO12
I/O
Input
Not used
18
P13/TXD6
I/O
Input
Not used
19
P14/RXD6
I/O
Input
Not used
20
P15/TOH0
TOH0
Output
PWM out for high side
21
P16/TOH1/INTP5
TOH1
Output
PWM out for high side
22
P17/TI50/TO50
I/O
Input
Not used
23
P130
Output
Output
Not used
24
P23/ANI3
Input
Input
Not used
25
P22/ANI2
Input
Input
Not used
26
P21/ANI1
Input
Input
Not used
27
P20/ANI0
ANI0
Input
Speed reference
28
AVREF
5V
A/D reference
29
AVSS
0V
A/D ground
30
P120/INTP0
Input
Application Note U17482EE1V0AN00
Not used
Chapter 4
Hardware Configuration
4.4 8-bit Hn Timer
This timer is used to generate a PWM signal that controls the speed of the motor via the MOSFETS
driver and MOSFET. The PWM signal is varied by modifying the duty cycle.
Hn (n = 0, 1) has the following functions:
• Interval timer
• Square-wave output
• PWM output
The following shows the block diagram of the H0 timer.
Figure 4-2:
Block Diagram of 8-bit H0 Timer
Internal bus
8-bit timer H mode control
register 0 (TMHMD0)
TMHE0 CKS02 CKS01 CKS00 TMMD01TMMD00 TOLEV0 TOEN0
3
8-bit timer H
compare register
10 (CMP10)
8-bit timer H
compare register
00 (CMP00)
2
TOH0/P15
Decoder
Selector
fX
fX/2
fX/22
fX/26
fX/210
8-bit timer/
event counter 50
output
Selector
Match Interrupt
generator
F/F
R
Output
controller
Level
inversion
Output latch
(P15)
PM15
8-bit timer
counter H0
Clear
PWM mode signal
1
Timer H enable signal
0
INTTMH0
PWM output mode with a frequency of 9.6 kHz is selected. The duty ratio of the 9.6 kHz signal is determined by the value of the 8-bit timer CMP1n compare register.
The calculation result of the speed control algorithm can be set on the fly, i.e., the CMP1n register can
be set at any time without stopping the Hn timer, because rewriting the CMP1n register is permitted
during timer operation.
The Hn timer compare register CMP1n is used to modify the duty cycle of PWM.
Application Note U17482EE1V0AN00
19
Chapter 4
Figure 4-3:
Hardware Configuration
Block Diagram of 8-bit H1 Timer
Internal bus
8-bit timer H mode control
register 1 (TMHMD1)
TMHE1 CKS12 CKS11 CKS10 TMMD11TMMD10 TOLEV1 TOEN1
3
8-bit timer H
compare register
11 (CMP11)
8-bit timer H
compare register
01 (CMP01)
TOH1/
INTP5/
P16
2
Decoder
Selector
Match Interrupt
generator
Selector
fX
fX/22
fX/24
fX/26
fX/212
fR/27
F/F
R
Output
controller
Level
inversion
Output latch
(P16)
PM16
8-bit timer
counter H1
Clear
PWM mode signal
1
0
Timer H enable signal
INTTMH1
The H0 and H1 timers are configured identically.
20
Application Note U17482EE1V0AN00
Chapter 4
Hardware Configuration
4.5 A/D Converter
The µPD780103 has on-chip A/D converter with four input channels that converts an analog input signal into a digital value with 10-bit resolution.
Figure 4-4:
Block Diagram of A/D Converter
AVREF
ADCS bit
ANI0/P20
Sample & hold circuit
ANI2/P22
Tap selector
Voltage comparator
Selector
ANI1/P21
AVSS
ANI3/P23
Successive
approximation
register (SAR)
AVSS
INTAD
Controller
Comparator
A/D conversion result
register (ADCR)
2
ADS1
ADS0
ADCS
FR2
Analog input channel
specification register
(ADS)
FR1
FR0
ADCE
Power-fail comparison
threshold register (PFT)
PFEN PFCM
A/D converter mode
register (ADM)
Power-fail comparison
mode register (PFM)
Internal bus
In this application a potentiometer is connected between VDD (5 V), ground and channel 1 (ANI0) of the
A/D converter. The potentiometer value represents the reference value for the speed control.
The conversion process is continuous and always the last converted value is read out from the ADCR
register of the µPD780103.
The conversion time of the A/D converter is 9.6 µs.
Analog reference AVDD and analog ground of the A/D converter are connected to VDD and VSS, respectively.
Application Note U17482EE1V0AN00
21
[MEMO]
22
Application Note U17482EE1V0AN00
Chapter 5 Software Process Descriptions
5.1 Introduction
The software consists of four main sections:
<1>
<2>
<3>
<4>
Main
Control with 8-bit H0 timer
Control with 8-bit H1 timer
A/D ISR
The motor operation is controlled by the H0, H1 timers and the A/D converter interrupt service routine.
The main program consists of an initialization routine and start-up of the control process.
H0 and H1 generate the PWM signal for controlling the motor speed. The A/D converter ISR provides
the speed reference value.
The operation of each of the software components is described in the following sections.
Application Note U17482EE1V0AN00
23
Chapter 5
Software Process Descriptions
5.2 Initialization
The initialization routine is responsible for initializing the µPD780103 device after a system reset. It configures the clock settings of the device, initializes the peripherals used for the motor control application
and enables the appropriate interrupts. The initialization has two parts as shown in Figure 5-1. The first
part initializes and sets the processor clock of the device and the second part initializes the peripherals
and their operating modes.
Figure 5-1:
Initialization Process
Initialization
Enable interrupts
Set processor
Configure
peripherals
Set port
Define
operating mode
The initialization contains the following sections:
<1>
<2>
<3>
<4>
<5>
24
System clock setting
8-bit H0 timer
8-bit H1 timer
A/D converter
I/O port setting
Application Note U17482EE1V0AN00
Chapter 5
Software Process Descriptions
5.3 Main
The main program provides the framework within which the subroutines execute the various tasks of
the motor control application.
The main program starts by invoking the global initialization subroutines CPU_ClockTo_X1 and
hdw_init.
The endless loop of the main program consists of the PWM generation, direction control and speed stabilization.
5.4 AD_convert (ISR)
The reference speed is given by a potentiometer.
The A/D converter continuously converts its input value. Approx. every 9.6 µs a new reference speed
value is provided to the ADCR register for further calculations.
The ISR normalizes the A/D converter's 10-bit result to 8 bits. The ISR also calculates the difference
between the old and new value of ADCR register. Both values are passed to appropriate routines for
further handling.
5.5 Ramp
This routine performs a soft start-up of the DC motor and soft variance of the motor speed.
After determining of the speed value, the PWM register of the Hn timer is set to minimum speed. Hn
generates the PWM signal for controlling the motor speed.
PWM generation of Hn is enabled and the PWM register, containing the minimum speed value, is incremented to increase the motor speed until the reference speed is reached.
Remark:
n = 0, 1
5.5.1 CMP_reg
This routine is invoked from within the ramp routine.
For a soft start-up or soft speed change, each change in the PWM duty cycle is followed by a delay.
This routine also determines which timer register must be set to the actual value.
5.6 turn_left or turn_right
This is the main control program and consists of the two routines turn_left() and turn_right() that provide
the following functions:
(a)
(b)
(c)
(d)
Set the PWM frequency
Initialize the port that controls the low-side driver
Invoke the ramp function
Determine the direction
Application Note U17482EE1V0AN00
25
Chapter 6 Conclusion
This application example provides a basic DC motor control system suitable for implementation using
NEC’s 78K0 8-bit microcontroller family.
Memory requirements for this example:
• 78K0 – µPD780103
Code:
Data:
24 kbytes available, 1869 bytes used
768 bytes available, 136 bytes used
The 78K0 microcontroller used in this application provides further resources for additional user functions or/and adaptations of the control algorithm.
26
Application Note U17482EE1V0AN00
Chapter 7
Software Flow Charts
Figure 7-1:
Main Program Flowchart
Main
Initialise CPU clock
Initialise Hardware
Disable all interrupts
A/D conversion started
A/D conversion
complete?
No
Yes
Read result A/D value
with 10-bit resolution
Convert the value
to 8-bit
Enable all interrupts
Endless loop
Application Note U17482EE1V0AN00
27
Chapter 7
Figure 7-2:
Software Flow Charts
CPU Clock Initialization
CPU_clock_to_X
Set oscillation
stabilization time
Ring oscillator
stopped?
No
Yes
Set CPU speed
Select X1 as input
clock
X1 is selected?
No
Yes
Select Ring oscillator
mode
Stop Watchdog
Timer
28
Application Note U17482EE1V0AN00
Chapter 7
Software Flow Charts
Figure 7-3:
Hardware Initialization
hdv_init
Initialise I/O Ports
Initialise H0 timer
Initialise H1 timer
Initialise A/D converter
Figure 7-4:
Main Endless Loop
Main Endless
Clear P0
Direction left?
Yes
No
Direction right?
No
left turn()
Clear P0
Yes
right turn()
Clear P0
old_AD = 0
Application Note U17482EE1V0AN00
29
Chapter 7
Software Flow Charts
Figure 7-5:
AD_convert (ISR)
INTAD Interrupt
AD_convert
Read result_AD value
with 10-bit resolution
Convert the value to
8-bit
result_AD
>=
Yes
result_AD = max_duty
No
result_AD <
old_AD?
Yes
delta_ramp =
result_AD - old_AD
Yes
delta_ramp =
old_AD - result_AD
No
result_AD >
old_AD?
No
End
30
Application Note U17482EE1V0AN00
Chapter 7
Software Flow Charts
Figure 7-6:
Left_turn()
left_turn()
Stop H1 timer
Set P3_bit.no1 low
result_AD >
max_delta?
Yes
Disable interrupt
delta_ramp =
result_AD
old_AD = 0
Enable interrupt
ramp()
No
Set P3_bit.no0 high
Set PWM frequency
Direction
left?
Yes
No
result_AD
> 1?
Yes
Disable interrupts
No
result_AD >
max_duty?
Yes
result_AD =
max_duty
No
delta_ramp >
max_delta?
ramp()
Yes
ramp()
No
result_AD >
max_duty?
Yes
result_AD =
max_duty
No
CMP10 =
result_AD
CMP10 = old_AD
H0 timer
OFF?
Yes
Start H0 timer
No
Enable interrupts
Stop H0 timer
End
Application Note U17482EE1V0AN00
31
Chapter 7
Software Flow Charts
Figure 7-7:
Right_turn()
Disable interrupt
old_AD = 0
right_turn()
Stop H0 timer
Set P3_bit.no1 high
result_AD >
max_delta?
Yes
delta_ramp =
result_AD
Enable interrupt
ramp()
No
Set P3_bit.no0 low
Set PWM frequency
Direction
right?
Yes
No
result_AD
> 1?
Yes
Disable interrupts
No
result_AD >
max_duty?
Yes
result_AD =
max_duty
No
delta_ramp >
max_delta?
ramp()
No
result_AD >
max_duty?
Yes
result_AD =
max_duty
No
CMP11 =
result_AD
CMP11 = old_AD
H1 timer
OFF?
Yes
Start H1 timer
No
Enable interrupts
Stop H1 timer
End
32
Application Note U17482EE1V0AN00
Yes
ramp()
Chapter 7
Software Flow Charts
Figure 7-8:
Ramp()
ramp()
Direction
left?
Yes
H0 timer
OFF?
No
Yes
Stop H1 timer
No
Start H0 timer
Yes
Start H1 timer
Yes
H0 timer
OFF?
Direction
right?
No
No
Stop H0 timer
result_AD >
old_AD?
Yes
No
Yes
result_AD <
old_AD?
delta_ramp >
max_delta?
Yes
result_AD =
old_AD
No
No
result_AD =
old_AD
Yes
delta_ramp >
max_delta?
No
Yes
delta_ramp - -
delta_ramp
>0 ?
delta_ramp
>0 ?
No
No
old_AD =
result_AD
old_AD =
result_AD
Yes
delta_ramp - -
result_AD - -
result_AD - -
CMP_reg()
CMP_reg()
End
Application Note U17482EE1V0AN00
33
Chapter 7
Software Flow Charts
Figure 7-9:
CMP_reg()
CMP_reg()
count loop <
Yes
No
Direction
left?
count_loop++
No operation
Yes
CMP10 =
No
Direction
right?
Yes
CMP11 =
No
delta_ramp =
End
34
Application Note U17482EE1V0AN00
Chapter 7
Software Flow Charts
Figure 7-10:
Disable all Interrupts
DI()
Disable
No operation
No operation
End
Figure 7-11:
Enable all Interrupts
EI()
Enable
No operation
No operation
End
Application Note U17482EE1V0AN00
35
[MEMO]
36
Application Note U17482EE1V0AN00
Chapter 8
Program Listing
/***********************************************************************/
/* PROJECT
= Motor control
*/
/* MODULE
= declar.c
*/
/* VERSION
= V0.1
*/
/* DATE
= 18.02.2005
*/
/* LAST CHANGE =
*/
/*
*/
/* NEC Electronics (Europe) GmbH
*/
/* Technical Product Support
*/
/* Customer Engineering Support
*/
/* D-40472 Düsseldorf, Germany
*/
/***********************************************************************/
/* Description: global declaration
*/
/***********************************************************************/
volatile unsigned short result_AD, delta_ramp;
unsigned short old_AD;
unsigned short count_loop;
/***********************************************************************/
/***********************************************************************/
/* PROJECT
= Motor control
*/
/* MODULE
= declar.h
*/
/* VERSION
= V0.1
*/
/* DATE
= 18.02.2005
*/
/* LAST CHANGE =
*/
/*
*/
/* NEC Electronics (Europe) GmbH
*/
/* Technical Product Support
*/
/* Customer Engineering Support
*/
/* D-40472 Düsseldorf, Germany
*/
/***********************************************************************/
/* Description: global declaration and definition
*/
/***********************************************************************/
#ifndef __DECLAR_H__
#define __DECLAR_H__
#define
#define
#define
#define
max_duty 235
PWM_FQ
255
max_delta 10
delay_val 3500
//
//
//
//
define
define
define
define
maximum of duty cycle
PWM frequency
maximum of delta
maximum of delay time value
extern volatile unsigned short result_AD, delta_ramp;
extern unsigned short old_AD;
extern unsigned short count_loop;
#endif
//__DECLAR_H__
/***********************************************************************/
Application Note U17482EE1V0AN00
37
Chapter 8
Program Listing
/***********************************************************************/
/* PROJECT
= Motor control
*/
/* MODULE
= init.c
*/
/* VERSION
= V0.1
*/
/* DATE
= 18.02.2005
*/
/* LAST CHANGE =
*/
/*
*/
/* NEC Electronics (Europe) GmbH
*/
/* Technical Product Support
*/
/* Customer Engineering Support
*/
/* D-40472 Düsseldorf, Germany
*/
/***********************************************************************/
/* Description: Module initializes the UPD780103 Hardware
*/
/***********************************************************************/
/***********************************************************************/
/* include
*/
/***********************************************************************/
#include ’io780103.h’
#include <intrinsics.h>
/***********************************************************************/
/* pragma
*/
/***********************************************************************/
#pragma language = extended
/***********************************************************************/
/* type definitions (function prototypes)
*/
/***********************************************************************/
void CPU_ClockTo_X1(void);
// Select CPU clock
void hdw_init (void);
// Hardware initialization
/***********************************************************************/
void CPU_ClockTo_X1(void)
{
OSTS = 0x02;
//
//
//
//
[email protected] wait after STOP
mode release (RESET value)
-----|||
Osc. stabilization time
-----010 - 2^13/fx
while (!OSTC_bit.no3) {__no_operation();}
// wait until ring oscillator stopped
PCC = 0x00;
// Use high speed mode fCPU=10MHz
MCM = 0x01;
// ------|1 - X1 input clock
MOC = 0x00;
// 0 -------- X1 input clock oscillating
while (!MCM_bit.no1)
{
MOC = 0x00;
MCM = 0x01;
}
RCM = 0x01;
WDTM = 0x77;
}
38
// Ring oscillator stopped
// 01110111 watchdog timer stopped
// end of vSwitchCPUClockToX1()
Application Note U17482EE1V0AN00
Chapter 8
Program Listing
/***********************************************************************/
void hdw_init (void)
{
/***********************************************************************/
/*************
setting port mode register, port register
************/
PM0=0xFF;
PM1=0x9F;
PM3=0xFC;
//1111 1111 P02,P03,P00,P01 as input
//1001 1111 P15, P16 as output
//1111 1100 P30, P31 as output for low side
P0=0x00;
P1=0x00;
P3=0x00;
//0000 0000 P02,P03,P00,P01 to input low level
//0000 0000 P15,P16 to output latch
//0000 0000 P30-P33 to output latch
/***********************************************************************/
__enable_interrupt();
/***********************************************************************/
/*************************
TMHMD0=0x29;
TMHMD1=0x19;
Timer H0, H1 setting
******************/
//0010 1001 f=2,5M;PWM mode;stopped;output enabled
//0001 1001 f=2,5M;PWM mode;stopped;output enabled
/***********************************************************************/
/******************
A/D Converter setting
************************/
ADS=0x00;
//00000000 ANI0 as input
ADM=0x31;
//00110001 operation with 9.6µs and with
//AVref (stopped)
ADMK=0;
//interrupt for AD-conversion enabled
/***********************************************************************/
}
//end of hdw_init()
Application Note U17482EE1V0AN00
39
Chapter 8
Program Listing
/***********************************************************************/
/* PROJECT
= Motor control
*/
/* MODULE
= main.c
*/
/* VERSION
= V0.1
*/
/* DATE
= 18.02.2005
*/
/* LAST CHANGE =
*/
/*
*/
/* NEC Electronics (Europe) GmbH
*/
/* Technical Product Support
*/
/* Customer Engineering Support
*/
/* D-40472 Düsseldorf, Germany
*/
/***********************************************************************/
/* Description: Main function
*/
/***********************************************************************/
/***********************************************************************/
/* type definitions (function prototypes)
*/
/***********************************************************************/
void CPU_ClockTo_X1(void);
// Select CPU clock
void hdw_init (void);
// Hardware initialization
void left_turn(void);
// Motorcontrol with H0 timer
void right_turn(void);
// Motorcontrol with H1 timer
void ramp(void);
// ramp function
void DI(void);
// disable interrupts
void EI(void);
// enable interrupts
/***********************************************************************/
// pragma
/***********************************************************************/
#pragma language = extended
/***********************************************************************/
// include
/***********************************************************************/
#include ’io780103.h’
#include ’declar.h’
#include <intrinsics.h>
/***********************************************************************/
void main(void)
{
CPU_ClockTo_X1();
hdw_init ();
DI();
// disable interrupts
ADCS=1;
while(!ADIF){}
result_AD=(ADCR>>8)-0.5;
//
//
//
//
EI();
// enable interrupts
40
start conversion
wait for conversion
Convert the 10 bit Result register
to 8 bit and to integer
Application Note U17482EE1V0AN00
Chapter 8
while (1)
{
P0=0x00;
}
}
Program Listing
// start endless loop
// Clear P0
if (P0_bit.no2 == 1)
{
left_turn();
P0=0x00;
}
// turn left
if (P0_bit.no3 == 1)
{
right_turn();
P0=0x00;
}
// turn right
old_AD=0;
// new initialisation of old value of ADC
// Clear P0
// end of
// Clear P0
// end of
if (P0_bit.no2 == 1)
if (P0_bit.no3 == 1)
// end of while(1)
// end of main
Application Note U17482EE1V0AN00
41
Chapter 8
Program Listing
/***********************************************************************/
/* PROJECT
= Motor control
*/
/* MODULE
= interr.c
*/
/* VERSION
= V0.1
*/
/* DATE
= 18.02.2005
*/
/* LAST CHANGE =
*/
/*
*/
/* NEC Electronics (Europe) GmbH
*/
/* Technical Product Support
*/
/* Customer Engineering Support
*/
/* D-40472 Düsseldorf, Germany
*/
/***********************************************************************/
/* Description: interrupt vector
*/
/***********************************************************************/
/***********************************************************************/
// include
/***********************************************************************/
#include ’io780103.h’
#include <intrinsics.h>
#include <declar.h>
/***********************************************************************/
#pragma vector = INTAD_vect
__interrupt void AD_convert(void)
{
result_AD=(ADCR>>8)-0.5;
if(result_AD>=max_duty)
{
result_AD=max_duty;
}
//set limit of duty cycle
if(result_AD < old_AD)
{
delta_ramp = old_AD - result_AD;
}
else if(result_AD > old_AD)
{
delta_ramp = result_AD - old_AD;
}
}
42
//end of AD_convert()
Application Note U17482EE1V0AN00
Chapter 8
Program Listing
/***********************************************************************/
/* PROJECT
= Motor control
*/
/* MODULE
= ramp.c
*/
/* VERSION
= V0.1
*/
/* DATE
= 18.02.2005
*/
/* LAST CHANGE =
*/
/*
*/
/* NEC Electronics (Europe) GmbH
*/
/* Technical Product Support
*/
/* Customer Engineering Support
*/
/* D-40472 Düsseldorf, Germany*/
/***********************************************************************/
/* Description: ramp function
*/
/***********************************************************************/
/***********************************************************************/
/* type definitions (function prototypes)
*/
/***********************************************************************/
void ramp(void);
// ramp function
void CMP_reg(void);
// determine the CMP-register
/***********************************************************************/
// pragma
/***********************************************************************/
#pragma language = extended
/***********************************************************************/
// include
/***********************************************************************/
#include ’io780103.h’
#include ’declar.h’
#include <intrinsics.h>
/***********************************************************************/
void ramp(void)
{
if((P0_bit.no2 == 1)&&(!TMHE0))
{
TMHE1=0;
//stop H1
TMHE0=1;
//start H0
}
else if ((P0_bit.no3 == 1)&&(!TMHE1))
{
TMHE0=0;
//stop H0
TMHE1=1;
//start H1
}
if(result_AD > old_AD)
{
if(delta_ramp > max_delta)
{
result_AD = old_AD;
for (delta_ramp; delta_ramp > 0; delta_ramp--)
{
result_AD++;
CMP_reg();
}
//end of for delta_ramp
Application Note U17482EE1V0AN00
43
Chapter 8
}
Program Listing
//end if(delta_ramp > max_delta)
old_AD = result_AD;
}
//end of if(result_AD > old_AD)
/***********************************************************************/
else if(result_AD < old_AD)
{
if(delta_ramp > max_delta)
{
result_AD = old_AD;
for (delta_ramp; delta_ramp > 0; delta_ramp--)
{
result_AD--;
CMP_reg();
}
//end of for delta_ramp
}
//end of if(delta_ramp > max_delta)
old_AD = result_AD;
}
//end of if(result_AD < old_AD)
/***********************************************************************/
}
//end of function ramp()
/***********************************************************************/
/***********************************************************************/
void CMP_reg(void)
{
for(count_loop=0;count_loop<delay_val;count_loop++)//time delay
{
__no_operation();
}
}
44
if(P0_bit.no2 == 1)
{
CMP10 = result_AD;
}
else if (P0_bit.no3 == 1)
{
CMP11=result_AD;
}
else
{
delta_ramp=1;//break of for-loop
}
// end of function CMP_reg()
Application Note U17482EE1V0AN00
Chapter 8
Program Listing
/***********************************************************************/
/* PROJECT
= Motor control
*/
/* MODULE
= control.c
*/
/* VERSION
= V0.1
*/
/* DATE
= 18.02.2005
*/
/* LAST CHANGE =
*/
/*
*/
/* NEC Electronics (Europe) GmbH
*/
/* Technical Product Support
*/
/* Customer Engineering Support
*/
/* D-40472 Düsseldorf, Germany
*/
/***********************************************************************/
/* Description: Motor control with H0 and H1 timers
*/
/***********************************************************************/
/***********************************************************************/
// include
/***********************************************************************/
#include ’io780103.h’
#include ’declar.h’
#include <intrinsics.h>
/***********************************************************************/
/***********************************************************************/
/* type definitions (function prototypes)
*/
/***********************************************************************/
void left_turn(void);
// Motorcontrol with H0 timer
void right_turn(void);
// Motorcontrol with H1 timer
void ramp(void);
// ramp function
void DI(void);
// disable interrupts
void EI(void);
// enable interrupts
/***********************************************************************/
/*******************
void left_turn (void)
{
Motorcontrol with H0 timer
TMHE1=0;
P3_bit.no1 = 0;
P3_bit.no0 = 1;
CMP00=PWM_FQ;
//
//
//
//
if(result_AD>max_delta)
{
DI();
******************/
stop H1
Low Side of H1 OFF
Low Side of H0 ON
Set PWM frequency for H0 = 9.6 kHz
// disable interrupts
old_AD=0;
delta_ramp = result_AD;
ramp();
EI();
// enable interrupts
}
Application Note U17482EE1V0AN00
45
Chapter 8
Program Listing
while ((P0_bit.no2 == 1)&&(result_AD >=1))
{
DI();
// disable interrupts
if(result_AD>=max_duty)
{
result_AD = max_duty; // set limit of duty cycle
if(delta_ramp > max_delta)
{
ramp();
}
}
else
{
ramp();
} // end of else
if(result_AD>=max_duty)
{
result_AD = max_duty;
CMP10 = result_AD;
}
else
{
CMP10 = old_AD;
}
if (!TMHE0)
{
TMHE0=1;
}
EI();
// set limit of duty cycle
// start H0
// enable interrupts
}//End of while
TMHE0=0;
// stop H0
}// end of left_turn()
46
Application Note U17482EE1V0AN00
Chapter 8
Program Listing
/***********************************************************************/
/*****************
Motorcontrol with H1 timer
********************/
void right_turn(void)
{
TMHE0=0;
P3_bit.no1 = 1;
P3_bit.no0 = 0;
CMP01=PWM_FQ;
//
//
//
//
if(result_AD>max_delta)
{
DI();
stop H0
Low Side of H1 ON
Low Side of H0 OFF
Set PWM frequency for H0 = 9.6 kHz
// disable interrupts
old_AD=0;
delta_ramp = result_AD;
ramp();
EI();
// enable interrupts
}
while ((P0_bit.no3 == 1)&&(result_AD >=1))
{
DI();
// disable interrupts
if(result_AD>=max_duty)
{
result_AD=max_duty;
// set limit of duty cycle
if(delta_ramp > max_delta)
{
ramp();
}
}
else
{
ramp();
}
// end of else
if(result_AD>=max_duty)
{
result_AD = max_duty;
CMP11 = result_AD;
}
else
{
CMP11 = old_AD;
}
if (!TMHE1)
{
TMHE1=1;
}
// set limit of duty cycle
// start H1
Application Note U17482EE1V0AN00
47
Chapter 8
EI();
Program Listing
// enable interrupts
}//end of while
TMHE1=0;
}
//stop H1
// end of right_turn()
/***********************************************************************/
48
Application Note U17482EE1V0AN00
Chapter 8
Program Listing
/***********************************************************************/
/* PROJECT
= Motor control
*/
/* MODULE
= d_e_inter.c
*/
/* VERSION
= V0.1
*/
/* DATE
= 18.02.2005
*/
/* LAST CHANGE =
*/
/*
*/
/* NEC Electronics (Europe) GmbH
*/
/* Technical Product Support
*/
/* Customer Engineering Support
*/
/* D-40472 Düsseldorf, Germany
*/
/***********************************************************************/
/* Description: Disable or enable interrupts
*/
/***********************************************************************/
/***********************************************************************/
/* type definitions (function prototypes)
*/
/***********************************************************************/
void DI(void);
void EI(void);
/***********************************************************************/
/***********************************************************************/
// include
/***********************************************************************/
#include <intrinsics.h>
/***********************************************************************/
void DI(void)
{
__disable_interrupt();
__no_operation();
__no_operation();
}
/***********************************************************************/
void EI(void)
{
__enable_interrupt();
__no_operation();
__no_operation();
}
/***********************************************************************/
Application Note U17482EE1V0AN00
49
[MEMO]
50
Application Note U17482EE1V0AN00
Facsimile Message
From:
Name
Company
Tel.
Although NEC has taken all possible steps
to ensure that the documentation supplied
to our customers is complete, bug free
and up-to-date, we readily accept that
errors may occur. Despite all the care and
precautions we've taken, you may
encounter problems in the documentation.
Please complete this form whenever
you'd like to report errors or suggest
improvements to us.
FAX
Address
Thank you for your kind support.
North America
Hong Kong, Philippines, Oceania
NEC Electronics America Inc.
NEC Electronics Hong Kong Ltd.
Corporate Communications Dept. Fax: +852-2886-9022/9044
Fax: 1-800-729-9288
1-408-588-6130
Korea
Europe
NEC Electronics Hong Kong Ltd.
NEC Electronics (Europe) GmbH
Seoul Branch
Market Communication Dept.
Fax: 02-528-4411
Fax: +49(0)-211-6503-1344
Asian Nations except Philippines
NEC Electronics Singapore Pte. Ltd.
Fax: +65-6250-3583
Japan
NEC Semiconductor Technical Hotline
Fax: +81- 44-435-9608
Taiwan
NEC Electronics Taiwan Ltd.
Fax: 02-2719-5951
I would like to report the following error/make the following suggestion:
Document title:
Document number:
Page number:
If possible, please fax the referenced page or drawing.
Document Rating
Excellent
Good
Acceptable
Poor
Clarity
Technical Accuracy
Organization
CS 99.1
[MEMO]