RuH_iranga
Junior Member level 3
Component:
16f877
POLOLU encoder motor Pololu - 131:1 Metal Gearmotor 37Dx57L mm with 64 CPR Encoder 2096 pulses per one shaft revolution.
Use RB0 interrupts and turn on the PORTB pull-up resistors.
use MikroC language.
By changing RD0 and RD1 you can change motor direction, then it should be reduced the count. and also change the (count<-4192) you can ensure that program detect the position as well as direction. this just reading encoder and you can use it with your application. Also possible to use 10k external Pull-UPs on B0 and B1.
Thanks.:smile:
16f877
POLOLU encoder motor Pololu - 131:1 Metal Gearmotor 37Dx57L mm with 64 CPR Encoder 2096 pulses per one shaft revolution.
Use RB0 interrupts and turn on the PORTB pull-up resistors.
use MikroC language.
Code:
int count=0; // This count use in interrupt routine
void interrupt() // enter when RB0 Falling
{
if(portb.f0&portb.f1) // By checking B0 and B1, Position and Direction Find
{count++; // If "+" direction
}
else // If "-" direction
{count--;
}
INTCON.INTF=0; // Clear flag
}
void main()
{
Pwm_Init(5000);
PWM_Start();
TRISB=0b11111111; // B0 and B1 encoder inputs
TRISD=0b00000000; // Motor Control Pin
INTCON=0b11010000; // enable RB0 interrupts
OPTION_REG=0b01000000; // Enable portB internal PULL-UP resistors
// And Rising edge of RB0 int
Pwm_Change_Duty(240); // Whatever speed
portd.f1=1; // Motor drive to "+"
portd.f0=0;
while(1)
{
if (count>4192) // Count exceeds 4192(2 round), Stop
{
portd.f1=0;
portd.f0=0;
}
}
}
By changing RD0 and RD1 you can change motor direction, then it should be reduced the count. and also change the (count<-4192) you can ensure that program detect the position as well as direction. this just reading encoder and you can use it with your application. Also possible to use 10k external Pull-UPs on B0 and B1.
Thanks.:smile: