PM Stepper Motor Control System by Pic - Ng Wai Liang - QA76.5.N48 2006

28
PM STEPPER MOTOR CONTROL SYSTEM BY PIC NG WAI LUNG B020210018 KOLEJ UNIVERSITI TEKNIKAL KEBANGSAAN MALAYSIA

Transcript of PM Stepper Motor Control System by Pic - Ng Wai Liang - QA76.5.N48 2006

Page 1: PM Stepper Motor Control System by Pic - Ng Wai Liang - QA76.5.N48 2006

PM STEPPER MOTOR CONTROL SYSTEM BY PIC

NG WAI LUNG

B020210018

KOLEJ UNIVERSITI TEKNIKAL KEBANGSAAN MALAYSIA

Page 2: PM Stepper Motor Control System by Pic - Ng Wai Liang - QA76.5.N48 2006

ABSTRAK

Projek ini mempersembahkan sebuah rekaan pengawal motor pelangkah yang

menggunakan pengawal mkro untuk mengawal segala pergerakkannya seperti putaran

dan kelajuan. Projek ini akhirnya berupaya dikawal oleh sistem konputer, alat pengesan

dan butang yang sebagai medan pengawal motor pelangkah tersebut. Kegunaan utama

motor pelangkah adalah seperti pemacu cakera, pencetak, robot, peralatan mesin,

pemain cakera padat dan sebagainya. Demi mencapai h g s i berikut, biasanya sistem

memerlukan satu pengawal mikro untuk menghasilkan denyutan digital menggerakkan

motor pelangkah dan menjana kkuensi menentu kelajuan putaran motor. Pada masa

lani, terdapat banyak jenis tangan robot yang memakai motor pelangkah sebagai

pergerakkanya disebabkan kejituannya untuk mencapai satu keductukan adalah tepat

sekali. Selain daripada itu, motor pelangkah juga banyak digunakan dalam industri

sebagai pengangkut kerana harga untuk satu motor pelangkah yang lebih murah.

Page 3: PM Stepper Motor Control System by Pic - Ng Wai Liang - QA76.5.N48 2006

ABSTRACT

This project represents the design and implementation of a stepper motor control system

that is conceive to using a microcontroller - Microchip, Peripheral Interface Controller

(PIC16F84A) to manipulated the operation of the motor such as speed and rotation and

lastly it will be able to control the operation through the computer, manual and sensor.

Preliminary application stepper motor is for disc drivers, printers, robots, machine tools,

CD players, plotters and so on. To achieve this, basically the system needs a

microcontroller to generate digital signal or pulse to move the stepper motor. The

velocity of the motor is depended with the period of the signal generated. Nowadays,

many kinds of robot arm are applying stepper motor as its movement motor because it

can make high accuracy to reach a position. Besides, the stepper motor also applied in

many industries area to use as conveyor because the stepper motor is the cheapest.

Page 4: PM Stepper Motor Control System by Pic - Ng Wai Liang - QA76.5.N48 2006

INTRODUCTION

1.1 An Overview

The Stepper Motor is an electromagnetic device that converts digital pulses into

mechanical shaft rotation. Advantages of stepper motors are low cost, high reliability,

high torque at low speeds and a simple, rugged construction that operates in almost any

environment. The main disadvantages in using a step motor is the resonance effect often

exhibited at low speeds and decreasing torque with increasing speed.

There are many lund of stepper motors in the market such as Unipolar type,

Bipolar type, Single-phase type, Multi-phase type and etc. On this project it was used the

2-phase Unipolar PM type stepper motor. The controller is a microprocessor based and

capable of generating step pulses as direction signals for the driver. In addition, the

controller is typically required to perform many other sophisticated command functions

such like rotational control and the speed control- The driver responsible converts the

indexer command signals into the power necessary to energize the motor windngs.

There are numerous types of drivers with different currenthmperage ratings and

construction technology. Not all drivers are suitable to run all motors, so when designing

Page 5: PM Stepper Motor Control System by Pic - Ng Wai Liang - QA76.5.N48 2006

a Stepper Motor Controller the dnver selection process is critical. Below had list up

some of the controller whch describes its specification and price according to Farnell

catalog 2005'06.

Image

Description

.- .

Brand Manufacturer

Part #

CONTROLLER, STEPPER 0.5A

STEPPER 4 OPTION

Current, RMS max: 3A

Depth, external: 83mm Length l Height,

external: 43mm Voltage, output

max: 36V dc

SAIA-BURGESS

SE2

Voltage, output min: 24V dc

Voltage, supply: 5V dc Width, external:

SANYO DENKI PMM-MD-2322 1 -

10 CONTROLLER,

Price Per 1 RM176.83 1 RM1,132.21 Unit #

I MCLENNAN

MSES70 EVO 2

CONTROLLER, STEPPER 3A Length l Height,

external: 1 OOmm Voltage, supply

max:42V Voltage, supply

min: 1 SV Width, external:60mm Length, overall: 160mm Output current per phase

(max):3.5A Output current per phase

(min):O.SA Output current ranges: 1

- 3 Amps Power, output: 12 W

Page 6: PM Stepper Motor Control System by Pic - Ng Wai Liang - QA76.5.N48 2006

I !

Image

I I I

I CONTROLLER, I DRIVE, 1.5A 1

Brand Manufacturer

Part #

Description

ASTROSYN / UNBRANDED I UNBRANDED

STEPPER 2A Current, output

max: 2A Depth, external:

160mm Frequency,

clock max: 30kHz Length 1 Height,

external: 17mm Voltage, supply

max: 30V Voltage, supply

min: 15V Width, external:

1 OOmm

XPVP 34

Current, full load: 1.5A Current, output

max: 1.5A Depth, external:

150mm Length 1 Height,

external: 3 5 m Voltage, output

max: 40V dc Voltage, output

min: 250mA @ 12V dc

Voltage, supply: 250V

GSM4+PSU2

STEPPER MOTOR DRIVE, 5A

Current, 1oad:SA Current, output

max: 250mA Depth, external:2 1 O m Length 1 Height,

external: 75mm Voltage, output

max:80V dc Voltage, output min: 12V dc

Voltage, supply:25OV Width, external: lOOm

GSM5+PSU5

Figure 1.1 : Farnell Catalog 2005106

Price Per Unit #

RM225.64

Width, external: l00mm

RM1,695.56 RM2,811.51

Page 7: PM Stepper Motor Control System by Pic - Ng Wai Liang - QA76.5.N48 2006

1.2 Objective

The objective of this project is to design an electronic controller to control 2-

phase Unipolar PM type stepper motor. The peripheral integrated circuit (PICl6F84A)

was used as a microprocessor to generated step pulses for the stepper motor. In general,

the speed and rotational of the stepper motor is depend to the step pulses character.

Therefore, the controller will be able to manipulate the speed and rotational of the motor.

Lastly, it includes the computer I/O port, manual and sensor connection part to let the

user control the stepper motor by easily. For this entire project, it concerned to the low

cost in manufixture and maximizes the best performance.

1.3 Scope of Work

In this project had include consideration to the selection of stepper motor

because different &meter of each stepper motor will needed different voltage to charge

the coil. Inside the controller had prepared several rotation control part, such as by

manual, digital and sensor to let the user easy to control the rotational of the stepper

motor based on their prefer. For the digital part, a parallel port was connects between the

controller and computer and it applied software were design by Visual Basic display at

the screen to allow user control the stepper motor. The programming for the PIC was

write in assembly language by MPLab and convert to hex code and them it was program

into the PIC by JDM programmer.

Page 8: PM Stepper Motor Control System by Pic - Ng Wai Liang - QA76.5.N48 2006

CHAPTER I1

LITERATURE STUDIES

2.1 Stepper Motor

In this chapter will give a brief review about the characteristic of the PM Stepper

Motor, functional of the Mcrocontroller and implementation of the PC interfacing to a

microcontroller. This is because all of that are needed to apply into the project. Initially,

because of this project at last is attended to the operation of the Stepper Motor, so it is

important to comprehend the motor specification in detail.

2.1.1 Introduction

Motion Control, in electronic terms, means to accurately control the movement of

an object based on speed, distance, load, inertia or a combination of all these factors.

There are numerous types of motion control systems, including; Stepper Motor, Linear

Step Motor, DC Brush, Brushless, Servo, Brushless Servo and more.

Page 9: PM Stepper Motor Control System by Pic - Ng Wai Liang - QA76.5.N48 2006

In Theory, a Stepper motor is a marvel in simplicity. It has no brushes, or contacts.

Basically it's a synchronous motor with the magnetic field electronically switched to

rotate the armature magnet around. A Stepping Motor System consists of three basic

elements, ofien combined with some type of user interface (Host Computer, PLC or

Dumb Terminal):

1. The Indexer (or Controller) is a microprocessor capable of generating step pulses

and direction signals for the driver. In addition, the indexer is typically required

to perform many other sophisticated command functions.

2. The Driver (or Amplifier) converts the indexer command signals into the power

necessary to energize the motor windings. There are numerous types of drivers,

with different current~mperage ratings and construction technology. Not all

drivers are suitable to run all motors, so when designing a Motion Control

System the driver selection process is critical.

3. The Step Motor is an electromagnetic device that converts hgital pulses into

mechanical shaft rotation.

The maximum speed of a stepper motor was determined by how long the voltage

charges the coil.

Page 10: PM Stepper Motor Control System by Pic - Ng Wai Liang - QA76.5.N48 2006

2.1.2 Operation Principle

- . . Stator

Figure 2.1: Four poles of PM stepper motor

In the PM type stepper motor, a permanent magnet is used for rotor and mils are

put on stator. The stepper motor model which has 4-poles is shown in the Figure 2.1

above. In case of this motor, step angle of the rotor is 90 degrees.

As for four poles, the top and the bottom and either side are a pair. x coil, 'il coil

and u coil, Vcoil correspond respectively. For example, Y coil and Vcoil are put to the

upper and lower pole. Y coil and Vcoil are rolled up for the direction of the pole to

become opposite when applying an electric current to the Y coil and applying an electric

current to the V coil. It is similar about x andK, too.

The turn of the motor is controlled by the electric current which pours into x , K, Y and V. The rotor rotational speed and the direction of the turn can be controlled by this

control.

Page 11: PM Stepper Motor Control System by Pic - Ng Wai Liang - QA76.5.N48 2006

Figure 2.2: Clockwise

"0" means grounding.

control

"0" means grounding.

Figure 2.3 : Counter clockwise controls

Page 12: PM Stepper Motor Control System by Pic - Ng Wai Liang - QA76.5.N48 2006

The motor whch was used this time is 48 steps and the step angle is 7.5 degrees.

The way of controlling is the same as Figure 2.2 and Figure 2.3. It operates when

controlling the electric current of x coil, )T coil, v coil and V coil. The case of the

clockwise control is shown below. The combination of x , Ti, v and V repeats four

patterns.

TabIe 2.4: Case of the c l o c h s e control

Page 13: PM Stepper Motor Control System by Pic - Ng Wai Liang - QA76.5.N48 2006

2.13 Application

Stepper motors can be found almost everywhere. Most of us use them everyday

without even realizing it. For instance, steppers power "analog" wristwatches (whch are

actually digital), disc drives, printers, robots, cash points, machine tools, CD players,

profile cutters, plotters and so on. Unlike other electric motors they do not simply rotate

smoothly when switched on. Every revolution is divided into a number of steps

(typically 200) and the motor must be sent a separate signal for each step. It can only

take one step at a time and each step is the same size, thus step motors may be

considered a digtal device. See the next page for more applications:

Page 14: PM Stepper Motor Control System by Pic - Ng Wai Liang - QA76.5.N48 2006

X-Y TABLE CONgTANT FLOW PUMP

PRINTER PHOTO MBE2BETTIE1Q

Page 15: PM Stepper Motor Control System by Pic - Ng Wai Liang - QA76.5.N48 2006

PROJECTOR W1RE CVTTER

INOEX TABLE

Figure 2.5: Sample applications stepper motor

Page 16: PM Stepper Motor Control System by Pic - Ng Wai Liang - QA76.5.N48 2006

2.2 Microcontroller

The mainly function of microcontroller was used to generated a step pulse signal

to operate the Stepper Motor which either in clockwise or counterclockwise rotation.

And also the speed of the motor can controlled by increased or decreased the period

generated the step signal by microcontroller.

2.2.1 Introduction

A microcontroller is a computer-on-a-chip optimized to control electronic

devices. It is a type of microprocessor emphasizing self-sufficiency and cost-

effectiveness, in contrast to a general-purpose microprocessor, the kind used in a PC. A

typical microcontroller contains all the memory and I/O interfaces needed, whereas a

general purpose microprocessor requires additional chips to provide these necessary

functions.

Microcontrollers are a component in many kinds of electronic equipment. They

are the vast majority of all processor chips sold. Over 50% are "simple" controllers, and

another 20% are more specialized digital signal processors (DSPs). They can be found

in almost any electrical device, washing machines, microwave ovens, telephones etc.

Most microcontrollers today are based on the von Neumann architecture, which

clearly defined the four basic components required for an embedded system. These

include a CPU core, memory for the program (ROM or Flash memory), memory for data

(RAM), one or more timers (customizable ones and watchdog timers), as well as 110

lines to communicate with external peripherals and complementary resources - all this

in a single integrated circuit. A microcontroller differs from a general-purpose CPU chip

in that the former generally is quite easy to make into a working computer, with a

Page 17: PM Stepper Motor Control System by Pic - Ng Wai Liang - QA76.5.N48 2006

minimum of external support chps. The idea is that the microcontroller will be placed in

the device to control, hooked up to power and any information it needs, and that's that.

For instance, a typical microcontroller will have a b d t in clock generator and a

small amount of RAM and ROM (or EPROM or EEPROM), meaning that to make it

work, all that is needed is some control software and a timing crystal. Microcontrollers

will also usually have a variety of input/output devices, such as analog-to-digtal

converters, timers, UARTs or specialized serial communications interfaces like IT,

Serial Peripheral Intedace and Controller Area Network. Often these integrated devices

can be controlled by specialized processor instructions.

Originally, microcontrollers were only programmed in assembly language, or

later in C code. More recently, however, some microcontrollers have begun to include a

built-in high-level programming language interpreter for greater ease of use. BASIC is a

common choice, and is used in the popular BASIC Stamp MCUs.

Microcontrollers trade away speed and flexibility to gain ease of equipment

design and low cost. There's only so much room on the chip to include functionality, so

for every UO device or memory increase the microcontroller includes, some other

circuitry has to be removed.

2.2.2 Specification of Microcontroller

The microcontroller used in this project is PIC16F84 manufactured by Microchip.

Selection of PICl6F84 is because it's easy to get a programmer, common, cheapest and

many examples using this PIC.

Page 18: PM Stepper Motor Control System by Pic - Ng Wai Liang - QA76.5.N48 2006

2.2.2.1 Introduction of Microchip PIC16F84A

PIC16F83 belongs to a class of 8-bit microcontrollers of RISC architecture. Its

general structure is shown on the following map representing basic blocks. Program

memory (FLASH)- for storing a written program. Since memorymade in FLASH

technology can be programmed and cleared more than once, it makes this

microcontroller suitable for device development. EEPROM - data memory that needs to

be saved when there is no supply. It is usually used for storing important data that must

not be lost if power supply suddenly stops. For instance, one such data is an assigned

temperature in temperature regulators. If during a loss of power supply ths data was lost,

we would have to make the adjustment once again upon return of supply. Thus our

device looses on self-reliance. RAM - data memory used by a program during its

execution. In RAM are stored all inter-results or temporary data during run-time.

PORTA and PORTB are physical connections between the microcontroller and the

outside world Port A has five, and port B has eight pins. FREE-RUN TIMER is an &bit

register inside a microcontroller that works independently of the program. On every

fourth clock of the oscillator it increments its value until it reaches the m a x i m (255),

and then it starts counting over again from zero. As we know the exact timing between

each two increments of the timer contents, timer can be used for measuring time which

is very useful with some devices. CENTRAL PROCESSING UNIT has a role of

connective element between other blocks in the microcontroller. It coordinates the work

of other blocks and executes the user program.

Page 19: PM Stepper Motor Control System by Pic - Ng Wai Liang - QA76.5.N48 2006

EEPROM FLASH

PIC1 6F84 outline

Figure 2.6: Block Diagram of PIC 16F84

2.2.2.2 Applications

PIC16F84 perf i ly fits many uses, fiom automotive industries and controlling

home appliances to industrial instruments, remote sensors, electrical door locks and

safety devices. It is also ideal for smart cards as well as for battery supplied devices

because of its low consumption.

EEPROM memory makes it easier to apply microcontrollers to devices where

permanent storage of various parameters is needed (codes for transmitters, motor speed,

receiver frequencies, etc.). Low cost, low consumption, easy handling and flexibility

make PIC16F84 applicable even in areas where microcontrollers had not previously

been considered (example: timer functions, interface replacement in larger systems,

coprocessor applications, etc.).

Page 20: PM Stepper Motor Control System by Pic - Ng Wai Liang - QA76.5.N48 2006

In System Programmability of this chip (along with using only two pins in data

transfer) makes possible the flexibility of a product, after assembling and testing have

been completed. This capability can be used to create assembly-line production, to store

calibration data available only after f m l testing, or it can be used to improve programs

on finished products.

2.2.2.3 Pin Description

PIC16F84 has a total of 18 pins. It is most frequently found in a DIP1 8 type of

case but can also be found in SMD case which is smaller from a DIP. DIP is an

abbreviation for Dual In Package. SMD is an abbreviation for Surface Mount Devices

suggesting that holes for pins to go through when mounting aren't necessary in soldering

this type of a component.

Figure 2.7: Pins description of PIC16F84

Page 21: PM Stepper Motor Control System by Pic - Ng Wai Liang - QA76.5.N48 2006

Pins on PIC16F84 microcontroller have the following meaning:

Pin no. 1

Pin n0.2

Pin no. 3

Pin no.4

Pin no.5

Pin no.6

Pin no.7

Pin no.8

Pin no.9

Pin no. 10

Pin no.11

Pin no. 12

Pin no. 13

Pin no. 14

Pin no.15

Pin no. 16

Pin no.17

Pin no.18

RA2 Second pin on port A. has no additional function.

RA3 Tbrd pin on port A. has no adhtional function.

RA4 Fourth pin on port A. TOCKl whch functions as a timer, is also

found on ths pin.

MCLR Reset input and Vpp programming voltage of a microcontroller.

Vss Ground of power supply.

RBO Zero pin on port B. Interrupt input is an additional function.

RB1 First pin on port B. No additional function.

RB2 Second pin on port B. No additional function.

RE33 Third pin on port B. No additional function.

FU34 Fourth pin on port B. No additional hct ion.

RE35 Fifth pin on port B. No additional function.

RB6 Sixth pin on port B. 'Clock' line in program mode.

RE37 Seventh pin on port B. Data' line in program mode.

Vdd Positive power supply pole.

OSC2 Pin assigned for connecting with an oscillator.

OSC 1 Pin assigned for connecting with an oscillator.

RA2 Second pin on port A. No additional function.

RAl First pin on port A. No additional function.

2.2.2.4 Types of Oscillators

PIC16F84 can work with four different configurations of an oscillator. Since

configurations with crystal oscillator and resistor-capacitor (RC) are the ones that are

used most frequently, these are the only ones we will mention here. Microcontroller type

with a crystal oscillator has in its designation XT, and a microcontroller with resistor-

Page 22: PM Stepper Motor Control System by Pic - Ng Wai Liang - QA76.5.N48 2006

capacitor pair has a designation RC. This is important because you need to mention the

type of oscillator when buying a microcontroller.

A) XT Oscillator

Crystal oscillator is kept in metal housing with two pins where you have written

down the frequency at whch crystal oscillates. One ceramic capacitor of 30pF whose

other end is connected to the ground needs to be connected with each pin.

Oscillator and capacitors can be packed in joint case with three pins. Such element is

called ceramic resonator and is represented in charts like the one below. A center pin of

the element is the ground, while end pins are connected with OSC 1 and OSC2 pins on

the microcontroller. When designing a device, the rule is to place an oscillator nearer a

microcontroller, so as to avoid any interference on lines on which microcontroller is

receiving a clock.

Connecting the oscillator

F i m e 2.8:

B) RC Oscillator

Connecting resonator to microcontroller

IJI applications where great time precision is not necessary, RC oscillator offers

additional savings during purchase. Resonant frequency of RC oscillator depends on

supply voltage rate, resistance R, capacity C and working temperature. It should be

Page 23: PM Stepper Motor Control System by Pic - Ng Wai Liang - QA76.5.N48 2006

mentioned here that resonant fkquency is also influenced by normal variations in

process Fameters, by tolerance of external R and C components, etc.

Figure 2.10: Connection RC Oscillator

V D D

Above diagram shows how RC oscillator is connected with PIC16F84. With

value of resistor R being below 2.2k, oscillator can become unstable, or it can even stop

the oscillation. With very high value of R (ex.lM) oscillator becomes very sensitive to

noise and humidity. It is recommended that value of resistor R should be between 3 and

100k. Even though oscillator will work without an external capacitor (C=OpF), capacitor

above 20pF should still be used for noise and stability. No matter which oscillator is

being used, in order to get a clock that microcontroller works upon, a clock of the

oscillator must be divided by 4. Oscillator clock divided by 4 can also be obtained on

OSC2/CLKOUT pin, and can be used for testing or synchronizing other logical circuits.

Clrrd-94 -

2.2.2.5 Reset

. Clodc

PIC16F84

QSC21CLKOUT

Reset is used for putting the microcontroller into a 'known' condition. That

practically means that microcontroller can behave rather inaccurately under certain

undesirable conditions. In order to continue its proper functioning it has to be reset,

meaning all registers would be placed in a starting position. Reset is not only used when

microcontroller doesn't behave the way we want it to, but can also be used when trying

Page 24: PM Stepper Motor Control System by Pic - Ng Wai Liang - QA76.5.N48 2006

out a device as an ink+ in program execution, or to get a microcontroller ready when

loading a program.

In order to prevent from bringing a logical zero to MCLR pin accidentally (line

above it means that reset is activated by a logical zero), MCLR has to be comected via

resistor to the positive supply pole. Resistor should be between 5 and 10K. This kind of

resistor, whose function is to keep a certain line on a logcal one as a preventive, is

called a pull up.

- PIC us 16W

the internal reset circuit

Figure 2.1 1

Microcontroller PIC 16F84 knows several sources of resets:

a) Reset during power on, POR (Power-On Reset)

b) Reset during regular work by bringmg logical zero to MCLR microcontroller's pin.

c) Reset during SLEEP regime

d) Reset at watchdog timer (WDT) overflow

e) Reset during at WDT overflow during SLEEP work regime.

The most important reset sources are a) and b). The first one occurs each time a

power supply is brought to the microcontroller and serves to bring all registers to a

starting position initial state. The second one is a product of purposeful bringing in of a

logical zero to MCLR pin during normal operation of the microcontroller. This second

one is often used in program development.

Page 25: PM Stepper Motor Control System by Pic - Ng Wai Liang - QA76.5.N48 2006

During a reset, RAM memory locations are not being reset. They are unknown

during a power up and are not changed at any reset. Unlike these, SFR registers are reset

to a starting position initial state. One of the most important effects of a reset is setting a

program counter (PC) to zero (0000h) , which enables the program to start executing

fiom the first written instruction.

23.2.6 Central Processing Unit

Central processing unit (CPU) is the brain of a microcontroller. That part is

responsible for finding and fetching the right instruction which needs to be executed, for

decoding that instruction, and finally for its execution.

Central processing unit connects d l parts of the microcontroller into one whole.

Surely, its most important function is to decode program instructions. When programmer

writes a program, instructions have a clear form like MOVLW 0x20. However, in order

for a microcontroller to understand that, this 'letter' form of an instruction must be

translated into a series of zeros and ones which is called an 'opcode'. This transition fiom

a letter to binary form is done by translators such as assembler translator (also known as

an assembler). Instruction thus fetched fiom program memory must be decoded by a

central processing unit. We can then select fiom the table of all the instructions a set of

actions which execute a assigned task defined by instruction. As instructions may w i h

themselves contain assignments which require different transfers of data fiom one

memory into another, fiom memory onto ports, or some other cdculations, CPU must be

connected with all parts of the microcontroller. This is made possible through a data bus

and an address bus.

Arithmetic logic unit is responsible for performing operations of adding,

subtracting, moving (left or right w i t h a register) and logic operations. Moving data

Page 26: PM Stepper Motor Control System by Pic - Ng Wai Liang - QA76.5.N48 2006

inside a register is also known as 'shifting'. PIC16F84 contains arn 8-bit arithmetic logic

~t and 8-bit work registers.

In instructions with two operands, ordinarily one operand is in work register (W

register), and the other is one of the registers or a constant. By operand we mean the

contents on which some operation is being done, and a register is any one of the GPR or

SFR registers. GPR is an abbreviation for 'General Purposes Registers', and SFR for

'Special Function Registers'. In instructions with one operand, an operand is either W

register or one of the registers. As an addition in doing operations in arithmetic and logic,

ALU controls status bits (bits found in STATUS regster). Exechon of some

instructions affects status bits, whch depends on the result itself. Depending on whch

instruction is being executed, ALU can affect values of Carry (C), Digit Carry PC), and

Zero (Z) bits in STATUS register.

2.2.2.7 STATUS Register

W - 0 RNV-D RAW4 R W - 1 R W - 1 RNV-x RAW-r RAW-x

R = Readable bi W = W i bit

U=LlnierRedM,readas'OO -n=Vakatpo\wer-orire@

Figure 2.12: Status Registers

IRP

9 bit 7 IRP megister Bank Select bit)

Bit whose role is to be an eighth bit for purposes of indirect addressing the internal

RAM.

1 =bank2 and3

0 = bank 0 and 1 (from OOh to FFh)

- 7 TO PD RPI R W Z DC C

Page 27: PM Stepper Motor Control System by Pic - Ng Wai Liang - QA76.5.N48 2006

bits 6:5 RP1 :RPO (Register Bank Select bits)

These two bits are upper part of the address for direct addressing. As instructions

which address the memory directly have only seven bits, they need one more bit in

order to address all 256 bytes whch is how many bytes PIC16F84 has. RP1 bit is

not used, but is left for some future expansions of this microcontroller.

01 = first bank

00 = zero bank

'r bit 4 TO Time-out ; Watchdog overflow.

Bit is set after turning on the supply and execution of CLRWDT and SLEEP

instructions. Bit is reset when watchdog gets to the end signaling that overflow took

place.

1 = overflow did not occur

0 = overflow d d occur

9 bit 3 PD (Powerdown bit)

Ths bit is set whenever power supply is brought to a microcontroller : as it starts

running, after each regular reset and after execution of instruction CLRWDT.

Instruction SLEEP resets it when microcontroller falls into low consumpbon mode.

Its repeated setting is possible via reset or by turning the supply omon . Setting can

be triggered also by a signal on RBOmFT pin, change on RB port, upon writing to

internal DATA EEPROM, and by a Watchdog.

1 = after supply has been turned on

0 = executing SLEEP instruction

9 bit 2 Z (Zero bit) In&cation of a zero result

This bit is set when the result of an executed arithmetic or logic operation is zero.

1 = result equals zero

0 = result does not equal zero

Page 28: PM Stepper Motor Control System by Pic - Ng Wai Liang - QA76.5.N48 2006

p bit 1 DC (Digrt Carry) DC Transfer

Bit affected by operations of addition, subtraction. Unlike C bit, this bit represents

transfer fiom the fourth resulting place. It is set in case of subtracting smaller from

greater number and is reset in the other case.

1 = transfer occurred on the fourth bit according to the order of the result

0 = transfer did not occur

DC bit is affected by ADDWF, ADDLW, SUBLW, SUBWF instructions.

p bit 0 C (Carry) Transfer

Bit that is affected by operations of addtion, subtraction and shifting.

1 = transfer occurred fiom the highest resulting bit

0 = transfer did not occur

C bit is affected by ADDWF, ADDLW, SUBLW, SUBWF instructions.

2.2.2.8 Ports

All port pins can be designated as input or output, according to the needs of a

device that's being developed. In order to define a pin as input or output pin, the right

combination of zeros and ones must be written in TRIS register. If the appropriate bit of

TRIS register contains logical "1 ", then that pin is an input pin, and if the opposite is true,

it's an output pin. Every port has its proper TRIS register. Thus, port A has TRISA, and

port B has TRISB. Pin direction can be changed during the course of work which is

particularly fitting for one-line communication where data flow constantly changes

direction. PORTA and PORTB state registers are located in bank 0, whle TRISA and

TRISB pin direction regsters are located in bank 1.