Hello guys,
I have a motor 70:1 Metal Gearmotor 37Dx70L mm with 64 CPR Encoder, connected to a motor shield based on LN298 driver, and an Arduino Mega.
I want to track the number of revolution of the motor. According with the specification if i only use one encoder output, for one complete revolution is needed 70* 12 pulses count.
I connect the encoder output to a interrupt to Mega and count 70*12 pulses but the motor do less then ONE complete revolution. Where is the mistake?? Below is the code i use.
[code]int pinA = 2;
int numberA=0;
int MOTOR1_PIN1 = 6;
int MOTOR1_PIN2 = 9;
void setup()
{
pinMode(MOTOR1_PIN1, OUTPUT);
pinMode(MOTOR1_PIN2, OUTPUT);
pinMode(pinA, INPUT);
pinMode(pinB, INPUT);
attachInterrupt(digitalPinToInterrupt(pinA), CountA, RISING);
Serial.begin(9600);
speed(-35);
}
void loop()
{
if (numberA == 70*12)
{
speed(0);
}
}
void CountA()
{
numberA++;
}
void speed(int speedValue) {
if (speedValue > 0) {
analogWrite(MOTOR1_PIN1, speedValue);
analogWrite(MOTOR1_PIN2, 0);
}
else {
analogWrite(MOTOR1_PIN1, 0);
analogWrite(MOTOR1_PIN2, -speedValue);
}
}[/code]