Go Down

Topic: watching pin state change and if stops change turns motor off (Read 449 times) previous topic - next topic

peter1929

Hello all, any help would be great.

i am using

int pulsePin = 3;   //motor hall effect input

how can i do a small sketech to check this is changing state and when stops changing state turns a motor off ?




robtillaart


so there is some pulsed signal on pin 3?
what is the frequency?

you should go IRQ based as holding state by a polled digitalRead() can miss pulses.

(code not tested)
Code: [Select]
#define THRESHOLD 500   // to be configured, now 500 millisec

boolean motorRunning = false;

volatile unsigned long lastTime = 0;

void IRQ()
{
  lastTime = millis();
}

void setup()
{
  attachInterrupt(1, IRQ, RISING);  // 1 = pin 3
}

void loop()
{
  if (millis() - lastTime > THRESHOLD)
  {
    motorRunning == false;
    // motorStop();
  }
  else
  {
    if (motorRunning == false)
    {
      motorRunning = true;
      // MotorStart();
    }
  }
}


Note for safety I propose to stop the motor over and over again if there is no pulse. This is just thinking safety.
Rob
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

peter1929

thanks fast reply.

my pulse is 6 pulses per mm of travel ( an linerar actuator), about 9 mm travel  per sec

robtillaart


so ! 54 pulses per second ... faster than every 25 millisecond. => THRESHOLD = 25

give it a try.
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy