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

Department of Collegiate and Technical Education

ARM CONTROLLER LAB


PART-B , PROGRAM-7

ARM CONTROLLER LAB (5TH SEM)


ELECTRONICS AND COMMUNICATION

Electronics and Communication Engineering 15EC55P


PROGRAM 7:
Write a Embedded C program to Interface
DC Motor Direction Control Interface
(MC05) with NV5004A

Electronics and Communication Engineering 15EC55P


Table of Content
• Pre-requisites required for understanding the program
• Specific objectives
• Course outcome
• Introduction to dc motor
• Methodology
• Components used for Interfacing dc motor
• Procedure of Interfacing program
• Algorithm and flow chart
• DC motor embedded c language program
• Assessment
• Activity
Electronics and Communication Engineering 15EC55P
Pre-requisites required for understanding the
program.
• LPC2148 ARM CPU and 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
Electronics and Communication Engineering 15EC55P
Specific objectives:
• To write an embedded c language program Interface dc motor and
control its speed and direction
• To run program on IDE (Integrated Development
Environment) Keil and Philips flash utility.

Electronics and Communication Engineering 15EC55P


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 using pwm.
• Understand the Procedure to execute the dc motor interfacing
programs in clockwise direction and anti-clockwise direction
rotation.
• Understands the different ports and GPIO of LPC 2148 ARM
Processor
Introduction to DC motor
• The DC motor is the device which converts the direct
current into the mechanical work.
• It works on the principle of Lorentz Law.
• The Fleming left-hand rule gives the direction of the force.
• The direction of rotation of the shaft of the motor can be
reversed by reversing the direction of Direct Current
through the motor.
• The DC motor speed can be controlled by applying varying
DC voltage
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).
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%
•LPC2148 has PWM peripheral through which we can generate
multiple PWM signals on PWM pins.

•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
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.

Electronics and Communication Engineering 15EC55P


• Check the status of port pins on tp7 to tp11

• Observe the status of Direction control switch on tp10


pins.

• Press Direction control switch and observe the direction


of rotation of DC motor.

• Press PWM control switch and observe the speed of


rotation of DC motor
Working of some of the instructions used in writing
the program
• IODIR (GPIO Port Direction control register):
• which individually controls the direction of each port pin.
• IO1DIR: Port 1 Input output direction.
• Example: IO1DIR = 0; Port 1 controlled pins are input.
IO1DIR = 1; Port 1 controlled pins are output.
• IO0DIR = 0x00070000; Port1 pin P1.16 to P1.18 as output
0000 0111
P1.23 P1.22 P1.21 P1.20 P1.19 P1.18 P1.17 P1.16
• PORT1
INPUT OUTPUT

Electronics and Communication Engineering 15EC55P


• IOSET (GPIO Port output Set 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
0000 0011
• PORT1 P1.23 P1.22 P1.21 P1.20 P1.19 P1.18 P1.17 P1.16

Before Execution After Execution


0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1
• IOCLR (GPIO Port output Clear register):
• 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
PORT1 : P1.23 P1.22 P1.21 P1.20 P1.19 P1.18 P1.17 P1.16
• Before Execution After Execution
• 0110 0 0 0 0 1 1 0 0 0 0 0 0 0 0
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.
Syntax: if(condition)
{
// Statements inside body of if }
else
{
//Statements inside body of else
}
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
}
Switch statement: A switch statement allows a variable to
be tested for equality against a list of values
Syntax:
switch (variable or an integer expression)
{
case constant: //C Statements ;
default: //C Statements ;
}
Components used for Interfacing DC motor
DC motor interface connection setup
Connection Setup:
• Connect RS232 cable to ARM7 kit and CPU serial
communication port .

• Connect NV5004A Power supply to 230AC voltage supply


board and ARM7 Kit.

• Connect 20pin FRC cable to ARM7 board of ports P1.16 to


P1.23 socket and DC motor interface module MC05 Ports.
Procedure
• 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.
• Write dc motor embedded c code in new file and save file
with .c extension and add this file to project.
• Run the project, check for errors and warnings. It should be
zero errors and zero warnings.
• 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.
• Build the project, now it will create a hex file in the same
folder.
• In ARM7 kit make switch mode to ISP, Click on “Read
Device ID” option to check communication between
ARM7kit and CPU through RS 232 cable.

• Once Read device ID successful than go to browse file and


select corresponding project dcmotor.hex file and click on
Upload to Flash.
• Once the uploading hex file successful than it shows the
hex file downloaded successfully from computer to ARM7
kit.
• Now ARM7 kit switch mode should be changed to RUN
mode and press on Reset button of ARM7 kit.
• The dc motor will start rotating either clockwise direction
or anticlockwise direction.
• In MC05 dc motor interface module Direction switch
button is provided to change the rotation either clockwise
or anticlockwise.
• In MC05 dc motor interface module PWM switch button is
provided for rotation 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 are
•Set sequence-0x00030000 on the pins IO1SET.
•Call delay function
•Clear sequence-0x00030000 on the pins IO1CLR.
•Clockwise direction are
•Set sequence-0x00050000 on the pins IO1SET.
•Call delay function
•Clear sequence-0x00050000 on the pins IO1CLR.
•End.
Electronics and Communication Engineering 15EC55P
DC Motor Interface Embedded C Program
#include <LPC214x.H>

/* Delay Program */
void MSdelay(unsigned int rTime)
{
unsigned int i,j;
for(i=0;i<=rTime;i++)
for(j=0;j<1275;j++);
}
/* Main Function*/
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--;

}
switch(Direction) /******* Switch case loop ********/
{
case 0: /************ case 0 – Anti-lockwise*************/
IO1SET = 0x00030000;
MSdelay(500);
IO1CLR = 0x00030000;
break;

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


IO1SET = 0x00050000;
MSdelay(500);
IO1CLR = 0x00050000;
break;
}
}
}
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.


What have we Understood?
1. Which register controls the direction of each port pin
a) IODIR register.
b) IOPIN register.
c) IOCLR register.
d) None of the above.

Key Answer -a

Electronics and Communication Engineering 15EC55P


2. IOCLR register produces LOW at corresponding port
pins when it executed.

a) False
b) True

Key Answer- b

Electronics and Communication Engineering 15EC55P


3. GPIO stands for

a) General Purpose Indirect Option


b) General Procedure Input Option
c) General Purpose Indirect Output
d) General Purpose Input Output

Key Answer- d

Electronics and Communication Engineering 15EC55P


4. How many GPIO Port pin value registers.
a) 2
b) 3
c) 4
d) 8

Key Answer- c

Electronics and Communication Engineering 15EC55P


5. DC motor is defined as

a) Direct Current into mechanical energy


b) Direct Current into electrical energy
c) Direct Current into power energy
d) None of the above

Key Answer- a

Electronics and Communication Engineering 15EC55P


6. On reset default GPIO registers becomes output
mode.

a) True
b) False

Key Answer- b

Electronics and Communication Engineering 15EC55P


7. DC Motor works on the principle of.
a. Lorentz Law
b. Ohm’s Law
c. Coulombs Law
d. None of the above

Key Answer- a

Electronics and Communication Engineering 15EC55P


8. In PWM ON signal over a period is known.

a. Positive cycle
b. Negative cycle
c. Duty cycle
d. None of the above

Key Answer- c

Electronics and Communication Engineering 15EC55P


9. Writing One’s produces HIGH at the corresponding
port pin is
a. IOCLR
b. IOPIN
c. IODIR.
d. IOSET

Key Answer- d

Electronics and Communication Engineering 15EC55P


10. Writing One’s produces LOW at the corresponding port
pin is
a. IOCLR
b. IOPIN
c. IODIR.
d. IOSET

Key Answer- a

Electronics and Communication Engineering 15EC55P


Activity
•Write an Embedded C language Program to interface dc motor
and rotates only in clockwise direction.

•Write an Embedded C language Program to interface dc motor


and rotates only in anti-clockwise direction.

Electronics and Communication Engineering 15EC55P


Thank you
VINODAKUMAR M. SONAR GPT Bagalkote-152

VITHALANI PARESH K GPT Raichur-117


K. RENUKA GPT Chitradurga-149
SHREELATA SAPPANDI GPT Hubli-171
NAVEEN KUMAR S GPT Mulabagal-156
SHRISHAIL HIREMATH GPT Surpur-180
VANISHREE YALLAPURMATH GPW Hubli- 121
ARJUN DGOTUR GPT Mundgod-167
UNDI SIDDESH GPT Kudlagi-174

GIRIJA YAMAKANMARDI GPT Vijayapur-120

Electronics and Communication Engineering 15EC55P

You might also like