hi there i am working on a project to control two stepper motors from a pic16f690 using L297 stepper motor controllers adn uln2075b quad darlington transitor ic. i having difficulty with the c code to control the motors from the pic can anyone help me with C code to control the motors??? PLEase:-D:-D
//////**********Chamwasu Musa Gali******Stepper Motor Control Codes*******Final Year Project Codes/////////////////#include <htc.h>#include <pic.h>#define stepcnt 100 //max number of steps#define _XTAL_FREQ 4000000void Run_Motor1_cw(void);void Run_Motor2_cw(void);void Accel_Motor1_cw(void);void Deccel_Motor1_cw(void);void Accel_Motor2_cw(void);void Deccel_Motor2_cw(void);void Run_Motor1_ccw(void);void Run_Motor2_ccw(void);void Accel_Motor1_ccw(void);void Deccel_Motor1_ccw(void);void Accel_Motor2_ccw(void);void Deccel_Motor2_ccw(void);void main(void){
TRISA =0xFF;//SET PORT A AS INPUT
PORTA =0;//INITIALISE PORTA AS 0
TRISB =0xFF;//SET PORT B AS INPUT PORT
PORTB =0;//INITIALISE PORT B AS 0
TRISC =0x00;//SET PORT C AS AN OUTPUT PORT
Run_Motor1_cw();}void Run_Motor1_cw(void)//function to run motor 1 at constant speed{int b;
PORTC =0x32;//reset motor phases to initial position 0101 and light up led to indicate motor 1 is active and wait for the step signal
__delay_us(150);for(b=0;b<=stepcnt;b++)//loop to step 100 times running motor1{
PORTC =0xB2;
__delay_us(150);
PORTC=0xB3;
__delay_us(50);}}void Run_Motor2_cw(void)//function to run motor 2 at constant speed{int d;
PORTC =0x52;//turn on led to indicate motor 2 is about to start running and wait for the step signal
__delay_us(15);for(d=0;d<=stepcnt;d++)//loop to run motor 2 for 100 steps{
PORTC =0xD2;
__delay_us(15);
PORTC =0xD6;
__delay_us(5);}}void Accel_Motor1_cw(void)//function to accelerate motor 1{int x;
PORTC=0xB2;//delay tables to accelerate motor 1
__delay_us(25);
PORTC =0xB3;
__delay_us(5);
PORTC =0xB2;
__delay_us(20);
PORTC =0xB3;
__delay_us(5);
PORTC =0xB2;
__delay_us(15);
PORTC =0xB3;
__delay_us(5);
PORTC =0xB2;
__delay_us(10);
PORTC =0xB3;
__delay_us(5);
PORTC =0xB2;
__delay_us(5);
PORTC =0xB3;for(x=0;x<=stepcnt;x++)//loop to maintain final speeed after delay table implementation for 100 steps{
PORTC =0xB2;
__delay_us(5);
PORTC =0xB3;
__delay_us(5);}}void Deccel_Motor1_cw(void)//function to decelerate motor 1{int y;
PORTC =0xB2;//delay tables to decelerate motor 1
__delay_us(5);
PORTC =0xB3;
__delay_us(5);
PORTC =0xB2;
__delay_us(10);
PORTC =0xB3;
__delay_us(5);
PORTC=0xB2;
__delay_us(15);
PORTC =0xB3;
__delay_us(5);
PORTC=0xB2;
__delay_us(20);
PORTC=0xB3;
__delay_us(5);
PORTC=0xB2;
__delay_us(25);
PORTC =0xB3;for(y=0;y<=stepcnt;y++)//loop to maintain final speed after deceleration table implentation{
PORTC =0xB2;
__delay_us(25);
PORTC =0xB3;
__delay_us(25);}}void Accel_Motor2_cw(void)//function to accelerate motor 2{int m;
PORTC=0xD2;//delay tables to accelerate motor two
__delay_us(25);
PORTC =0xD6;
__delay_us(5);
PORTC =0xD2;
__delay_us(20);
PORTC =0xD6;
__delay_us(5);
PORTC =0xD2;
__delay_us(15);
PORTC =0xD6;
__delay_us(5);
PORTC =0xD2;
__delay_us(10);
PORTC =0xD6;
__delay_us(5);
PORTC =0xD2;for(m=0;m<=stepcnt;m++)//loop to maintain final speeed after delay table implementation for 100 steps{
PORTC =0xD2;
__delay_us(5);
PORTC =0xD6;
__delay_us(5);}}void Deccel_Motor2_cw(void){int n;
PORTC =0xD2;//delay tables to decelerate motor 2
__delay_us(5);
PORTC =0xD6;
__delay_us(5);
PORTC =0xD2;
__delay_us(10);
PORTC =0xD6;
__delay_us(5);
PORTC=0xD2;
__delay_us(15);
PORTC =0xD6;
__delay_us(5);
PORTC=0xD2;
__delay_us(20);
PORTC=0xD6;
__delay_us(5);
PORTC=0xD2;
__delay_us(25);
PORTC =0xD6;for(n=0;n<=stepcnt;n++)//loop to maintain final speed after deceleration table implentation{
PORTC =0xD2;
__delay_us(25);
PORTC =0xD6;
__delay_us(25);}}void Run_Motor1_ccw(void)//function to run motor 1 counter clockwise{int n;
PORTC =0x30;//initialise motor 1 and turn on led for motor 1
__delay_us(150);for(n=0;n<=stepcnt;n++)// loop to run motor one at contstan speed counter clockwise{
PORTC =0xB0;
__delay_us(150);
PORTC =0xB1;
__delay_us(50);}}void Run_Motor2_ccw(void){int n;
PORTC =0x50;
__delay_us(150);for(n=0;n<=stepcnt;n++){
PORTC =0xD0;
__delay_us(150);
PORTC =0xD4;
__delay_us(50);}}void Accel_Motor1_ccw(void){int x;
PORTC=0xB0;//delay tables to accelerate motor 1
__delay_us(25);
PORTC =0xB1;
__delay_us(5);
PORTC =0xB0;
__delay_us(20);
PORTC =0xB1;
__delay_us(5);
PORTC =0xB0;
__delay_us(15);
PORTC =0xB1;
__delay_us(5);
PORTC =0xB0;
__delay_us(10);
PORTC =0xB1;
__delay_us(5);
PORTC =0xB0;
__delay_us(5);
PORTC =0xB1;for(x=0;x<=stepcnt;x++)//loop to maintain final speeed after delay table implementation for 100 steps{
PORTC =0xB0;
__delay_us(5);
PORTC =0xB1;
__delay_us(5);}}void Deccel_Motor2__ccw(void){int n;
PORTC =0xD0;//delay tables to decelerate motor 2
__delay_us(5);
PORTC =0xD4;
__delay_us(5);
PORTC =0xD0;
__delay_us(10);
PORTC =0xD4;
__delay_us(5);
PORTC=0xD0;
__delay_us(15);
PORTC =0xD4;
__delay_us(5);
PORTC=0xD0;
__delay_us(20);
PORTC=0xD4;
__delay_us(5);
PORTC=0xD0;
__delay_us(25);
PORTC =0xD4;for(n=0;n<=stepcnt;n++)//loop to maintain final speed after deceleration table implentation{
PORTC =0xD0;
__delay_us(25);
PORTC =0xD4;
__delay_us(25);}
}
---------- Post added at 00:21 ---------- Previous post was at 00:17 ----------
HI guys this is the code to run two motors from one pic 16f690 using L297 stepper motor controllers and an ULN2075B quad darlington arrays to step the motors i have been running the code but the motors are not responding i am thinking wether the delays i have used are too small or what is the problem i don't know. i am using unipolar steeper motor with 28mA per phase and 7.5W power please can somenone give me some help here cheers