Download as pdf or txt
Download as pdf or txt
You are on page 1of 14

ARM Controller Lab 15EC55P 2020-21

Program 7: DC Motor Direction Control Interface (MC05) with


NV5004A

Pre-requisites required for understanding the program.


Knowledge on

 LPC2148 ARM CPU.


 LPC2148 Peripherals.
 Register Description of GPIO.
 NV5004A ARM 7 Development board kit
 DC motor interface block of MC05.
 DC motor basics.
 Knowledge of Assembly and Embedded C programming language.
Specific objectives:
 To write an embedded c language program Interface DC motor and control its speed.

 To run program on IDE (Integrated Development Environment) keil v4 software to


write program and to download hex file Philips flash utility software is used.

Course outcome:
 To analyze the embedded c programs on interfacing kits.
 Understand the Procedure to execute the DC motor interfacing programs with various speed
of rotation.

 Understands the different ports and GPIO of LPC 2148 ARM Processor.

 Understand the Procedure to execute the dc motor interfacing programs in clockwise


direction and anti-clockwise direction rotation.

Electronics and Communication Engineering


ARM Controller Lab 15EC55P 2020-21

Introduction:
 DC motor converts electrical energy in the form of Direct Current into mechanical energy.
 In case of a motor, the mechanical energy produced is in the form of rotational movement of the
motor shaft.
 The direction of rotation of the shaft of the motor can be reversed by reversing the direction of
Direct Current through the motor.
 The motor can be rotated at a certain speed by applying a fixed voltage to it. If the voltage varies,
the speed of the motor varies.
 Thus, the DC motor speed can be controlled by applying varying DC voltage; whereas the
direction of rotation of the motor can be changed by reversing the direction of current through it.
 For reversing the current, we can make use of H-Bridge circuit or motor driver ICs that employ
the H-Bridge technique or any other mechanisms.

Working of DC Motor:
 The DC motor is the device which converts the direct current into the mechanical work.
 The Fleming left-hand rule gives the direction of the force.
 The direction of the force ie rotation of the motor can be changed by changing the direction
of current.

Pulse Width Modulation (PWM):


Pulse Width Modulation (PWM) is a technique by which width of a pulse is varied while keeping
the frequency constant. A period of a pulse consists of an ON cycle (HIGH) and an OFF cycle
(LOW). The fraction for which the signal is ON over a period is known as duty cycle.

Duty Cycle (In %) = [Ton / Ton + Toff ] x 100

E.g. consider a pulse with a period of 10ms which remains ON (high) for 2ms.The duty cycle of this
pulse will be

D = (2ms / 10ms) x 100 = 20%

Through PWM technique, we can control the power delivered to the load by using ON-OFF signal.
Pulse Width Modulated signals with different duty cycle are shown below.

Electronics and Communication Engineering


ARM Controller Lab 15EC55P 2020-21

 LPC2148 has PWM peripheral through which we can generate multiple PWM signals on
PWM pins. Also, LPC2148 supports two types of controlled PWM outputs as,

Single Edge Controlled PWM Output: Only falling edge position can be controlled.

Double Edge Controlled PWM Output: Both Rising and Falling edge positions can be
controlled.

Electronics and Communication Engineering


ARM Controller Lab 15EC55P 2020-21

Methodology:

 Interface MC05 – DC motor interfacing module to NV5004A ARM 7 development board kit.

 Connection: Connect one 20 pin FRC Cable from port pin P1.16 to P1.23 to the "DC Motor
Interface Block" of MC05.

 Download the hex file from system to ARM board kit and Run the program by click on Reset
button.

 Observe the rotation of DC motor.

 Check the status of port pins on tp7 to tp10 pins.

 Observe the status of Direction control switch on tp10 pins.

 Press Direction control switch and observe the direction of rotation of DC motor.

 Again, check the status of port pins on tp7 to tp10 pins.

 Press PWM control switch and observe the speed of rotation of DC motor.

Electronics and Communication Engineering


ARM Controller Lab 15EC55P 2020-21

Working of some of the instructions used in writing theprogram:


1. IODIR (GPIO Port Direction control register): This is a Legacy APB (ARM Peripheral
Bus) GPIO (General purpose Input Output) register which individually controls the direction
of each port pin.
 IO1DIR: Port 1 Input output direction.

Example: IO1DIR = 0; Port 1 controlled pin is input.


IO1DIR = 1; Port 1 controlled pin is output.
IO1DIR = 0x00070000; Port1 pin P1.16 to P1.18 configured as output and pin P1.20 to P1.23 input

0000 0111

Port 1: P1.23 P1.22 P1.21 P1.20 P1.19 P1.18 P1.17 P1.16

Port1: 0 0 0 0 0 1 1 1
INPUT OUTPUT

1. IOPIN (GPIO Port pin value register): This is a Legacy APB (ARM Peripheral
Bus) GPIO (General purpose Input Output) register which is the current state of
the GPIO configured port pins can always be read from this register, regardless of
pin direction.

 IO1PIN: Port 1 pin current state.

Example: Check bit status of Port 1 pin P1.19 is equal to 0, than speed 100
else speed =200.
if (check_bit(IO1PIN,19) == 0) /* Check if P1.19 is SET */
{
Direction = 0;
Else
Direction = 1;
}

Electronics and Communication Engineering


ARM Controller Lab 15EC55P 2020-21

2. IOSET (GPIO Port Output set register): This is a Legacy APB (ARM Peripheral
Bus) GPIO (General purpose Input Output) register which controls the state of
output pin in conjunction with IOCLR register. Writing One’s produces HIGH at
the corresponding port pins. Writing Zeroes has no effect i.e. it becomes LOW.

 IO1SET: Port 1 output set register.


Example: IO1SET = 1; Port 1 pins are HIGH.

IO1SET = 0; Port 1 pins are LOW.


IO1SET = 0x00030000; Port1 pin P1.16 and P1.17 goes HIGH remaining pins LOW.

0000 0011
Port 1: P1.23 P1.22 P1.21 P1.20 P1.19 P1.18 P1.17 P1.16

Before Execution: 0 0 0 0 0 0 0 0

After Execution: 0 0 0 0 0 0 1 1

 IO1SET: Port 1 output set register.


Example: IO1SET = 1; Port 1 pins are HIGH.
IO1SET = 0; Port 1 pins are LOW.
IO1SET = 0x00050000; Port1 pin P1.16 and P1.18 goes HIGH remaining pins LOW.

0000 0101
Port 1: P1.23 P1.22 P1.21 P1.20 P1.19 P1.18 P1.17 P1.16

Before Execution: 0 0 0 0 0 0 0 0

After Execution: 0 0 0 0 0 1 0 1

Electronics and Communication Engineering


ARM Controller Lab 15EC55P 2020-21

3. IOCLR (GPIO Port Output clear register): This is a Legacy APB


(ARM Peripheral Bus) GPIO (General purpose Input Output) register
which controls the state of output pin. Writing One’s produces LOW
at the corresponding port pins and clears the corresponding bits in the
IOSET register. Writing zeroes has no effect.

 IO1CLR: Port 1 output clear register.

Example: IO1CLR = 1; Port 1 pins are LOW.


IO1CLR= 0x00030000; Port1 pin P1.16 and P1.17 goes LOW.

0000 0011
Port 1: P1.23 P1.22 P1.21 P1.20 P1.19 P1.18 P1.17 P1.16

Before Execution: 0 0 0 0 0 0 1 1

After Execution: 0 0 0 0 0 0 0 0

 IO1CLR: Port 1 output clear register.


Example: IO1CLR = 1; Port 1 pins are HIGH.

IO1CLR= 0x00050000; Port1 pin P1.16 and P1.18 goes LOW.

0000 0101
Port 1: P1.23 P1.22 P1.21 P1.20 P1.19 P1.18 P1.17 P1.16

Before Execution: 0 0 0 0 0 1 0 1

After Execution: 0 0 0 0 0 0 0 0

Electronics and Communication Engineering


ARM Controller Lab 15EC55P 2020-21

2. if else statement: If condition returns true then the statements inside the body of “if”
are executed and the statements inside body of “else” are skipped. If condition returns
false then the statements inside the body of “if” are skipped and the statements in “else”
are executed.
Syntax:
if(condition)
{
// Statements inside body of if
}
else
{
//Statements inside body of else
}

3. While statement: A loop is used for executing a block of statements repeatedly until a
given condition returns false.
Syntax:
while (condition test)
{
//Statements to be executed repeatedly
// Increment (++) or Decrement (--) Operation
}

4. Switch statement: A switch statement allows a variable to be tested for equality


against a list of values. Each value is called a case, and the variable being switched on
is checked for each switch case.
Syntax:
switch (variable or an integer expression)
{
case constant: //C Statements ;
case constant: //C Statements ;
default: //C Statements ;
}

Electronics and Communication Engineering


ARM Controller Lab 15EC55P 2020-21

Components used for Interfacing DC motor:

Electronics and Communication Engineering


ARM Controller Lab 15EC55P 2020-21

Procedure of Interfacing between Computer, ARM7 Kit and MC05 Peripheral:

Connection Setup:
1. Connect RS232 cable to ARM7 kit and CPU serial communication port as show in
above fig.
2. Connect NV5004A Power supply to 230AC voltage supply board and ARM7 Kit board.
3. Connect 20pin FRC cable to ARM7 board of ports P1.16 to P1.23 socket and DC motor
interface module MC05 Ports.
4. There is one switch in ARM7 Kit RUN/ISP mode. During downloading of hex file
switch mode should be ISP (In System Programming) mode. Once downloading is
complete during execution of program switch mode should be in RUN mode and press
on reset button in the ARM7 board.

Procedure:
1. Open Keil V4 software and create a new project with the name of DC Motor, select
NXP tab LPC2148 processor, save project, Click Yes for startup.s file.
2. Write dc motor embedded c code in new file and save file with .c extension and add
this file to project.
3. Run the project, check for errors and warnings. It should be zero errors and zero
warnings.

Electronics and Communication Engineering


ARM Controller Lab 15EC55P 2020-21

4. Go to Target option, right click on it, click on option of target and new window will
appear. Click on Output window there is one checkbox with name Create Hex file, on
this checkbox click it.
5. Build the project, now it will create a hex file in the same folder.
6. Open the Philips flash utility software click on Read device ID. In ARM7 Kit switch
mode should be ISP mode. Here before downloading hex file it will get check
communication between cpu and arm7 kit.
7. Once Read device ID successful than go to browse file and select corresponding
project dcmotor.hex file and click on Upload to Flash.
8. Once the uploading hex file successful than it shows the hex file downloaded
successfully from computer to ARM7 kit.
9. Now ARM7 kit switch mode should be changed to RUN mode and press on Reset
button of ARM7 kit.
10. The dc motor will start rotating either clockwise direction or anticlockwise direction.
11. In MC05 dc motor interface module Direction switch button is provided to change the
rotation either clockwise or anticlockwise.
12. In MC05 dc motor interface module PWM switch button is provided to vary the pulse
width while keeping the frequency constant for speed of dc motor.

Algorithm:
 Start
 Initialize the port1 pin number of P1.16 to P1.18 as output and P1.19 as input ports.
 Declare the variable for direction.
 Write a common delay program of say 500 ms
 Check bit value of P1.19 for direction.
 If direction bit value is 0 than motor rotates in anticlockwise direction.
 If direction bit value is 1 than motor rotates in clockwise direction.
 Anticlockwise direction is
o Set sequence-0x00030000 on the pins IO1SET.
o Call delay function
o Clear sequence-0x00030000 on the pins IO1CLR.
 Clockwise direction is
o Set sequence-0x00050000 on the pins IO1SET.
o Call delay function
o Clear sequence-0x00050000 on the pins IO1CLR.
 End.

Electronics and Communication Engineering


ARM Controller Lab 15EC55P 2020-21

Flow Chart:

Start

Initialize Port pins as input


and output

Declare the variable for


direction

Check port P1.19 value for


direction

Check port bit


P1.19 for True or Yes(1)
Direction

False or No(0)
Anticlockwise. Anticlockwise.
Set Seqence: 0x00030000 Set Seqence: 0x00050000
Call delay Call delay
Clear Sequence : 0x00030000 Clear Sequence : 0x00050000

End

Electronics and Communication Engineering


ARM Controller Lab 15EC55P 2020-21

 Embedded C LanguageProgram:

/******************************************************************************
* FileName: Main.c
* Processor: LPC2148
* Complier: Keil IDE

*******************************************************************************
* File Description: DC Motor Direction Control Interface (MC05) with NV5004A
*Connection: Connect one 20 pin FRC Cable from port pin P1.16 to P1.23 to the "DC Motor
Interface Block" of MC05.
* Connect a patch cord to +12V DC from external source to MC05.
*******************************************************************************/
#include <LPC214x.H>
/*******************************************************************************
* Delay
* Description : This function provide Delay in Mili Sec.
********************************************************************************/
void MSdelay(unsigned int rTime)
{
unsigned int i,j;
for(i=0;i<=rTime;i++)
for(j=0;j<1275;j++);
}

/*********************************
Main:Description : This function used to interface
****************************************************/

void main (void)


{
unsigned char Direction;
IO1DIR = 0x00070000; /* Define Port1 pin P1.16 to P1.18 as output & P1.19 as input */
IO1SET = 0x00000000; /* Starting phase value (1100) */
Direction = 0;

while (1)
{
if ( (IO1PIN & 1<<19) == 0) /* Check if P1.19 is SET */
{

if (Direction == 0)
Direction++;
else if (Direction == 1)
Direction--;

Electronics and Communication Engineering


ARM Controller Lab 15EC55P 2020-21

Switch (Direction) /******* Switch case loop ********/


{
case 0: /************ case 0 - Anti-clockwise*************/

IO1SET = 0x00030000;
MSdelay (500);
IO1CLR = 0x00030000;

break;

case 1: /************** case 1 - Clockwise************/

IO1SET = 0x00050000;
MSdelay(500);
IO1CLR = 0x00050000;

break;

}
}
}
/***********************************END**************************************/
Output:

* Observe the rotation of DC motor.


* Check the status of port pins on tp7 to tp10 pins.
* Observe the status of Direction control switch on tp10 pins.
* Press Direction control switch and observe the direction of rotation of DC motor.
* Again check the status of port pins on tp7 to tp10 pins.
*********************************************************************/

Applications or where it is useful?


 Air compressor
 Lifts
 Elevators
 Wiper
 Automatic windscreen
 Drills
 Conveyors
 Fans
 Automobiles as a starter motor
 Personal computer disc drives
 Toys
 Wheelchairs
 Etc

Electronics and Communication Engineering

You might also like