Hi,
I have a simple stepper motor application (within a much larger project) that runs a motor until it is stopped by end switch.
My question is: what is the corrector best way to stop the motor when the end switch is met, and enable when a new request comes (Not by number of steps.
I did not find any 'enable' / 'disable' bit in the Atmel AVR interrupt registers' descriptions.
(I know I can do it by changing the prescaler, but this is not a clean way).
Sorry I forgot to show the interrupt handler.
Here it is again, with the handler, and simplified
The question is: There will be an interrupt each 1 mSec that will drive one step.
When the end switch closes, I want the motor to stop, but I can not find a way to hold or disable / enable the interrupt of its handler.
//The interrupt handler:
ISR(TIMER3_COMPA_vect) //Timer3 is used for the stepper motor speed control.
{
motorRight(); //Run one step per each interrupt.
}
void motorRight()
{
digitalWrite(stepDirection, HIGH); //Setting direction Going Right
//Toggle the motor pin on/off for square signal.
digitalWrite(stepperStepPin, !digitalRead(stepperStepPin));
while (digitalRead(rightSwitch) == 1 )
{ //Wait for switch closure = 0
//How you stop the rotation? (The handler)?
}