Reed switch pulse counting jumps in the beginning , then gets right.

Hello everyone.

I’m trying to control a linear actuator with the feedback of its built in reed switch.

The problem I’m having is that everytime I engage the actuator from a standstill, while trying to count the number of pulses the value jumps with about 200 and then starts counting “correctly”.

fx. startcount is 0 in serial monitor, the motor is activated the counter jumps to around 200 and then correctly starts to count 201, 202, 203 ect.

Then if I stop the actuators at the count of 600 and start it again it jumps to 800 and starts correctly counting 801, 802, 803 and so on.

Acording to the documentation of my linak LA30L motor it should produce 8 pulses/spindle revolution the spindel pitch is 9mm and the lenght of the stroke is 250mm

I’m recording aprox 1000 minus the 200 initial “wrong” reading for a stroke.

The Programmer box that came with the actuators have a built in pulse counter and that counts around 450 pulses per stroke.

I have made a video showing the actuators moving with an oscilloscope attached to monitor the pulses LINAK LA30L actuators back and forth with oscilloscope - YouTube

The reason I dont know the excact pulse counts of a stroke, is that I haven’t calibrated the actuators as it requires them to be mounted and engage a sequence, that will set the end point of the actuator by a current limiter when it reached the end of travel.

Is there something wrong with my code?

int CountPin = 2;

volatile int PulseSeen = 0;

void setup() {
  pinMode(CountPin, INPUT);
  attachInterrupt(0, Counter, FALLING);
  Serial.begin(9600);
  Serial.println("Start of test");

}

void loop() {
Serial.println(PulseSeen);
}

void Counter (){
  PulseSeen++;
  }

I don't see a problem with your code, that could cause an jump by just (exactly?) 200 pulses.

Could it be a motor power supply problem, where the motor power drops too low due to high initial motor current?

It seems to be a debounce problem when the reed switch activates. I found another thread here on the forum, I’m currently testing his code and it seems to work. Will report back shortly if it works as intended.