Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Interfacing Stepper Motor with LPC 1343

Status
Not open for further replies.

sanpai

Newbie level 6
Newbie level 6
Joined
Oct 23, 2012
Messages
11
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
1,367
Hey team ,

We are trying to interface the stepper motor with the LPC 1343 controller and we are facing quite a number of challenges in the same .

We haven got the ULN2003 ic for the driver but we used l293d and DS2003N in the place but no luck .

we have tried everything but haven been successful in getting the motor run.

below is the code for the same , please let us know where exactly the problem is surfacing .

Expecting an early reply from you folks :)

CODE :



Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
===============================================================================
 Name        : main.c
 Author      : Santhosh Pai
 Version     :
 Copyright   : Copyright (C)
 Description : main definition
===============================================================================
*/
 
#ifdef __USE_CMSIS
#include "LPC13xx.h"
#include "clkconfig.h"
#include "gpio.h"
#include "config.h"
#include "timer32.h"
#endif
 
#include <cr_section_macros.h>
#include <NXP/crp.h>
 
// Variable to store CRP value in. Will be placed automatically
// by the linker when "Enable Code Read Protect" selected.
// See crp.h header for more information
__CRP const unsigned int CRP_WORD = CRP_NO_CRP ;
 
// TODO: insert other include files here
 
// TODO: insert other definitions and declarations here
 
int main(void) {
    
    //considering an stepper motor with an step angle of  1.8 degree
    
    //setting the pins of p2.0 to p2.4 as outputs
 
    LPC_GPIO2->DIR |= 0x0000000F;
 
    enable_timer32(0);//enable timer 0
    
        while(1)//anticlockwise rotation
        {
            LPC_GPIO2->DATA |= 0x00000006;
            LPC_GPIO2->DATA |= 0x00000003;
            LPC_GPIO2->DATA |= 0x00000009;
            LPC_GPIO2->DATA |= 0x0000000C;
            delay32Ms(0,100);
            
        }
        
    return 0 ;
}




The code is building fine but its not running the motor ,please let us know whether we have to use ULN2003 IC itself and not anything else .and please do review the code if there are anymistakes .

Thanks,

Santhosh Pai
 
Last edited by a moderator:

How are you connecting the motor to the microcontroller?. What is the motor doing (moving erratically or just stopped)? Can you upload a schematic of what you are doing?
For what I can see in the code, you are not doing anything (writing 0xC to the port and then wait) you may want to try this:
Code:
void rotateRigth(int *val)
{
  if(*val==0x03) *val = 0x09;
  else if(*val == 0x09) *val = 0x0C;
  else *val = *val >> 1;
}

int val=0x0C;
while(1)
  {
    rotateRigth(&val);
    delay32Ms(0,100);
    LPC_GPIO2->DATA=val;
  }
Why are you making a logical OR to the output? LPC_GPIO2->DATA |= 0x00000006;
Aren't you trying to have an output like this?:
Code:
0110
0011
1001
1100
0110
0011
1001
1100
 
Last edited:

Hello Pedro,

Thanks for your very quick response , we had posted a wrong code earlier sorry for that .

The stepper motor was not responding and it was standstill.
Please check the code below which was burned to the controller and check the hardware connections from the schematic.Please let us know whether DS2003N is the right IC to drive the stepper motor .

Code:
#ifdef __USE_CMSIS
#include "LPC13xx.h"
#include "clkconfig.h"
#include "gpio.h"
#include "config.h"
#include "timer32.h"
#endif
 
#include <cr_section_macros.h>
#include <NXP/crp.h>
 
// Variable to store CRP value in. Will be placed automatically
// by the linker when "Enable Code Read Protect" selected.
// See crp.h header for more information
__CRP const unsigned int CRP_WORD = CRP_NO_CRP ;
 
// TODO: insert other include files here
 
// TODO: insert other definitions and declarations here
 
int main(void) {
    
    //considering an stepper motor with an step angle of  1.8 degree
    
    //setting the pins of p2.0 to p2.3 as outputs[ATTACH=CONFIG]81867._xfImport[/ATTACH]
 
    LPC_GPIO2->DIR |= 0x0000000F;
 
    enable_timer32(0);//enable timer 0
    
        while(1)//anticlockwise rotation
        {
            LPC_GPIO2->DATA = 0x00000006;
            LPC_GPIO2->DATA = 0x00000003;
            LPC_GPIO2->DATA = 0x00000009;
            LPC_GPIO2->DATA = 0x0000000C;
            delay32Ms(0,100);
            
        }
        
    return 0 ;
}

The data sheet for the ic can be found below

**broken link removed**

- - - Updated - - -

Hi pedro ,

Im reattaching the image of the hardware schematic , please check and let us know .

Motor connection.jpg
 

As far as I can see, the problem is in your code. In your while loop you are writing to LPC_GPIO2 a 6, then a 3, then a 9 and then a 0x0C. After that you wait for 100 ms and do the same over and over.
The correct logic would be, write a 6, delay, write a 3, delay, write a 9, delay and so on.
You are trying yo use a half-step drive.
440px-Drive.png


Or you can do something like this:
Code:
void rotateRigth(int *val)
{
  if(*val==0x03) *val = 0x09;
  else if(*val == 0x09) *val = 0x0C;
  else *val = *val >> 1;
}

int val=0x0C;
while(1)
{
   rotateRigth(&val);
   delay32Ms(0,100);
   LPC_GPIO2->DATA=val;
}
 
  • Like
Reactions: sanpai

    sanpai

    Points: 2
    Helpful Answer Positive Rating
Hey Mr Pedro,

Sorry for getting back lately .

There was a problem with the connections due to which we were unable to run the motor , the common pin of the motor must be connected to the VCC and we have used the half step drive mode to run the motor .

Thanks for your help all is well now . :)
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top