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.

PIC18f452 dc motor coding help...

Status
Not open for further replies.

Waran

Newbie level 5
Joined
Jul 22, 2009
Messages
10
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Malaysia
Activity points
1,523
delaying dc motor

Hi,

This is the coding I did to control a dc motor to run clockwise and anti-clockwise and control the speed of the dc motor.I previously had problem when using 'delay_ms' and I replace it by applying a simple loop to make a delay which is 'wait()' command. The code is error free when I compile using mikroC PRO compiler.But can it work when I burn and apply to a circuit given below?

void wait() {
unsigned int k ;
for(k=0;k<5000;k++);
}

void main (void)
{

TRISA = 0x00; //Initialize these Ports as Outputs
TRISC = 0x00; //This one too
TRISD = 0x00; //This one toooo


PORTA = 0x00; //Initialize PORTA...so the LED is off

PORTC.F0 = 0; //Brake Off
PORTD.F1 = 1; //Direction Forward
PORTD.F1 = 0; //Direction reverse

while(1)
{
if (PORTD.F1 == 1)
{
wait();
wait(); //Some delay to see it works with human eye
PORTC = 0b00001111; // 0x0F Full Speed

wait();
wait();
wait();
wait(); //Some delay to see it works with human eye
PORTC = 0b00001011; //0X0B (3/4 Full Speed)

wait();
wait();
wait();
wait(); //Some delay to see it works with human eye
PORTC = 0b00000101; //0x07 (1/2 Full Speed)

wait();
wait();
wait();
wait(); //Some delay to see it works with human eye
PORTC = 0b00000011; //0x03 (1/4 Full Speed)

PORTD.F0 = 1; //Turn Brake On
wait(); //Some delay to see it works with human eye
PORTD.F0 = 0; //Turn Brake Off
}
else if (PORTD.F1 == 0)
{
wait();
wait();
wait();
wait(); //Some delay to see it works with human eye
PORTC = 0b00001111; // 0x0F (Full Speed)

wait();
wait();
wait();
wait(); //Some delay to see it works with human eye
PORTC = 0b00001011; //0X0B (3/4 Full Speed)

wait();
wait();
wait();
wait(); //4 * 0.5 seconds = 2 Second Pause
PORTC = 0b00000101; //0x07 (1/2 Full Speed)

wait();
wait();
wait();
wait(); //Some delay to see it works with human eye
PORTC = 0b00000011; //0x03 (1/4 Full Speed)

PORTD.F0 = 1; //Turn Brake On
wait(); //Some delay to see it works with human eye
PORTD.F0 = 0; //Turn Brake Off
}
}
}


 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top