You are on page 1of 38

Tunisia Polytechnic School

Engineering internship report

Design and Implementation of Permanent Magnet DC Motors Control For Electric Wheel-Chair Application
Internship carried out from the 17th of July to 28th of August 2011 at:

Supervised by: M. Khaled OUALI (head of R&D) Elaborated by: Haythem SAKKA (3rd year Engineering Student)

Academic year 2011-2012

Acknowledgments
I would like first to express my Sincere thanks to M. Kaled OUALI who gave me the opportunity to fulfill this successful training in AlphaTec

My deepest gratitude is addressed to all those involved in providing me with the tremendous opportunity of participating in this internship; my appreciation to all those who made my training period in AlphaTec an experience that far surpassed my every expectation. I would like also to thank most warmly my supervisor M. Sabeur FERGENI and M. Mohamed MASMOUDI for their welcome and support to accomplish my work successfully. My welcome to AlphaTec was so warm and it was my greatest privilege to be able to work alongside such skilled and dedicated member staff that had shown me kindness, friendship and hospitality throughout my training period.

Tunisia Polytechnic School

Engineering internship report

Table of Contents
ABSTRACT ..................................................................................................................................................... 2 RSUM ........................................................................................................................................................ 3 INTRODUCTION............................................................................................................................................. 4 I.
A. B. C. 1. 2. 3. 4. 5.

BRUSHED DC MOTOR FUNDAMENTAL .................................................................................................. 5


OVERVIEW .......................................................................................................................................................................................................................... 5 MAGNETIC PRINCIPLES AND MOTOR THEORY ......................................................................................................................................................................... 5 DYNAMIC MODEL OF PERMANENT MAGNET DC MOTOR ........................................................................................................................................................... 8 Electrical characteristics ........................................................................................................................................................................................... 8 Mechanical characteristics ....................................................................................................................................................................................... 9 State Space Representation ..................................................................................................................................................................................... 9 Transfer Function Block Diagram .......................................................................................................................................................................... 10 st Speed control model (1 order model approximation) ........................................................................................................................................ 11

II.
A. B.

HOW TO CONTROL A BRUSHED DC MOTOR .........................................................................................12


BIDIRECTIONAL ROTATION .................................................................................................................................................................................................. 12 SPEED CONTROL ................................................................................................................................................................................................................ 12

III. APPLICATION SETUP .............................................................................................................................13


A. B. C. D. E. F. G. DESCRIPTION OF THE APPLICATION ...................................................................................................................................................................................... 13 SCOPE STATEMENT ............................................................................................................................................................................................................ 13 SYSTEM CONFIGURATION ................................................................................................................................................................................................... 13 USING THE LPC1343 ........................................................................................................................................................................................................ 14 MOTOR SELECTION ............................................................................................................................................................................................................ 15 MOSFET SELECTION ......................................................................................................................................................................................................... 16 CONTROLLING SPEED AND DIRECTION .................................................................................................................................................................................. 16 1. Joystick selection ..................................................................................................................................................................................................... 16 2. Controlling speed and direction ............................................................................................................................................................................. 17 3. Driving model .......................................................................................................................................................................................................... 17

IV. PCB DESIGN ..........................................................................................................................................18


A. B. C. THE ALTIUM DESIGNER ENVIRONMENT ................................................................................................................................................................................ 18 GETTING STARTED WITH PCB DESIGN .................................................................................................................................................................................. 19 THE REALIZED PCB ............................................................................................................................................................................................................ 20

V.
A.

SOFTWARE ...........................................................................................................................................21
NXP LPCXPRESSO DEVELOPMENT PLATFORM ....................................................................................................................................................................... 21 LPCXpresso IDE ........................................................................................................................................................................................................ 22 LPCXpresso development board ............................................................................................................................................................................ 23 B. EVALUATE, EXPLORE AND DEVELOP ...................................................................................................................................................................................... 23 C. LPC1343 CONFIGURATION ................................................................................................................................................................................................ 24 1. GPIO configuration ................................................................................................................................................................................................. 24 2. ADC configuration: .................................................................................................................................................................................................. 27 3. Timer configuration (16-bit Timer) ........................................................................................................................................................................ 28 1. 2.

CONCLUSION................................................................................................................................................32 APPENDIX: ..................................................................................................................................................... I BIBLIOGRAPHY ............................................................................................................................................. IV

1|P ag e

Tunisia Polytechnic School

Engineering internship report

Abstract
This work is part of the research conducted by APLTHATEC company desire to create a prototype of an electric wheelchair. Using basic electronic components and an NPX microcontroller platform, I designed a control board with two brushed DC motors that enables to drive the chair using a 2-axis analog joystick.

2|P ag e

Tunisia Polytechnic School

Engineering internship report

Rsum
Ce travail sinscrit dans le cadre de la recherch mene par APLTHATEC envie de raliser son prototype de chaise roulante lectrique. Utilisant les composants lectroniques de base et une plateforme microcontrleur NPX, javais conu une carte de commande de deux moteurs collecteurs courant continu qui permet de piloter la chaise avec un joystick analogique 2 axes.

3|P ag e

Tunisia Polytechnic School

Engineering internship report

Introduction
The embedded electronic applications occupy a large consumption range nationally and globally. Currently, small Tunisian businesses ensure the production of some applications based on imported technology. Therefore, these products have the disadvantage that they bring little added value and hinder the development of these enterprises. ALPHATECH is a medium-sized business that wants to create products with high added value. For this ALPHATECH implemented an R & D department in order to make its own technology developed around low cost platforms. Currently, APLHATECH is seeking to launch a new product: electric wheelchairs, which are highly demanded on the Tunisian market but yet they are well sold because of their high prices compared to the living standard of Tunisia. In this vision, the R & D ALPHATECH was responsible for implementing a prototype of electric wheelchair at low cost. This was part of my internship where I was responsible for engineering design and implements a control board with two DC motors controlled by a two-axis analog joystick. To make this work, I examined the functioning and control of DC motors. Then, I designed the model of my project and finally, I implemented my model on both Altium Designer to create the pattern of PCB and on the used microcontroller IDE to implement the control algorithm.

4|P ag e

Tunisia Polytechnic School

Engineering internship report

I.

Brushed DC motor fundamental


A. Overview

A brushed PMDC motor typically consists of stationary fixed permanent magnets (the stator) a rotating electro-magnet (the rotor) and a metal body to concentrate the flux (see Fig 1). By attraction of opposite poles and repulsion of like poles, a torque acts on the rotor and makes it turn. As soon as the rotor begins to turn, fixed brushes make and break contact with the rotating segments (commutation) in turn. The rotor coils are energized and de-energized in such way that as the rotor turns, the axis of the new rotor poles are always opposed to the stator poles. Because of the way the commutation is arranged, the rotor is in constant motion. By reversing the power supply to the motor, the current in the rotor coils and therefore the north and south poles are reversed and the motor changes its direction of rotation. The speed and torque of the motor depend on the strength of the magnetic field generated by the energized windings of the motor, which in its turn depend on the current flowing through them. Therefore adjusting the rotor voltage (and current) will change the motor speed.

Fig. 1: Brushed Permanent Magnet Direct Current Motor

B.

Magnetic Principles and Motor Theory

The Lorentz Law enunciates that a current-carrying wire in a magnetic field will induce an electromotive force. When the conductor moves out of the main field, the wire stops because there is no longer any inter action between the flux lines and therefore no force is created.

Fig. 2: Lorentz law demonstration

Since a motor produces a continuous rotation motion, the conductor that is placed inside of the main field (between the two magnets) must be in the shape of a loop. When the loop is connected to a DC supply,

5|P ag e

Tunisia Polytechnic School

Engineering internship report

electron current flows from point A to B of the loop, and from point C to point D on the other side of the loop. Because current flows through the segments of the loop that are opposite each to other, the segment on one side pushes upward while the segment on the other side pushes downward. Because the loop is designed to pivot on its axis, the combined force creates a twisting action called torque.

Fig. 3: Torque creation

When the loop reaches a position perpendicular to the main field, there is no interaction between the flux lines to cause the loop to rotate. This position is called the neutral plane. Due to inertia, the loop continues to rotate counterclockwise (CCW).

Fig. 4: Magnet neutral plane position

However, since the direction of the current flow through the loop does not change, the interaction between the conductor segments and the main field develops a torque in the opposite wise. Instead of continuing in the CCW direction, the loop stops and changes direction. An oscillating motion is produced until the armatures settle in the neutral plane. The continuous rotation of the rotor is achieved by reversing the direction of current through the loop as it passes the neutral plane. A switching device, called a Commutator, achieves the current change. The commutator is shaped like a ring that is split into the segments. Each segment is connected to an end of the loop. The commutator and wire loop rotate together, and they are referred to as the armature.

Fig. 5: Commutator function

As the armature turns, the commutator makes contact with carbon brushes that supply current to the wire loop. Each brush is connected to a DC power supply.

6|P ag e

Tunisia Polytechnic School

Engineering internship report

position1: In this position, current enters the loop through the negative brush and exits through the positive brush.

Fig. 6: Start-up position

Position2: When the rotor aligns with the neutral plane, the brushes make contact with both commutator segments. The rotor loop shorts out, and current flows from one brush to the other through the commutator segments. The result is that no torque is produced, but the inertia causes the rotor to continue turning past the neutral position.

Fig. 7: Neutral position and inertia role

Position3: As the rotor turns into the main field, the switching action of the commutator reverses the direction of the current flow. This causes the current to flow into the rotor section closed to the south pole of the magnet, as it did in position1. The torque that is developed causes the rotor to continue twisting in the CCW direction.

Fig. 8: Commutation position

Position4: As the rotor turns out of the main field, it aligns with the neutral plane position. Inertia will cause the rotor to continue turning into the main field, causing the rotation cycle to be repeated.

7|P ag e

Tunisia Polytechnic School

Engineering internship report

Fig. 9: Neutral position and second commutation

The rotation of the armature continues in one direction because the commutator keeps reversing the direction which makes the current flows through the loop every half turn (180). In this way the magnetic fields of the rotor always interact the same way with the main field to maintain a continuous torque in one direction.

C.

Dynamic model of permanent magnet DC motor

According to the previous section, the DC motor acts as convertor of the electric energy received in the input to mechanic energy delivered in the output. The modeling aims to establish mathematical equations that relate input quantities (current and voltage) with output ones (speed and torque). Two balance equations can be developed by considering the electrical and mechanical characteristics of the system. 1. Electrical characteristics The equivalent electrical circuit of a DC motor is illustrated in Fig10. It can be represented by a voltage source (Va) across the coil of the armature. The electrical equivalent of the armature coil can be described by an inductance (La) in series with a resistance (Ra) in series with an induced voltage (Vc) which opposes the voltage source. The induced voltage is generated by the rotation of the electrical coil through the fixed flux lines of the permanent magnets. This voltage is often referred to as the back emf (electromotive force).

Fig. 10: Electrical representation of PMDC motor

The Kirchoffs voltage law around the electrical loop enables to set the electrical equation linking the voltage (Va) across the armature and the current (Ia) through the armature: (1) The back efm Vc is proportional to the speed W of the rotor. It can be written as: (2)

8|P ag e

Tunisia Polytechnic School

Engineering internship report

Substituting the equation (1) into the equation (2) gives the following differential equation: (3) 2. Mechanical characteristics The mechanical equation reflecting the couples acting on the rotor can be written as following: (4) Where is the electromagnetic torque, is the torque produced from the velocity of the rotor, torque of the mechanical load, and is the inertia of the rotor and the equivalent mechanical load. is the

The electromagnetic torque is proportional to the current through the armature winding and can be written as following: (5) Where is the torque constant and like the velocity constant is dependent on the flux density of the fixed magnets, the reluctance of the iron core, and the number of turns in the armature winding. The torque associated with the velocity is written: (6) where is the damping coefficient associated with the mechanical rotational system of the machine,

Substituting the equations (5) and (6) into (4) gives the following differential equation: (7) 3. State Space Representation The differential equations given in the equations (3) and (7) for the armature current and the angular velocity can be written: (8) (9) which describe the dc motor system. Putting the differential equations into state space form gives:

(10)

(11)

9|P ag e

Tunisia Polytechnic School which is expressed symbolically as:

Engineering internship report

(12) (13) where is the state vector, is the input vector, and is the output vector.

4. Transfer Function Block Diagram A block diagram for the system can be developed from the differential equations (8) and (9). Taking the Laplace transform of each equation gives: (14) (15) If perturbations around some steady state value are considered, the initial conditions go to zero and all the variables become some change around a reference state, and the equations can be expressed as follows: (16)

(17) The above equations can then easily be put into block diagram form. The block diagram obtained from these equations for a permanent magnet dc motor is shown in Fig. 11.

Fig. 11: Block diagram representation of (16) and (17)

The block diagram in (Fig. 11) can be simplified by making the assumption that the load torque is constant. The only load torque to be concerned with is the friction in the system, which is relatively constant while the motor is moving. Since the change in TL is zero, it does not need to appear in the block diagram. Also, if one

10 | P a g e

Tunisia Polytechnic School

Engineering internship report

only focuses on the angular velocity as the response of interest, the block diagram becomes as shown in (Fig. 12).

Fig. 12: Block diagram of the dc motor as modeled in this study

5. Speed control model (1st order model approximation) In general the coefficients and are so close that it is reasonable to consider them equal, while neglecting the losses in the electromechanical power conversion. We consider that: (5) Limiting ourselves to first-order dependencies, we obtain the following transfer function: (17) where defining: The electromechanical time constant of the system: (18) The static gain: (13) We obtain that in the steady state of a DC motor the rotational speed is proportional to the input voltage:

11 | P a g e

Tunisia Polytechnic School

Engineering internship report

II.

How to control a brushed DC motor


A. Bidirectional rotation

Driving a brushed DC motor in both directions, by reversing the current through it, can be accomplished by using a full-bridge (see Fig. 13), which consists of four N-channel MOSFETs. For Forward rotation Q1 and Q4 are switched on while Q2 and Q3 are off. For Reverse rotation Q2 and Q3 are on while Q1 and Q4 are off. If the upper two MOSFETs are turned off and the lower ones are turned on, the motor brakes. The motor will Coast (free running) when the four switches are turned off.

Fig. 13: Bidirectional rotation using a full-bridge

B.

Speed control

The no-load motor speed is proportional to the voltage applied across the motor. Thus by simply varying the voltage across the motor, one can control the speed of the motor. Pulse Width Modulation (PWM) is used to implement this (see Fig. 14). It is based on a fixed frequency pulse waveform with a variable duty cycle. The average voltage applied to the motor is proportional to the PWM duty cycle.

Fig. 14: PWM speed control

12 | P a g e

Tunisia Polytechnic School

Engineering internship report

III.

Application setup A.
Description of the application

The application consists in designing a PCB (Printed Circuit Board) equipped with a microcontroller that enables to drive a wheelchair through acting on a two axis analog Joystick. Two brushed PMDC motors drive the traction wheels of the chair. A careful control of the speed and direction of each motor can cause the chair to move in the direction wished by the user. My main tasks in the company were: Designing the PCB including the selection of these components. Implementing a control algorithm on the selected microcontroller.

B.

Scope statement

I had the opportunity to accomplish my work with materials available in the enterprise. For some electronic components I was allowed to choose from components available at the suppliers of alpha technology. For some costly component, I had to ask my supervisor for alternatives.

C.

System configuration

The system configuration I adopted for my project is like shown is the figure below:

Fig. 15: Block-Diagram of designed system

In this application, the PWM signals (for H Bridges) are generated by one 16 bits Timer match outputs of the LPC1343 microcontroller. The motor speed (duty cycle) and direction are adjusted by reading a potentiometers (of the joystick) using two of the LPC1343s ADC inputs (see Fig. 15).

13 | P a g e

Tunisia Polytechnic School

Engineering internship report

The user gives the instruction via the two axis analog joystick. The output signals of the joystick (voltages) are captured by the LPC1343 and converted to digital. The new values are exploited to determine the proper outputs. Then combinational logic treatment is used to drive the motors.

D.

Using the LPC1343

For this application I used the LPC1343. Available in an LQFP48 or FVQFN33 package it is the most performing member (for now) of the ARM7 Cortex M3 based LPC1300 family. It offers high speed (72 MHz) 32-bit CPU performance and includes 32KB of flash memory, 8KB of data memory, USB Device, one Fastmode plus (Fm+) I2C interface, one UART, 8 ADC channels, four general purpose timers, and 42 general purpose I/O pins.

Fig. 16: LPC134x key features and Block Diagram

14 | P a g e

Tunisia Polytechnic School

Engineering internship report

E.

Motor selection

For this application the company provided me with a 250W motor that is shown shown below. When the engine is no loaded its speed is 452 RPM at 24 V input. The maximum continuous current is 2A. With load torque is 6.23 Nm; speed is 383 RPM and current may up to 13.3A.

Fig. 17: Motor Features

The base frequency of the PWM signal plays an important role in the sound of the motor, thus it affects the human ear that can detect frequencies from 20 Hz to 20 kHz. It also influences the behavior of the motor. Sometimes there is insufficient armature inductance to prevent the current from falling to zero during each cycle parts. This is known as the discontinuous current mode (see Fig. 18), and it is usually encountered when the motor is lightly loaded. It is very undesirable because when the current is discontinuous, the speed falls off rapidly when the load increases. With discontinuous current, the relevant part of the torque-speed curve is very droop and it will cause some pulsing in the motor armature, making the motor much noisier. For this application, using the mentioned motor, and in order to accomplish continuous current mode a PWM frequency of 8 KHz has been selected.

15 | P a g e

Tunisia Polytechnic School

Engineering internship report

Fig. 18: Influence of PWM frequency

F.

MOSFET selection

The ST IRF540 N-channel TrenchMOS logic level FET is used for this system. It is chosen in relation with the selected motor, which is supplied with 24 V, and requires a maximum starting current of 13.3 A. For a 24 V - supplied motor, the MOSFET VDS needs to be at least 40 V, while the drain current needs to be high enough to deal with the motor (starting) current. The latter is already reduced thanks to a softacceleration mechanism (in small steps up / down towards the required speed) implemented in software.

G.

Controlling speed and direction

1. Joystick selection For this application, the joystick is only represented by two potentiometers. But, they act like the 2-Axis Joystick (#27800)1 of PARALLAX Inc.

Fig. 19: PARALLAX two axis joystick

Specifications shown in the appendix.

16 | P a g e

Tunisia Polytechnic School

Engineering internship report

2. Controlling speed and direction In order to control the direction and speed of the motors, two 10 k potentiometers connected with two ADC inputs of the LPC1343 are used (see Fig 4). The first potentiometer controls Forward and Backward movements and the second controls turning Right or Left. The A/D converter has a 10-bit resolution. This means there are 1024 possible potentiometer steps. The center position (+ hysteresis) is the resting point for the motor speed (break).

1023
Forward

Turn left 522

Turn right

Brake

501

Turn left

Turn right

Backward

Fig.20: Analog Input Speed and Direction Scale

3. Driving model Lets consider an instruction defined by the position (X, Y) of a forward linear motion (Fig.20: green area), both wheels are driven in the forward direction with the same speed. Variations on Y enable to vary the speed of the movement, while changes on X enable to vary its radius. If such shifts are positive on X (only shifts in the red zone), the speed of the left wheel is kept unchanged and is the speed of the right wheel declines in proportion to the X offset until canceled.

17 | P a g e

Tunisia Polytechnic School

Engineering internship report

IV.

PCB design

To accomplish this task, I had to learn to use the electronic development environment Altium Designer. This is a software package which allows electronic circuit designers to design, draw and simulate electronic circuit boards. Altium Designer provides a unified electronic product development environment, catering for all aspects of the electronic development process, including: System Design and Capture Physical PCB Design FPGA Hardware Design Embedded Software Development Mixed-Signal Circuit Simulation Signal Integrity Analysis PCB Manufacturing FPGA system implementation and debugging (when working with a suitable FPGA development board, such as an Altium NanoBoard).

A.

The Altium Designer Environment

Altium Designer offers a unique design environment, with all areas of design from capture to generation of PCB manufacturing output; from embedded software development to processing and download of an FPGA design into a physical FPGA device brought together in the one environment through the underlying support of the DXP integration platform. The figure (Fig. 20) summarizes some of the key elements of the Altium Designer environment.

Fig. 20: Altium Designer

18 | P a g e

Tunisia Polytechnic School

Engineering internship report

B.

Getting started with PCB Design

Altium is a vastly complex software design suite. To fulfill a PCB design project, you shall follow this process: Creating a new Schematic Sheet. Drawing the Schematic: Locating the Component and Loading the Libraries Create unfound Components Place the Components on the Schematic Wiring up the Circuit Creating a New PCB Document: Adding a new PCB to the Project Transferring the Design: Updating the PCB Designing the PCB: Setting up the PCB Workspace Defining the Layer Stack and Other Non-electrical Layers in a View Configuration Setting Up New Design Rules

Fig. 21: PCB rules and Constraints editor

Positioning the Components on the PCB Manually Routing the Board Viewing Your Board Design in 3D Mode

Fig. 22: The 3D view rotation sphere

19 | P a g e

Tunisia Polytechnic School

Engineering internship report

Creating and Importing 3D Bodies for Component Footprints Verifying Your Board Design

Fig. 23: Completed board in 3D

C.

The realized PCB

I designed the PCB of the circuit represented in the previous section by the block diagram (Fig. 15). The difficulties I encountered during this work were technical rather than theoretical. I learned many technical tips concerning optimizing the use of components, characteristics of wires in both control and power circuit. Also, I faced many optimization constraints concerning the use of the microcontrollers resources and adapting alimentation to the components characteristics. The main measures I took were: Putting flyback diodes to protect transistors of the control bridge from inductive reverse load. Putting protective capacities to prevent over loading the transistors. Avoiding the use of some annoying forms of tracks. Using wide tracks for the power circuit. Applying to a minimum the transistors. Minimizing the power consumption of the LPC1343 by choosing pins so as it uses only one Timer to generate all PWM signals needed to drive both motors.

The schematic is represented in the appendix.

20 | P a g e

Tunisia Polytechnic School

Engineering internship report

V.

Software

The software of my application is written in C language under LPCXpresso NXP environment. It performs the following main tasks: Read potentiometers for desired speed and orientation Set PWM duty cycles and GPIO outputs.

Fig. 24 shows a flow chart of the main loop.

Fig. 24: Main routine

A.

NXP LPCXpresso development platform

LPCXpresso is a new, low-cost development platform available from NXP. The software consists of an enhanced, Eclipse-based IDE, a GNU C compiler, linker, libraries, and an enhanced GDB debugger. The hardware consists of the LPCXpresso development board which has an LPC-Link debug interface and an NXP LPC ARM-based microcontroller target. LPCXpresso is an end-to-end solution enabling embedded engineers to develop their applications from initial evaluation to final production. The LPCXpresso IDE, powered by Code Red Technologies, is based on the popular Eclipse development platform and includes several LPC-specific enhancements. It is an industry-standard GNU toolchain with an optimized C library that gives engineers all the tools necessary to develop high-quality software solutions quickly and cost-effectively.

21 | P a g e

Tunisia Polytechnic School

Engineering internship report

The LPCXpresso target board, jointly developed by NXP, Code Red Technologies, and Embedded Artists, includes an integrated JTAG debugger (LPC-Link), so there is no need for a separate JTAG debug probe. The target portion of the board can be connected to expansion boards to provide a greater variety of interfaces, and I/O devices. The on-board LPC-Link debugger provides a high-speed USB to JTAG/SWD interface to the IDE and it can be connected to other debug targets such as a customer prototype. Users can also use the LPCXpresso IDE with the Red Probe JTAG adapter from Code Red Technologies.

Fig. 25: LPCXpresso development platform

1. LPCXpresso IDE LPCXpressos IDE is a highly integrated software development environment for NXPs LPC Microcontrollers, which includes all the tools necessary to develop high quality software solutions in a timely and cost effective fashion. LPCXpresso is based on Eclipse with many LPC specific enhancements. It also features the latest version of the industry standard GNU tool chain with a proprietary optimized C library providing professional quality tools at low cost. The LPCXpresso IDE can build an executable file of any size with full code optimization and it supports a download limit of 128 kB after registration. LPCXpresso supports the full embedded product design cycle by moving beyond chip evaluation boards and supporting development on external target boards.

Fig. 26: LPCXpresso IDE

22 | P a g e

Tunisia Polytechnic School

Engineering internship report

2.

LPCXpresso development board

Fig. 27: LPCXpresso development board

The LPCXpresso board contains a JTAG/SWD debugger called the LPC-Link and a target MCU. LPC-Link is equipped with a 10-pin JTAG header (highlighted on the above image) and it is seamlessly connected to the target via USB (the USB interface and other debug features are provided by NXPs ARM9 based LPC3154 MCU). Cutting the tracks between the LPC-link and the target will make the LPC-Link a stand-alone JTAG debugger. This enables the LPCXpresso platform to be connected to an external target and used to develop a wide variety of NXPs Cortex-M0, Cortex-M3, and ARM7/9 based applications. The target includes a small prototyping area and easily accessible connections for expansion. The LPCXpresso board with target can be used: On its own for software development and benchmarking Connected to an off-the-shelf baseboard for rapid proof-of-concepts Connected to customer-designed board for a full prototype

B.

Evaluate, explore and develop

Users can envisage three stages from evaluation to product development. During evaluation, features and peripherals of the target MCU can be easily tested with the prototyping area and easily accessible to the target board. Complementing the target board is also easy-to-use example projects and a useful Getting Started guide. For rapid proof-of-concepts, users can get an off-the-shelf base board from Embedded Artists and quickly explore the next level of applications. And finally LPCXpresso users can seamlessly develop their final application by using the LPC-Links 10-pin JTAG connector to attach any JTAG-capable custom board. This way, users can now enjoy the same user experience right from evaluation to product development.

23 | P a g e

Tunisia Polytechnic School

Engineering internship report

Fig. 28: Product development stages

C.

LPC1343 configuration

As it is seen in the flow chart (fig. 14), three main configurations must be set via configuration registers: GPIO configuration. ADC configuration. Timer configuration.

1. GPIO configuration The I/O configuration registers control the electrical characteristics of the pins. The following characteristics are configurable: pin function internal pull-up/pull-down or Repeater mode function hysteresis analog input or digital mode for pins hosting the ADC inputs I2C mode for pins hosting the I2C-bus function

The IOCON registers control the function (GPIO or peripheral function), the input mode, and the hysteresis of all PIO pins. In addition, the I2C-bus pins can be configured for different I2C-bus modes. If a pin is used as input pin for the ADC, an analog input mode can be selected.

24 | P a g e

Tunisia Polytechnic School

Engineering internship report

Fig. 29: Standard I/O pin configuration

General Purpose Input Output can be configured as input or output by software. Each GPIO register can be up to 12 bits wide and can be read or written using word or half-word operations at word addresses.

Fig. 30: GPIO register overview

As shown in the figure above, the GPIO resister offers many abilities. Two only are needed for my application:

25 | P a g e

Tunisia Polytechnic School Data level (GPIODATA register). Data direction ( GPIODIR).

Engineering internship report

a) GPIO data register The GPIODATA register holds the current state of the pin (HIGH or LOW), independently of whether the pin is configured as a GPIO input or output or as another digital function. If the pin is configured as GPIO output, the current value of the GPIODATA register is driven to the pin.

Fig. 31: GPIO data register

The reading of the GPIODATA register always returns the current logic level (state) of the pin independently of its configuration. Because there is a single data register for both the value of the output driver and the state of the pins input, writing operations have different effects depending on the pins configuration: If a pin is configured as GPIO input, a write to the GPIODATA register has no effect on the pin level. A read returns the current state of the pin. If a pin is configured as GPIO output, the current value of GPIODATA register is driven to the pin. This value can be a result of writing to the GPIODATA register, or it can reflect the previous state of the pin if the pin is switched to GPIO output from GPIO input or another digital function. A read returns the current state of the output latch. If a pin is configured as another digital function (input or output), a write to the GPIODATA register has no effect on the pin level. A read returns the current state of the pin even if it is configured as an output. This means that by reading the GPIODATA register, the digital output or input value of a function other than GPIO on that pin can be observed. b) GPIO data direction

Fig. 32: GPIO data direction register

26 | P a g e

Tunisia Polytechnic School

Engineering internship report

2. ADC configuration: The LPC13xx family includes an 8 channel 10-bit successive approximation Analog-to-Digital Converter (ADC) with a maximum conversion rate of 400 kHz. The ADC is configured using the following registers: Pins: The ADC pin functions are configured in the IOCONFIG register block. Power and peripheral clock: In the SYSAHBCLKCTRL register. Power to the ADC at run-time is controlled through the PDRUNCFG register.

For this application, I used two ADC input linked with PIO0_11 and PIO1_0 pins which support ADC function.

Fig. 33: IOCON_R_PIO0_11 register bit description

Fig. 34: Enable clock for ADC

27 | P a g e

Tunisia Polytechnic School

Engineering internship report

Fig. 35: Power ADC

3. Timer configuration (16-bit Timer) The LPC13xx family includes two 16-bit counter/timers with a programmable 16-bit prescaler that efforts counter or timer operation. These timers are equipped with one 16-bit capture channel that can take a snapshot of the timer value at input signal transitions. A capture event may also optionally generate an interrupt. Also they are matched to Four 16-bit match registers that allow: Continuous operation with optional interrupt generation on match. Stop timer on match with optional interrupt generation. Reset timer on match with optional interrupt generation.

In addition to four 16-bit match registers that allow: Continuous operation with optional interrupt generation on match. Stop timer on match with optional interrupt generation. Reset timer on match with optional interrupt generation.

For each timer, up to four match registers can be configured as PWM allowing the use of up to three match outputs as single edge controlled PWM outputs.

Each Counter/timer is designed to count cycles of the peripheral clock (PCLK) or an externally supplied clock and can optionally generate interrupts or perform other actions at specified timer values based on four match registers. Each counter/timer also includes one capture input to trap the timer value at an input signal transition, optionally generating an interrupt. In PWM mode, three match registers on CT16B0 and two match registers on CT16B1 can be used to provide a single-edge controlled PWM output on the match output pins. It is recommended to use the match registers that are not pinned out to control the PWM cycle length. Rules for single edge controlled PWM outputs: 1. All single edge controlled PWM outputs go LOW at the beginning of each PWM cycle (timer is set to zero) unless their match value is equal to zero. 2. Each PWM output will go HIGH when its match value is reached. If no match occurs (i.e. the match value is greater than the PWM cycle length), the PWM output remains continuously LOW. 3. If a match value larger than the PWM cycle length is written to the match register, and the PWM signal is HIGH already, then the PWM signal will be cleared on the next start of the next PWM cycle. 4. If a match register contains the same value as the timer reset value (the PWM cycle length), then the PWM output will be reset to LOW on the next clock tick. Therefore, the PWM output will always consist of a one clock tick wide positive pulse with a period determined by the PWM cycle length (i.e. the timer reload value).

28 | P a g e

Tunisia Polytechnic School

Engineering internship report

5. If a match register is set to zero, then the PWM output will go to HIGH the first time the timer goes back to zero and will stay HIGH continuously.
Note: When the match outputs are selected to serve as PWM outputs, the timer reset (MRnR) and timer stop (MRnS) bits in the Match Control Register MCR must be set to 0 except for the match register setting the PWM cycle length. For this register, set the MRnR bit to 1 to enable the timer reset when the timer value matches the value of the corresponding match register.

Fig. 36: 16-bit counter/timer block diagram

29 | P a g e

Tunisia Polytechnic School The CT16B0/1 are configured using the following registers:

Engineering internship report

Pins: The CT16B0/1 pins must be configured in the IOCONFIG register block Power and peripheral clock: In the SYSAHBCLKCTRL register, set bit 7 and bit 8

In my application I used the CT16B1 timer linked to PIO1_9 and PIO1_10. This choice has been made to economize the energy consumption. In fact PIO1_9 and PIO1_10 can be outputs for the same counter CT16B1 and consequently this enable to generate both PMW signals useing only one timer.

Fig. 37: Configure PIO1_9 to PWM function

30 | P a g e

Tunisia Polytechnic School

Engineering internship report

Fig. 38: Configure matching registers

31 | P a g e

Tunisia Polytechnic School

Engineering internship report

Conclusion
This training presents my first experience in the electronics engineering of embedded systems. This experience has been very rewarding either in terms of scientific knowledge or professional and technical matters. It gave me the opportunity to study the classes of electric motors (bearing in mind that electrical has never been my option studied). It also allowed me to work on professional microcontroller platforms and software tools. The Internship was considered successful by my supervisor and has a usable result on the company. But for me I see that it would take a lot of work and more research to improve the project.

32 | P a g e

Appendix:

Appendix.1: Schematic document

Appendix.2: Printed circuit board design

II

Appendix.3: Schematic of the joystick III

Bibliography
Documents
AMIR FAIZY. DC MOTOR CONTROL USING CHOPPER. National Institute of Technology Rourkela India. 2010. User Guide: Welcome to the Altium Designer Environment. Altium. 2006. User Guide: Getting started with NXP LPCXpresso. NXP. 2011. User Guides: LPC1311/13/42/43 User manual. NXP. 2011. Internal documents of the enterprise.

Websites
http://www.nxp.com http://en.wikipedia.org

IV