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.

help with mplab errors

Status
Not open for further replies.

Eng_MC

Member level 1
Joined
Nov 16, 2010
Messages
39
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,865
hi i am using mplab to write up a code in C using the High-tech C compiler when i compile i get an error about using _delay_us in my code please can anyone help
 

#include <pic.h>
#define stepcnt 100 //max number of steps


void Run_Motor1(void);
void Run_Motor2(void);
void Accel_Motor1(void);
void Deccel_Motor1(void);
void Accel_Motor2(void);
void Deccel_Motor2(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 = 0xFF; //SET PORT C AS AN OUTPUT PORT

Run_Motor1();


}

void Run_Motor1(void) //function to run motor 1 at constant speed
{
int b;
PORTC = 0x32; //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 = 0x32;
delay_us(150);
PORTC= 0x33;
delay_us(50);
}
}

void Run_Motor2(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 = 0x52;
delay_us(15);
PORTC = 0x56;
delay_us(5);
}
}

void Accel_Motor1(void) //function to accelerate motor 1
{
int x;
PORTC= 0x32; //delay tables to accelerate motor 1
delay_us(25);
PORTC = 0x33;
delay_us(5);
PORTC = 0x32;
delay_us(20);
PORTC = 0x33;
delay_us(5);
PORTC = 0x32;
delay_us(15);
PORTC = 0x33;
delay_us(5);
PORTC = 0x32;
delay_us(10);
PORTC = 0x33;
delay_us(5);
PORTC = 0x32;
delay_us(5);
PORTC = 0x33;

for(x=0;x<=stepcnt;x++) //loop to maintain final speeed after delay table implementation for 100 steps
{
PORTC = 0x32;
delay_us(5);
PORTC = 0x33;
delay_us(5);
}
}

void Deccel_Motor1(void) //function to decelerate motor 1
{
int y;
PORTC = 0x32; //delay tables to decelerate motor 1
delay_us(5);
PORTC = 0x33;
delay_us(5);
PORTC = 0x32;
delay_us(10);
PORTC = 0x33;
delay_us(5);
PORTC= 0x32;
delay_us(15);
PORTC = 0x33;
delay_us(5);
PORTC= 0x32;
delay_us(20);
PORTC= 0x33;
delay_us(5);
PORTC= 0x32;
delay_us(25);
PORTC = 0x33;

for(y=0;y<=stepcnt;y++) //loop to maintain final speed after deceleration table implentation
{
PORTC = 0x32;
delay_us(25);
PORTC = 0x33;
delay_us(25);
}
}

void Accel_Motor2(void) //function to accelerate motor 2
{
int m;
PORTC= 0x52; //delay tables to accelerate motor two
delay_us(25);
PORTC = 0x56;
delay_us(5);
PORTC = 0x52;
delay_us(20);
PORTC = 0x56;
delay_us(5);
PORTC = 0x52;
delay_us(15);
PORTC = 0x56;
delay_us(5);
PORTC = 0x52;
delay_us(10);
PORTC = 0x56;
delay_us(5);
PORTC = 0x52;

for(m=0;m<=stepcnt;m++) //loop to maintain final speeed after delay table implementation for 100 steps
{
PORTC = 0x32;
delay_us(5);
PORTC = 0x33;
delay_us(5);
}
}

void Deccel_Motor2(void)
{
int n;
PORTC = 0x52; //delay tables to decelerate motor 2
delay_us(5);
PORTC = 0x56;
delay_us(5);
PORTC = 0x52;
delay_us(10);
PORTC = 0x56;
delay_us(5);
PORTC= 0x52;
delay_us(15);
PORTC = 0x56;
delay_us(5);
PORTC= 0x52;
delay_us(20);
PORTC= 0x56;
delay_us(5);
PORTC= 0x52;
delay_us(25);
PORTC = 0x56;

for(n=0;n<=stepcnt;n++) //loop to maintain final speed after deceleration table implentation
{
PORTC = 0x32;
delay_us(25);
PORTC = 0x33;
delay_us(25);
}
}

---------- Post added at 20:38 ---------- Previous post was at 20:33 ----------

the code is to run 2 stepper motors using a PIC16F690 and l297 stepper motor controller with quad darlington arrays.
 

use delay macro "__delay_us(z);"
where z is any integer. but for this you have to specify the crystal frequency. it this case 4MHz is selected. Below is the code with no error; successful compilation.

Code:
#include <htc.h>
#include <pic.h>
#define stepcnt 100 //max number of steps
#define _XTAL_FREQ 4000000

void Run_Motor1(void);
void Run_Motor2(void);
void Accel_Motor1(void);
void Deccel_Motor1(void);
void Accel_Motor2(void);
void Deccel_Motor2(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 = 0xFF; //SET PORT C AS AN OUTPUT PORT

Run_Motor1();


}

void Run_Motor1(void) //function to run motor 1 at constant speed
{
int b;
PORTC = 0x32; //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 = 0x32;
__delay_us(150);
PORTC= 0x33;
__delay_us(50);
}
}

void Run_Motor2(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 = 0x52;
__delay_us(15);
PORTC = 0x56;
__delay_us(5);
}
}

void Accel_Motor1(void) //function to accelerate motor 1
{
int x;
PORTC= 0x32; //delay tables to accelerate motor 1
__delay_us(25);
PORTC = 0x33;
__delay_us(5);
PORTC = 0x32;
__delay_us(20);
PORTC = 0x33;
__delay_us(5);
PORTC = 0x32;
__delay_us(15);
PORTC = 0x33;
__delay_us(5);
PORTC = 0x32;
__delay_us(10);
PORTC = 0x33;
__delay_us(5);
PORTC = 0x32;
__delay_us(5);
PORTC = 0x33;

for(x=0;x<=stepcnt;x++) //loop to maintain final speeed after delay table implementation for 100 steps
{
PORTC = 0x32;
__delay_us(5);
PORTC = 0x33;
__delay_us(5);
}
}

void Deccel_Motor1(void) //function to decelerate motor 1
{
int y;
PORTC = 0x32; //delay tables to decelerate motor 1
__delay_us(5);
PORTC = 0x33;
__delay_us(5);
PORTC = 0x32;
__delay_us(10);
PORTC = 0x33;
__delay_us(5);
PORTC= 0x32;
__delay_us(15);
PORTC = 0x33;
__delay_us(5);
PORTC= 0x32;
__delay_us(20);
PORTC= 0x33;
__delay_us(5);
PORTC= 0x32;
__delay_us(25);
PORTC = 0x33;

for(y=0;y<=stepcnt;y++) //loop to maintain final speed after deceleration table implentation
{
PORTC = 0x32;
__delay_us(25);
PORTC = 0x33;
__delay_us(25);
}
}

void Accel_Motor2(void) //function to accelerate motor 2
{
int m;
PORTC= 0x52; //delay tables to accelerate motor two
__delay_us(25);
PORTC = 0x56;
__delay_us(5);
PORTC = 0x52;
__delay_us(20);
PORTC = 0x56;
__delay_us(5);
PORTC = 0x52;
__delay_us(15);
PORTC = 0x56;
__delay_us(5);
PORTC = 0x52;
__delay_us(10);
PORTC = 0x56;
__delay_us(5);
PORTC = 0x52;

for(m=0;m<=stepcnt;m++) //loop to maintain final speeed after delay table implementation for 100 steps
{
PORTC = 0x32;
__delay_us(5);
PORTC = 0x33;
__delay_us(5);
}
}

void Deccel_Motor2(void)
{
int n;
PORTC = 0x52; //delay tables to decelerate motor 2
__delay_us(5);
PORTC = 0x56;
__delay_us(5);
PORTC = 0x52;
__delay_us(10);
PORTC = 0x56;
__delay_us(5);
PORTC= 0x52;
__delay_us(15);
PORTC = 0x56;
__delay_us(5);
PORTC= 0x52;
__delay_us(20);
PORTC= 0x56;
__delay_us(5);
PORTC= 0x52;
__delay_us(25);
PORTC = 0x56;

for(n=0;n<=stepcnt;n++) //loop to maintain final speed after deceleration table implentation
{
PORTC = 0x32;
__delay_us(25);
PORTC = 0x33;
__delay_us(25);
}
}
 
  • Like
Reactions: Eng_MC

    Eng_MC

    Points: 2
    Helpful Answer Positive Rating
thanks alot malik_zohaib
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top