Hello everyone. I have been searching and researching and have not found any viable answers to my questions. I have one of these actuators (http://www.timotion.com/product/1481269298/74) hooked up to a motor shield (https://www.pololu.com/product/2507) on a Arduino Mega. The MA2 is configured with dual hall effects but I only need the one. Using an interrupt I am counting the rotations to keep track of the stroke distance. The problem I am having is when I send the counter data to the serial monitor for review I get multiples and multiples showing up. I have attached a screen capture of the serial monitor for review. Can anyone tell me why this is and will it have any bearing on accuracy? In the example code I am retracting and extending to the internal limit switches. Thanks in advance for any insight.
#include "DualVNH5019MotorShield.h"
DualVNH5019MotorShield md;
// Motorshield Speed Variable
const int motorspeed = 400; //400 is max speed
const int delayMotor = 200; //settle inertia before changing directions
volatile unsigned long act_hallcounter; // volatile variables, may be changed
volatile byte act_hallstate = LOW; // volatile variables, may be changed
const int act_hallpin = 19; //Signal wire in Pin 19 on Mega for interrupt
boolean act_retracting = false;
boolean act_extending = false;
void setup() {
pinMode(act_hallpin, INPUT);
digitalWrite(act_hallpin, HIGH); // enable internal pullup (if hall needs it)
md.init(); // initialize VNH5019
attachInterrupt(digitalPinToInterrupt(act_hallpin), act_read_hall, RISING);
Serial.begin(9600);
Serial2.begin(9600);
Serial.println("Actuator Control Test");
}
void loop() {
if (Serial2.available()>0)
{
char data = Serial2.read();
switch (data)
{
case 'E': // Extend Actuator
Serial.println ("Extend Actuator");
act_extend();
break;
case 'R': // Retract Actuator
Serial.println ("Retract Actuator");
act_retract();
break;
case 'C': // Calibrate
Serial.println ("Calibrate Actuator");
act_calibrate();
break;
}
}
}
void act_retract()
{
act_retracting = true;
md.setM2Speed(-motorspeed);
delay(1);
while(md.getM2CurrentMilliamps() > 0)
{
md.setM2Speed(-motorspeed);
Serial.println(act_hallcounter);
}
md.setM2Brake(400);
act_retracting = false;
}
void act_extend()
{
act_extending = true;
act_hallcounter = 0;
md.setM2Speed(motorspeed);
delay(1);
while(md.getM2CurrentMilliamps() > 0)
{
md.setM2Speed(motorspeed);
Serial.println(act_hallcounter);
}
md.setM2Brake(400);
act_extending = false;
}
void act_calibrate() //Retract actuator to home position to reset counter
{
md.setM2Speed(-motorspeed);
delay(1);
while(md.getM2CurrentMilliamps() > 0)
{
md.setM2Speed(-motorspeed);
}
md.setM2Brake(400);
delay(delayMotor);
act_hallcounter = 0;
}
void act_read_hall() //ISR for counting hall effect
{
act_hallstate = digitalRead(act_hallpin); // read input signal level
if (act_extending == true) { act_hallcounter ++; }
if (act_retracting == true) { act_hallcounter --; }
}

