Stepper motor Interface with Cortex m4

This example describes how to run a stepper motor uisng cortex m4. The processor we have used is LPC4088 Cortex M4.We have used cortex m4 development board from pantech

Procedure to run stepper motor using Cortex m4 development board

  1. Power: In the PCONP register, set the PCGPIO bit
  2. Configure pins P3.23 to P3.26 as GPIO pins using IOCON registers IOCON_P3_23 to
    IOCON_P3_26
  3. Configure the pins P3.23 to P3.24 as output pins using their direction registers.
  4. Send the stepper sequence via IO lines

Stepper motor Interface with Cortex m4 – C source code

#include <LPC407x_8x_177x_8x.h>

void delay_ms(long ms);
 
int main(void)
{
  //1. Set the PCGPIO bit
  LPC_SC->PCONP |= (1<<15);
 
  //2. Configure pins P3.23 to P3.26 as GPIO pins
  LPC_IOCON->P3_23 = 0x0;
  LPC_IOCON->P3_24 = 0x0;
  LPC_IOCON->P3_25 = 0x0;
  LPC_IOCON->P3_26 = 0x0;
 
  //3.Configure the pins P3.23 to P3.26 as output pins
  LPC_GPIO3->DIR = (0x0F<<23);
 
  while(1)
  {
   //4. Send the stepper sequence
   //Stepper Squence 1001,1100,0110,0011
   LPC_GPIO3->PIN=(0x09<<23);     
   delay_ms(5);  
    LPC_GPIO3->PIN=(0x0c<<23);
    delay_ms(5);
    LPC_GPIO3->PIN=(0x06<<23);
    delay_ms(5);
    LPC_GPIO3->PIN=(0x03<<23);
   delay_ms(5);
  }
}

void delay_ms(long ms)      // delay 1 ms per count @ CCLK 120 MHz
{
  long i,j;
  for (i = 0; i < ms; i++ )
  for (j = 0; j < 26659; j++ );
}

Pantech:
Leave a Comment

This website uses cookies.