Stepper motor acceleration-constant speed-deceleration operation program (C51 source program)

Publisher:MysticJourneyLatest update time:2016-10-21 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
ME300 series MCU development system + stepper motor module demonstration program

Function: The stepper motor starts in an accelerated mode, and after the speed reaches the maximum speed specified by the program, it keeps running at a constant speed for a period of time, and then starts to decelerate.

The demo program is run in the same way until the stepper motor stops rotating. The K1 key controls the running of the demo program. D1-D4 on the stepper motor module can indicate the working status.

/******************************************************************/
/* */
/* ME300B MCU Development System Demonstration Program - Stepper Motor Acceleration and Deceleration Running Program */
/* */
/* When the stepper motor starts, the speed gradually accelerates from slow to fast. */
/* Stepper motor runs at a constant speed */ 
/* Stepper motor gradually decelerates from fast to slow and stops */
/* Website http://www.elecfans.com                                                   */
 /******************************************************************/
    
#include        //51 chip pin definition header file
#include        //Internally contains the delay function _nop_();

#define uchar unsigned char
#define uint unsigned int

sbit K1=P1^4;
uchar co de FFW[8]={0xf1,0xf3,0xf2,0xf6,0xf4,0xfc,0xf8,0xf9};
//uchar co de REV[8]={0xf9,0xf8,0xfc, 0xf4,0xf6,0xf2,0xf3,0xf1};
uchar rate ;        
/**************************************** *********************/
/*                                                  
/* Delay
/* 11.0592MHz clock,                                    
/*                                                      
/****************** *******************************************/
void delay()
 {                           
   uchar k;
   uint s;
   k = rate;
   do
    {
       for(s = 0; s <500; s++);  
    }while(--k);
 }
/****************** ******************************************/
/*
/*Stepper motor forward rotation
/*
/******************************************** ****************/
void motor_ffw()

   uchar i;
 
    for (i=0; i<8; i++) //One cycle rotates 30 degrees
    {
       P1 = FFW[i ]; //Get data
       delay(); //Adjust speed
    }
}

/************************************************************
*                                                       
*Stepper motor operation                                               
*                                                      
*********************************************************/
void motor_turn()

   uchar x;
   rate=0x10;
   x=0xf0;
   do
     {
        motor_ffw(); //acceleration
        rate--;
     }while(rate!=0x01);

   do
     {     
        motor_ffw(); //Constant speed
       x--;
     }while(x!=0x01);
  
   do
     {
        motor_ffw(); //Deceleration 
        rate++;
     }while(rate!=0x10);    
}

/************************************************************
*                                                       
* Main program                                               
*                                                      
**********************************************************/
main()
{     
   
   P1=0xf0;

   while(1)
  {
      P1=0xf0;
      if(K1==0)
     {
       motor_turn();
     }
  } 
}

/****************************************************** *******/

Stepper motor acceleration-constant speed-deceleration operation program (C51 source program) - z86k - z86k's blog

Reference address:Stepper motor acceleration-constant speed-deceleration operation program (C51 source program)

Previous article:The volatile keyword in C51
Next article:51 MCU CAN bus communication program

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号