Go Down

Topic: Motor drive triggering interrupt (Read 691 times) previous topic - next topic

Pokey

Quote
What if the shuttle has reached the end by then...


The shuttle is on a rail that is 5 feet long. I have it in the middle of its run. In the time that the test drive takes to complete the shuttle only moves a few inches. It never gets anywhere near the sensors.

I know this sounds crazy but if I set my loop to:
Code: [Select]
void loop() {
  if(endposflag){ endposflag=0;  drive_shuttle(rev);  }
  if(homeposflag){ homeposflag=0; drive_shuttle(fwd);  }
}


The shuttle will jerk back and forth moving within only a few inches as the interrupts trigger forcing it change direction. Again, the sensors are easily 15 inches away from the motor.

I am completely stumped...thank you for the feedback though.

jraskell

declare endposflag and homeposflag volatile.  You should declare any variables that will be used in your main code and interrupts this way.  This prevents the compiler from potentially optimizing out code it shouldn't.

Pokey

Don't ask me how, but the idea occurred to me that the LEDs in the slot sensors may be flickering when the Arduino and the H-bridge Vcc suddenly draw power. So I isolated the power supply for the LED's and the problem went away...the interrupts trigger when the shuttle hits the sensors! :)

Well...that was certainly a learning experience. :~

Quote
declare endposflag and homeposflag volatile.


I now have that in my code. Thanks.

Go Up