Hello –
I am curious about the resolution I am obtaining from my newly received magnetic encoders for micrometal gearmotors. But, first, sweet job on those Pololu!
So, I am getting 600 counts per wheel revolution. They are advertised as 12 CPR, but seems I am getting 6 CPR, with 100:1 Micro MP gearmotors. My tests returned this value on an Arduino Uno and minimal 1284P-PU @ 16MHz, and tests failed on AMini. On the AMiniLV, my sole remaining pins for pin change ints was the MISO & MOSI lines, single motor tested. From each encoder I can measure HIGH and LOW with ref to GND on the OUTA and OUTB, e.g., 5.02V and ~180mV.When motors are allowed to free-run, the count goes up to 32k, swaps sign, and cycles back around to zero as expected. In the end I will be using the 1284P-PU as the MCU.
I am using the Arduino IDE 1.0.5-r2. Back in December I pulled down the Pololu-Arduino libraries and installed the 2012 version. The “PololuWheelEncoder” folder is where it is expected and no errors appear on verify/compile. In the changelog for the 2015 version (for Arduino 1.6) there is added boards and programmers files, that being the only difference I can tell at present.
I am fine with the results obtained from these as described above, but I am curious what I may be doing wrong to not be receiving the 12CPR from the encoders.
A hui hou, Mark
Code below for review:
[code]
#include <PololuWheelEncoders.h>
/* TB6612FNG to 1284P-PU “Arduino” pins */
#define PWMA 13
#define AIN1 18
#define AIN2 19
#define PWMB 14
#define BIN1 2
#define BIN2 3
#define STBY 12
long previousMillis = 0;
long intervalPrint = 100;
void setup(){
Serial.begin(115200);
//PololuWheelEncoders::init(2,3,4,5); // Arduino UNO
PololuWheelEncoders::init(22,23,20,21); // 1284P-PU
pinMode(PWMA,OUTPUT);
pinMode(AIN1,OUTPUT);
pinMode(AIN2,OUTPUT);
pinMode(PWMB,OUTPUT);
pinMode(BIN1,OUTPUT);
pinMode(BIN2,OUTPUT);
pinMode(STBY,OUTPUT);
Serial.println(“1284 motor test”);
startUp();
delay(2000);
Forward();
}
void loop(){
unsigned long currentMillis = millis();
if (currentMillis - previousMillis > intervalPrint)
{
previousMillis = currentMillis;
Serial.print("M1 = ");
Serial.print(PololuWheelEncoders::getCountsM1());
Serial.print(", M2 = ");
Serial.print(PololuWheelEncoders::getCountsM2());
Serial.print(" // Error M1 = ");
Serial.print(PololuWheelEncoders::checkErrorM1());
Serial.print(", M2 = ");
Serial.println(PololuWheelEncoders::checkErrorM2());
}
}
//****** MOTOR CONTROL *******
//****************************
void Forward ()
{
digitalWrite (AIN1,HIGH);
digitalWrite (AIN2,LOW);
analogWrite(PWMA,255);
digitalWrite (BIN1,HIGH);
digitalWrite (BIN2,LOW);
analogWrite(PWMB,255);
}
void Backward ()
{
digitalWrite (AIN1,LOW);
digitalWrite (AIN2,HIGH);
analogWrite(PWMA,255);
digitalWrite (BIN1,LOW);
digitalWrite (BIN2,HIGH);
analogWrite(PWMB,240);
}
void stopAll ()
{
digitalWrite (AIN1,HIGH);
digitalWrite (AIN2,HIGH);
analogWrite(PWMA,255);
digitalWrite (BIN1,HIGH);
digitalWrite (BIN2,HIGH);
analogWrite(PWMB,255);
}
void startUp ()
{
digitalWrite(STBY,HIGH);
}
void shutDown ()
{
digitalWrite(STBY,LOW);
}[/code]