Hi All
I need assistance with a my first project I am working on please. I have made a system that uses an interupt signal from a Hall Effect Sensor to tell the servo motor to start to move a certain amount of positions determined by my coding (the signal is just to tell the servo to start).
I have a larger servo (3Nm) that has a dedicated servo system which for now, I am just sending the pulse frequency to control the movement. The connection between the Arduino and Servo is Opto Isolated.
The problem is when I power the servo on, the interupt signal seems to be triggered at a very fast rate even though the Hall Effect Sensor has not moved. I tried all trigger combinations of the interupt (rising, falling, low, change) and the results are the same. I also disconnected the motor from the dedicated servo system to eliminate that possibility of interference.
I tested the code and wiring on a stepper motor and driver and I have no interference. And when I put the servo system off, the code runs as expected with no interference.
The user manual for the servo does say that I need an EMI filter at the power source. I did not install one yet however if someone could confirm whether the lack of EMI filter is the cause or maybe it is some other issue?
I am new to electronics so am not to familiar about EMI filter and noise.
Thank you for the help
I have attached my code below:
#define PINA 2 // pulse
#define PINB 3 //sign
#define PINC 4 //enable
#define PINI 5 //interupt pin
#define INTERRUPT 5 // that is, pin 5
volatile boolean fired;
void isr ()
{
if (digitalRead(PINI) == 0)
{
fired = true;
count++;
}
}
void setup() {
Serial.begin(38400);
Serial.println("Begin");
fired = false;
pinMode(PINI, INPUT); //receives signal from first Arduino
digitalWrite (PINI, 1);
attachInterrupt (digitalPinToInterrupt(PINI), isr, FALLING);
pinMode(PINC, OUTPUT);//enable
digitalWrite(PINC, 1);
pinMode(PINA, OUTPUT);
digitalWrite(PINA, 0);
pinMode(PINB, OUTPUT);
digitalWrite(PINB, 1);
}
void loop() {
if (fired == true)
{
fired = false;
for (int c = 1; c<=1; c++) {
digitalWrite(PINA, 1);
delayMicroseconds(300);
digitalWrite(PINA, 0);
delayMicroseconds(300);
}
}
}