Arduino controlled stepper motor for Mill X-axis drive

Advert

Arduino controlled stepper motor for Mill X-axis drive

Home Forums CNC machines, Home builds, Conversions, ELS, automation, software, etc tools Arduino controlled stepper motor for Mill X-axis drive

Viewing 3 posts - 26 through 28 (of 28 total)
  • Author
    Posts
  • #794095
    nevillet
    Participant
      @nevillet

      Thanks for all your help on this thread.

      On Dave’s suggestion I’ve managed to deenergise the motor stopping it dead by using the ENA +/- terminals.

      I’ve fed the ENA+ with +5V and to stop the motor, grounding the ENA- terminal.

      The next stage in this project is coupling the X lead screw to the motor shaft with a coupling made on the lathe. (I’ll start a new thread..)

      Advert
      #794890
      nevillet
      Participant
        @nevillet

        The Arduino is controlling the stepper driver and it works but not quite as I’d want.

        At the moment I have a speed control and a push button switch that changes the motor direction.
        To stop the motor i’m using the ENABLE+ & ENABLE- terminals on the controler but this is not via the Arduino but rather directly.

        What I’d like is to do is have a single 3 position switch (On-Off-On) that controls the direction and the enable functionality.

        It would also help if a couple of LED’s were employed to show which position (Forward-Stop-Reverse) the switch was in.

        Can anyone suggest how to code this?

        (this is the sketch I’m using at the moment)

         

         

        int reverseSwitch = 2; // Push button for reverse
        int driverPUL = 7; // PUL- pin
        int driverDIR = 6; // DIR- pin
        int spd = A0; // Potentiometer

        // Variables

        int pd = 500; // Pulse Delay period
        boolean setdir = LOW; // Set Direction

        // Interrupt Handler

        void revmotor (){

        setdir = !setdir;

        }

        void setup() {

        pinMode (driverPUL, OUTPUT);
        pinMode (driverDIR, OUTPUT);
        attachInterrupt(digitalPinToInterrupt(reverseSwitch), revmotor, FALLING);

        }

        void loop() {

        pd = map((analogRead(spd)),0,1023,2000,50);
        digitalWrite(driverDIR,setdir);
        digitalWrite(driverPUL,HIGH);
        delayMicroseconds(pd);
        digitalWrite(driverPUL,LOW);
        delayMicroseconds(pd);

        }

         

        #794903
        John Haine
        Participant
          @johnhaine32865

          A simple way to use such a 3 position switch is to connect its common to ground and connect the other two poles each to an input with a pullup enabled.  Then if both inputs are HIGH you disable the drive, or depending on which is LOW drive in one direction or the other.  No need to use interrupts for this.

          One thing to watch out for is if you have the feedrate set quite high and suddenly ask the stepper to move it may well stall.  Ideally you program an acceleration ramp and there are standard Arduino libraries to do this – accelstepper is one I recall. I think that it also takes care of all the pulse generation stuff, hopefully without using delay() function.

          One of the reasons for using GRBL to generate the pulses is that all the acceleration stuff is already taken care of.

        Viewing 3 posts - 26 through 28 (of 28 total)
        • Please log in to reply to this topic. Registering is free and easy using the links on the menu at the top of this page.

        Advert

        Latest Replies

        Viewing 25 topics - 1 through 25 (of 25 total)
        Viewing 25 topics - 1 through 25 (of 25 total)

        View full reply list.

        Advert

        Newsletter Sign-up