Professional Documents
Culture Documents
EC 15EC55P PB E7 Sy
EC 15EC55P PB E7 Sy
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.
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.
E.g. consider a pulse with a period of 10ms which remains ON (high) for 2ms.The duty cycle of this
pulse will be
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.
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.
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.
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.
0000 0111
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.
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;
}
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.
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
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
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
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
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
}
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.
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.
Flow Chart:
Start
False or No(0)
Anticlockwise. Anticlockwise.
Set Seqence: 0x00030000 Set Seqence: 0x00050000
Call delay Call delay
Clear Sequence : 0x00030000 Clear Sequence : 0x00050000
End
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
****************************************************/
while (1)
{
if ( (IO1PIN & 1<<19) == 0) /* Check if P1.19 is SET */
{
if (Direction == 0)
Direction++;
else if (Direction == 1)
Direction--;
IO1SET = 0x00030000;
MSdelay (500);
IO1CLR = 0x00030000;
break;
IO1SET = 0x00050000;
MSdelay(500);
IO1CLR = 0x00050000;
break;
}
}
}
/***********************************END**************************************/
Output: