Motor control with PIC16F88

Status
Not open for further replies.

Engin_nerd

Newbie level 1
Joined
Jul 28, 2009
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,300
pic16f88 mikroc

I'm stuck on this project and I believe something is wrong with my code. I'm using a black/white wheel encoder with 24 tics on it, a infrared reflective light sensor (to detect the black and white tics), a dc motor, and a quadruple half h-driver to control the motors movement.

I want the motor to move from the black tic, to the white tic and stop. This is the first step in my project and im I'm having problems with the motor stopping at each of these tics. The motor can turn over 360 degrees before it stops. Here is my code. If any one has any ideas, I'm very new to programming so any help would be appreciated. I attached my code in a notepad file

Added after 6 minutes:

***sorry my file didnt upload, here is my code***

-----------------------------------------------------------------------------------

#include "HEADER1.h"

//PORTA FOR SENSOR
#define DETECT BIT2


//PORTB FOR MOTOR CONTROL
#define CW BIT0
#define CCW BIT1
#define STOP (~BIT0|~BIT1)

//parameters
#define deg15 1 //tics for 15 degrees

unsigned char sensor;
unsigned char lastvalue;
unsigned int count;

void countdown(char source, unsigned int tics){
count = 0;

if (source == 'R'){
PORTB = CW;
}
else if(source =='L'){
PORTB = CCW;}

else{PORTB = STOP;}

lastvalue= PORTA&DETECT; //initialize before compare
while(count<tics){
sensor = PORTA&DETECT; // poll sensor first time
if(sensor!= lastvalue)//change detected
{
Delay_ms(10); //wait 15ms
sensor = PORTA&DETECT; //confirm change
if(sensor != lastvalue)
{
if((sensor&DETECT) != (lastvalue&DETECT)){count++; }
lastvalue = sensor;
}
}
}
PORTB=STOP;
}

void clockwise(){
countdown('R', deg15);

}

void counterclockwise(){
countdown('L', deg15);

}

void main(){
ANSEL =0; //turn off ATD

TRISA = 0xFF; //SENSOR ONLY INPUT
TRISB = 0xFC; //MOTOR OUTPUT

clockwise();

}

Added after 7 minutes:

The compiler I'm using is MikroC.

Added after 38 seconds:

The compiler I'm using is MikroC.
 

pic16f88 beginners projects

Maybe you could post youre schematics here so we can see what is going wrong.
Type of hardware and type of motor.
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…