Wednesday, October 1, 2008

Make MCU Board - DC and Stepper Motor Module


DC motor and stepper motor are generally devices that they are used in automation control domain,
I introduce the control circuit and programming for these 2 type motors, as following:



The circuit schematic:














Main program:
/*******************************************************************************

Copyright (c) 2008 Wizign Ltd.
All Rights Reserved.

main.c: Main program for demo trigger of motors

Version: 1.0.0

Date: Oct 01, 2008

Author: YenHung Chen

E-mail: yhchen@wizign.com

Revision:
---------- -----------------------------------------------------------------
2008/10/01 Created by YenHung Chen, demo trigger of motors for both 8051 and PIC

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



<>For AT89S52

LCD display:
There are 8 data pins, which are connected P2.
The control pins are connected to P1_0, P1_1, and P1_2.

Step motor:
P3_0, P3_1, P3_2, P3_3

DC motor:
P3_6, P3_7

<>For PIC16F877A

LCD display:
There are 8 data pins, which are connected PORTD
The control pins are connected to RA0, RA1, and RA2.

Step motor:
RC0, RC1, RC2, RC3

DC motor:
RC6, RC7


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

#include "global.h"
#include "delay.h"
#include "lcd.h"
#include "motor.h"

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// define IO and global variables

#ifdef MCU_PIC

// Configurations
typedef unsigned int config;
config at 0x2007 __CONFIG = _XT_OSC & _PWRTE_OFF & _BODEN_OFF & _WDT_OFF & _LVP_OFF;

#endif


//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// define functions

/* Initilize parameters before run the main loop */
void InitParams(void)
{

LCDInit();
MotorInit();
}

/* Display message on LCD panel */
void DisplayRotateStatus(char* pMsg)
{
LCDGoto(0);    // goto 1st line
LCDPuts("  WIZIGN LTD.  ");

// Display rotate status
LCDGoto(0x40);    // goto 2nd line
LCDPuts(pMsg);
}

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// main program

void main(void)
{
int count = 0;
int direction = 0;  // 0:clockwise, 1:counter clockwise

// Initilize parameters
InitParams();

/* do loop */
while(1){
    if(direction == 0){
        DisplayRotateStatus("Clockwise");
        MotorStepRotate(MOTOR_ROTATE_CW, 4);
        MotorDCRotate(MOTOR_ROTATE_CW, 2);
    }else{  // left
        DisplayRotateStatus("C Clockwise");
        MotorStepRotate(MOTOR_ROTATE_CCW, 2);
        MotorDCRotate(MOTOR_ROTATE_CCW, 4);
    }
    count++;
    if(count >= 200){
        count = 0;
        direction = (direction == 0) ? 1 : 0;
    }
}
}

No comments: